summaryrefslogtreecommitdiff
path: root/src/mailman/runners
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/runners')
-rw-r--r--src/mailman/runners/digest.py59
-rw-r--r--src/mailman/runners/docs/digester.rst12
-rw-r--r--src/mailman/runners/tests/test_digest.py27
3 files changed, 49 insertions, 49 deletions
diff --git a/src/mailman/runners/digest.py b/src/mailman/runners/digest.py
index bbef1f33f..c591c10a9 100644
--- a/src/mailman/runners/digest.py
+++ b/src/mailman/runners/digest.py
@@ -33,10 +33,10 @@ from mailman.core.runner import Runner
from mailman.email.message import Message, MultipartDigestMessage
from mailman.handlers.decorate import decorate
from mailman.interfaces.member import DeliveryMode, DeliveryStatus
-from mailman.utilities.i18n import make
+from mailman.interfaces.template import ITemplateLoader
from mailman.utilities.mailbox import Mailbox
-from mailman.utilities.string import oneline, wrap
-from urllib.error import URLError
+from mailman.utilities.string import expand, oneline, wrap
+from zope.component import getUtility
log = logging.getLogger('mailman.error')
@@ -67,23 +67,16 @@ class Digester:
# digest header are separate MIME subobjects. In either case, it's
# the first thing in the digest, and we can calculate it now, so go
# ahead and add it now.
- self._masthead = make('masthead.txt',
- mailing_list=mlist,
- display_name=mlist.display_name,
- got_list_email=mlist.posting_address,
- got_listinfo_url=mlist.script_url('listinfo'),
- got_request_email=mlist.request_address,
- got_owner_email=mlist.owner_address,
- )
+ template = getUtility(ITemplateLoader).get(
+ 'list:member:digest:masthead', mlist)
+ self._masthead = wrap(expand(template, mlist, dict(
+ # For backward compatibility.
+ got_list_email=mlist.posting_address,
+ got_request_email=mlist.request_address,
+ got_owner_email=mlist.owner_address,
+ )))
# Set things up for the table of contents.
- if mlist.digest_header_uri is not None:
- try:
- self._header = decorate(mlist, mlist.digest_header_uri)
- except URLError:
- log.exception(
- 'Digest header decorator URI not found ({}): {}'.format(
- mlist.fqdn_listname, mlist.digest_header_uri))
- self._header = ''
+ self._header = decorate('list:member:digest:header', mlist)
self._toc = StringIO()
print(_("Today's Topics:\n"), file=self._toc)
@@ -151,7 +144,7 @@ class MIMEDigester(Digester):
masthead['Content-Description'] = self._subject
self._message.attach(masthead)
# Add the optional digest header.
- if mlist.digest_header_uri is not None:
+ if len(self._header) > 0:
header = MIMEText(self._header.encode(self._charset),
_charset=self._charset)
header['Content-Description'] = _('Digest Header')
@@ -186,16 +179,8 @@ class MIMEDigester(Digester):
def finish(self):
"""Finish up the digest, producing the email-ready copy."""
self._message.attach(self._digest_part)
- if self._mlist.digest_footer_uri is not None:
- try:
- footer_text = decorate(
- self._mlist, self._mlist.digest_footer_uri)
- except URLError:
- log.exception(
- 'Digest footer decorator URI not found ({0}): {1}'.format(
- self._mlist.fqdn_listname,
- self._mlist.digest_footer_uri))
- footer_text = ''
+ footer_text = decorate('list:member:digest:footer', self._mlist)
+ if len(footer_text) > 0:
footer = MIMEText(footer_text.encode(self._charset),
_charset=self._charset)
footer['Content-Description'] = _('Digest Footer')
@@ -220,7 +205,7 @@ class RFC1153Digester(Digester):
print(self._masthead, file=self._text)
print(file=self._text)
# Add the optional digest header.
- if mlist.digest_header_uri is not None:
+ if len(self._header) > 0:
print(self._header, file=self._text)
print(file=self._text)
# Calculate the set of headers we're to keep in the RFC1153 digest.
@@ -273,16 +258,8 @@ class RFC1153Digester(Digester):
def finish(self):
"""Finish up the digest, producing the email-ready copy."""
- if self._mlist.digest_footer_uri is not None:
- try:
- footer_text = decorate(
- self._mlist, self._mlist.digest_footer_uri)
- except URLError:
- log.exception(
- 'Digest footer decorator URI not found ({}): {}'.format(
- self._mlist.fqdn_listname,
- self._mlist.digest_footer_uri))
- footer_text = ''
+ footer_text = decorate('list:member:digest:footer', self._mlist)
+ if len(footer_text) > 0:
# MAS: There is no real place for the digest_footer in an RFC 1153
# compliant digest, so add it as an additional message with
# Subject: Digest Footer
diff --git a/src/mailman/runners/docs/digester.rst b/src/mailman/runners/docs/digester.rst
index c5b1a0e6e..ea31761a1 100644
--- a/src/mailman/runners/docs/digester.rst
+++ b/src/mailman/runners/docs/digester.rst
@@ -139,9 +139,8 @@ The MIME digest has lots of good stuff, all contained in the multipart.
Send Test mailing list submissions to
test@example.com
<BLANKLINE>
- To subscribe or unsubscribe via the World Wide Web, visit
- http://lists.example.com/listinfo/test@example.com
- or, via email, send a message with subject or body 'help' to
+ To subscribe or unsubscribe via email, send a message with subject or
+ body 'help' to
test-request@example.com
<BLANKLINE>
You can reach the person managing the list at
@@ -221,7 +220,6 @@ The MIME digest has lots of good stuff, all contained in the multipart.
_______________________________________________
Test mailing list
test@example.com
- http://lists.example.com/listinfo/test@example.com
<BLANKLINE>
--===============...==--
<BLANKLINE>
@@ -242,9 +240,8 @@ The RFC 1153 contains the digest in a single plain text message.
Send Test mailing list submissions to
test@example.com
<BLANKLINE>
- To subscribe or unsubscribe via the World Wide Web, visit
- http://lists.example.com/listinfo/test@example.com
- or, via email, send a message with subject or body 'help' to
+ To subscribe or unsubscribe via email, send a message with subject or
+ body 'help' to
test-request@example.com
<BLANKLINE>
You can reach the person managing the list at
@@ -300,7 +297,6 @@ The RFC 1153 contains the digest in a single plain text message.
_______________________________________________
Test mailing list
test@example.com
- http://lists.example.com/listinfo/test@example.com
<BLANKLINE>
<BLANKLINE>
------------------------------
diff --git a/src/mailman/runners/tests/test_digest.py b/src/mailman/runners/tests/test_digest.py
index 0448a7349..6157f500b 100644
--- a/src/mailman/runners/tests/test_digest.py
+++ b/src/mailman/runners/tests/test_digest.py
@@ -17,6 +17,7 @@
"""Test the digest runner."""
+import os
import unittest
from email.iterators import _structure as structure
@@ -26,6 +27,7 @@ from mailman.app.lifecycle import create_list
from mailman.config import config
from mailman.email.message import Message
from mailman.interfaces.member import DeliveryMode
+from mailman.interfaces.template import ITemplateManager
from mailman.runners.digest import DigestRunner
from mailman.testing.helpers import (
LogFileMark, digest_mbox, get_queue_messages, make_digest_messages,
@@ -34,6 +36,8 @@ from mailman.testing.helpers import (
subscribe)
from mailman.testing.layers import ConfigLayer
from string import Template
+from tempfile import TemporaryDirectory
+from zope.component import getUtility
class TestDigest(unittest.TestCase):
@@ -220,6 +224,29 @@ class TestI18nDigest(unittest.TestCase):
self._mlist.digest_size_threshold = 0
self._process = config.handlers['to-digest'].process
self._runner = make_testable_runner(DigestRunner)
+ # Add a French version of the digest masthead.
+ tempdir = TemporaryDirectory()
+ self.addCleanup(tempdir.cleanup)
+ french_path = os.path.join(tempdir.name, 'fr', 'masthead.txt')
+ os.makedirs(os.path.dirname(french_path))
+ with open(french_path, 'w', encoding='utf-8') as fp:
+ print("""\
+Envoyez vos messages pour la liste $display_name à
+\t$got_list_email
+
+Pour vous (dés)abonner par courriel, envoyez un message avec « help » dans
+le corps ou dans le sujet à
+\t$got_request_email
+
+Vous pouvez contacter l'administrateur de la liste à l'adresse
+\t$got_owner_email
+
+Si vous répondez, n'oubliez pas de changer l'objet du message afin
+qu'il soit plus spécifique que « Re: Contenu du groupe de $display_name...
+""", file=fp)
+ getUtility(ITemplateManager).set(
+ 'list:member:digest:masthead', self._mlist.list_id,
+ 'file:///{}/$language/masthead.txt'.format(tempdir.name))
def test_multilingual_digest(self):
# When messages come in with a content-type character set different