summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/app/notifications.py9
-rw-r--r--src/mailman/app/tests/test_notifications.py27
-rw-r--r--src/mailman/commands/docs/create.rst1
-rw-r--r--src/mailman/docs/NEWS.rst1
-rw-r--r--src/mailman/interfaces/languages.py2
-rw-r--r--src/mailman/languages/manager.py1
-rw-r--r--src/mailman/model/docs/languages.rst5
-rw-r--r--src/mailman/model/docs/users.rst1
8 files changed, 43 insertions, 4 deletions
diff --git a/src/mailman/app/notifications.py b/src/mailman/app/notifications.py
index 84561a306..5604d5f05 100644
--- a/src/mailman/app/notifications.py
+++ b/src/mailman/app/notifications.py
@@ -64,8 +64,11 @@ def send_welcome_message(mlist, address, language, delivery_mode, text=''):
"""
if mlist.welcome_message_uri:
try:
- welcome_message = getUtility(ITemplateLoader).get(
- mlist.welcome_message_uri)
+ uri = expand(mlist.welcome_message_uri, dict(
+ listname=mlist.fqdn_listname,
+ language=language.code,
+ ))
+ 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=''):
else:
digmode = ''
msg = UserNotification(
- formataddr((user_name, address)),
+ formataddr((user_name, address)),
mlist.request_address,
_('Welcome to the "$mlist.real_name" mailing list${digmode}'),
text, language)
diff --git a/src/mailman/app/tests/test_notifications.py b/src/mailman/app/tests/test_notifications.py
index 74716246c..392cc535d 100644
--- a/src/mailman/app/tests/test_notifications.py
+++ b/src/mailman/app/tests/test_notifications.py
@@ -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',
+ 'test@example.com', 'xx')
+ os.makedirs(path)
+ 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: anne@example.com
Your options: http://example.com/anne@example.com
""")
+
+ 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 = (
+ 'mailman:///$listname/$language/welcome.txt')
+ # Add the xx language and subscribe Anne using it.
+ manager = getUtility(ILanguageManager)
+ xx = manager.add('xx', 'us-ascii', 'Xlandia')
+ add_member(self._mlist, 'anne@example.com', 'Anne Person',
+ 'password', DeliveryMode.regular, 'xx')
+ send_welcome_message(self._mlist, 'anne@example.com', xx,
+ DeliveryMode.regular)
+ # Now there's one message in the virgin queue.
+ messages = get_queue_messages('virgin')
+ self.assertEqual(len(messages), 1)
+ message = messages[0].msg
+ self.assertEqual(str(message['subject']),
+ 'Welcome to the "Test List" mailing list')
+ self.assertEqual(message.get_payload(),
+ 'You just joined the Test List mailing list!')
diff --git a/src/mailman/commands/docs/create.rst b/src/mailman/commands/docs/create.rst
index e902c58e1..6ef72e573 100644
--- a/src/mailman/commands/docs/create.rst
+++ b/src/mailman/commands/docs/create.rst
@@ -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 = ['test3@example.com']
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index 331ce64a8..c1fdc948d 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -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.
Commands
--------
diff --git a/src/mailman/interfaces/languages.py b/src/mailman/interfaces/languages.py
index e44534d72..a93bfcaaa 100644
--- a/src/mailman/interfaces/languages.py
+++ b/src/mailman/interfaces/languages.py
@@ -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.')
diff --git a/src/mailman/languages/manager.py b/src/mailman/languages/manager.py
index 1e3cc1e77..ca7001102 100644
--- a/src/mailman/languages/manager.py
+++ b/src/mailman/languages/manager.py
@@ -46,6 +46,7 @@ class LanguageManager:
raise ValueError('Language code already registered: ' + code)
language = Language(code, charset, description)
self._languages[code] = language
+ return language
@property
def codes(self):
diff --git a/src/mailman/model/docs/languages.rst b/src/mailman/model/docs/languages.rst
index 21143f28b..7bfb0594d 100644
--- a/src/mailman/model/docs/languages.rst
+++ b/src/mailman/model/docs/languages.rst
@@ -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(mgr.codes)
[u'en', u'it', u'pl']
diff --git a/src/mailman/model/docs/users.rst b/src/mailman/model/docs/users.rst
index bd1f36b35..7325d66b9 100644
--- a/src/mailman/model/docs/users.rst
+++ b/src/mailman/model/docs/users.rst
@@ -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