Commit 73f49713 authored by Barry Warsaw's avatar Barry Warsaw

Fix welcome_message_uri to do the placeholder interpolations guaranteed in the

IMailingList documentation.


 * `ILanguageManager.add()` returns the `ILanguage` object just created.
parent d4b4c6c1
......@@ -64,8 +64,11 @@ def send_welcome_message(mlist, address, language, delivery_mode, text=''):
if mlist.welcome_message_uri:
welcome_message = getUtility(ITemplateLoader).get(
uri = expand(mlist.welcome_message_uri, dict(
welcome_message = getUtility(ITemplateLoader).get(uri)
except URLError:
log.exception('Welcome message URI not found ({0}): {1}'.format(
mlist.fqdn_listname, mlist.welcome_message_uri))
......@@ -94,7 +97,7 @@ def send_welcome_message(mlist, address, language, delivery_mode, text=''):
digmode = ''
msg = UserNotification(
formataddr((user_name, address)),
formataddr((user_name, address)),
_('Welcome to the "$mlist.real_name" mailing list${digmode}'),
text, language)
......@@ -68,6 +68,12 @@ Welcome to the $list_name mailing list.
Your name: $user_name
Your address: $user_address
Your options: $user_options_uri""", file=fp)
# Write a list-specific welcome message.
path = os.path.join(self.var_dir, 'templates', 'lists',
'[email protected]', 'xx')
with open(os.path.join(path, 'welcome.txt'), 'w') as fp:
print('You just joined the $list_name mailing list!', file=fp)
def tearDown(self):
config.pop('template config')
......@@ -99,3 +105,24 @@ Welcome to the Test List mailing list.
Your address: [email protected]
Your options:[email protected]
def test_more_specific_welcome_message_nonenglish(self):
# mlist.welcome_message_uri can contain placeholders for the fqdn list
# name and language.
self._mlist.welcome_message_uri = (
# Add the xx language and subscribe Anne using it.
manager = getUtility(ILanguageManager)
xx = manager.add('xx', 'us-ascii', 'Xlandia')
add_member(self._mlist, '[email protected]', 'Anne Person',
'password', DeliveryMode.regular, 'xx')
send_welcome_message(self._mlist, '[email protected]', xx,
# Now there's one message in the virgin queue.
messages = get_queue_messages('virgin')
self.assertEqual(len(messages), 1)
message = messages[0].msg
'Welcome to the "Test List" mailing list')
'You just joined the Test List mailing list!')
......@@ -125,6 +125,7 @@ The language must be known to Mailman.
>>> from mailman.interfaces.languages import ILanguageManager
>>> getUtility(ILanguageManager).add('ee', 'iso-8859-1', 'Freedonian')
<Language [ee] Freedonian>
>>> FakeArgs.quiet = False
>>> FakeArgs.listname = ['[email protected]']
......@@ -58,6 +58,7 @@ Interfaces
* `IListRequests.get_request()` now takes an optional `request_type`
argument to narrow the search for the given request.
* New `ITemplateLoader` utility.
* `ILanguageManager.add()` returns the `ILanguage` object just created.
......@@ -60,6 +60,8 @@ class ILanguageManager(Interface):
:param description: The English description of the language,
e.g. 'English' or 'French'.
:type description: string
:return: The language object just added.
:rtype: ILanguage
codes = Attribute('An iterator over all known codes.')
......@@ -46,6 +46,7 @@ class LanguageManager:
raise ValueError('Language code already registered: ' + code)
language = Language(code, charset, description)
self._languages[code] = language
return language
def codes(self):
......@@ -31,10 +31,12 @@ Adding languages
Adding a new language requires three pieces of information, the 2-character
language code, the English description of the language, and the character set
used by the language.
used by the language. The language object is returned.
>>> mgr.add('en', 'us-ascii', 'English')
<Language [en] English>
>>> mgr.add('it', 'iso-8859-1', 'Italian')
<Language [it] Italian>
And you can get information for all known languages.
......@@ -54,6 +56,7 @@ Other iterations
You can iterate over all the known language codes.
>>> mgr.add('pl', 'iso-8859-2', 'Polish')
<Language [pl] Polish>
>>> sorted(
[u'en', u'it', u'pl']
......@@ -255,6 +255,7 @@ Some of these preferences are booleans and they can be set to ``True`` or
>>> from mailman.interfaces.languages import ILanguageManager
>>> getUtility(ILanguageManager).add('it', 'iso-8859-1', 'Italian')
<Language [it] Italian>
>>> from mailman.core.constants import DeliveryMode
>>> prefs = user_1.preferences
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment