summaryrefslogtreecommitdiff
path: root/src/mailman/mta
diff options
context:
space:
mode:
authorBarry Warsaw2016-07-16 15:44:07 -0400
committerBarry Warsaw2016-07-16 15:44:07 -0400
commitdbde6231ec897379ed38ed4cd015b8ab20ed5fa1 (patch)
tree1226d06a238314262a1d04d0bbf9c4dc0b72c309 /src/mailman/mta
parent3387791beb7112dbe07664041f117fdcc20df53d (diff)
downloadmailman-dbde6231ec897379ed38ed4cd015b8ab20ed5fa1.tar.gz
mailman-dbde6231ec897379ed38ed4cd015b8ab20ed5fa1.tar.zst
mailman-dbde6231ec897379ed38ed4cd015b8ab20ed5fa1.zip
New template system. Closes #249
The new template system is introduced for API 3.1. See ``src/mailman/rest/docs/templates.rst`` for details.
Diffstat (limited to 'src/mailman/mta')
-rw-r--r--src/mailman/mta/deliver.py8
-rw-r--r--src/mailman/mta/docs/decorating.rst21
-rw-r--r--src/mailman/mta/tests/test_delivery.py15
-rw-r--r--src/mailman/mta/verp.py2
4 files changed, 23 insertions, 23 deletions
diff --git a/src/mailman/mta/deliver.py b/src/mailman/mta/deliver.py
index 6ca743df4..caca18aef 100644
--- a/src/mailman/mta/deliver.py
+++ b/src/mailman/mta/deliver.py
@@ -102,11 +102,11 @@ def deliver(mlist, msg, msgdata):
)
template = config.logging.smtp.every
if template.lower() != 'no':
- log.info('%s', expand(template, substitutions))
+ log.info('%s', expand(template, mlist, substitutions))
if refused:
template = config.logging.smtp.refused
if template.lower() != 'no':
- log.info('%s', expand(template, substitutions))
+ log.info('%s', expand(template, mlist, substitutions))
else:
# Log the successful post, but if it was not destined to the mailing
# list (e.g. to the owner or admin), print the actual recipients
@@ -117,7 +117,7 @@ def deliver(mlist, msg, msgdata):
substitutions['recips'] = COMMA.join(recips)
template = config.logging.smtp.success
if template.lower() != 'no':
- log.info('%s', expand(template, substitutions))
+ log.info('%s', expand(template, mlist, substitutions))
# Process any failed deliveries.
temporary_failures = []
permanent_failures = []
@@ -145,7 +145,7 @@ def deliver(mlist, msg, msgdata):
smtpcode = code, # noqa
smtpmsg = smtp_message, # noqa
)
- log.info('%s', expand(template, substitutions))
+ log.info('%s', expand(template, mlist, substitutions))
# Return the results
if temporary_failures or permanent_failures:
raise SomeRecipientsFailed(temporary_failures, permanent_failures)
diff --git a/src/mailman/mta/docs/decorating.rst b/src/mailman/mta/docs/decorating.rst
index 94331163b..551256426 100644
--- a/src/mailman/mta/docs/decorating.rst
+++ b/src/mailman/mta/docs/decorating.rst
@@ -30,7 +30,7 @@ We start by writing the site-global header and footer template.
>>> os.makedirs(site_dir)
>>> config.push('templates', """
... [paths.testing]
- ... template_dir: {0}
+ ... template_dir: {}
... """.format(template_dir))
>>> myheader_path = os.path.join(site_dir, 'myheader.txt')
@@ -44,16 +44,19 @@ We start by writing the site-global header and footer template.
... print("""\
... User name: $user_name
... Language: $user_language
- ... Options: $user_optionsurl
... """, file=fp)
Then create a mailing list which will use this header and footer. Because
these are site-global templates, we can use a shorted URL.
>>> mlist = create_list('test@example.com')
- >>> mlist.header_uri = 'mailman:///myheader.txt'
- >>> mlist.footer_uri = 'mailman:///myfooter.txt'
-
+ >>> from mailman.interfaces.template import ITemplateManager
+ >>> from zope.component import getUtility
+ >>> manager = getUtility(ITemplateManager)
+ >>> manager.set('list:member:regular:header', mlist.list_id,
+ ... 'mailman:///myheader.txt')
+ >>> manager.set('list:member:regular:footer', mlist.list_id,
+ ... 'mailman:///myfooter.txt')
>>> transaction.commit()
>>> msg = message_from_string("""\
@@ -65,11 +68,11 @@ these are site-global templates, we can use a shorted URL.
... This is a test.
... """)
- >>> recipients = set([
+ >>> recipients = {
... 'aperson@example.com',
... 'bperson@example.com',
... 'cperson@example.com',
- ... ])
+ ... }
>>> msgdata = dict(
... recipients=recipients,
@@ -80,7 +83,6 @@ More information is included when the recipient is a member of the mailing
list.
::
- >>> from zope.component import getUtility
>>> from mailman.interfaces.member import MemberRole
>>> from mailman.interfaces.usermanager import IUserManager
>>> user_manager = getUtility(IUserManager)
@@ -126,7 +128,6 @@ The decorations happen when the message is delivered.
This is a test.
User name: Anne Person
Language: English (USA)
- Options: http://example.com/aperson@example.com
----------
From: aperson@example.org
To: test@example.com
@@ -144,7 +145,6 @@ The decorations happen when the message is delivered.
This is a test.
User name: Bart Person
Language: English (USA)
- Options: http://example.com/bperson@example.com
----------
From: aperson@example.org
To: test@example.com
@@ -162,7 +162,6 @@ The decorations happen when the message is delivered.
This is a test.
User name: Cris Person
Language: English (USA)
- Options: http://example.com/cperson@example.com
----------
diff --git a/src/mailman/mta/tests/test_delivery.py b/src/mailman/mta/tests/test_delivery.py
index fda74faad..f5729597d 100644
--- a/src/mailman/mta/tests/test_delivery.py
+++ b/src/mailman/mta/tests/test_delivery.py
@@ -25,10 +25,12 @@ import unittest
from mailman.app.lifecycle import create_list
from mailman.config import config
from mailman.interfaces.mailinglist import Personalization
+from mailman.interfaces.template import ITemplateManager
from mailman.mta.deliver import Deliver
from mailman.testing.helpers import (
specialized_message_from_string as mfs, subscribe)
from mailman.testing.layers import ConfigLayer
+from zope.component import getUtility
# Global test capture.
@@ -50,6 +52,7 @@ class TestIndividualDelivery(unittest.TestCase):
"""Test personalized delivery details."""
layer = ConfigLayer
+ maxDiff = None
def setUp(self):
self._mlist = create_list('test@example.com')
@@ -70,22 +73,21 @@ Subject: test
path = os.path.join(self._template_dir,
'site', 'en', 'member-footer.txt')
os.makedirs(os.path.dirname(path))
- with open(path, 'w') as fp:
+ with open(path, 'w', encoding='utf-8') as fp:
print("""\
address : $user_address
delivered: $user_delivered_to
language : $user_language
name : $user_name
-options : $user_optionsurl
""", file=fp)
config.push('templates', """
[paths.testing]
- template_dir: {0}
+ template_dir: {}
""".format(self._template_dir))
self.addCleanup(config.pop, 'templates')
- self._mlist.footer_uri = 'mailman:///member-footer.txt'
- # Let assertMultiLineEqual work without bounds.
- self.maxDiff = None
+ getUtility(ITemplateManager).set(
+ 'list:member:regular:footer', self._mlist.list_id,
+ 'mailman:///member-footer.txt')
def tearDown(self):
# Free global references.
@@ -123,6 +125,5 @@ address : anne@example.org
delivered: anne@example.org
language : English (USA)
name : Anne Person
-options : http://example.com/anne@example.org
""")
diff --git a/src/mailman/mta/verp.py b/src/mailman/mta/verp.py
index 87c6609a0..8ede6cb67 100644
--- a/src/mailman/mta/verp.py
+++ b/src/mailman/mta/verp.py
@@ -64,7 +64,7 @@ class VERPMixin:
recipient)
return sender
return '{0}@{1}'.format(
- expand(config.mta.verp_format, dict(
+ expand(config.mta.verp_format, mlist, dict(
bounces=sender_mailbox,
local=recipient_mailbox,
domain=DOT.join(recipient_domain))),