diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 7 | ||||
| -rw-r--r-- | src/mailman/handlers/decorate.py | 22 | ||||
| -rw-r--r-- | src/mailman/handlers/docs/decorate.rst | 13 | ||||
| -rw-r--r-- | src/mailman/handlers/tests/test_decorate.py | 22 |
4 files changed, 35 insertions, 29 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 341f22f0a..0f778c494 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -52,6 +52,13 @@ Internal API * A handful of unused legacy exceptions have been removed. The redundant `MailmanException` has been removed; use `MailmanError` everywhere. +Message handling +---------------- + * New placeholders have been added for message headers and footers. You can + use a placeholder of the format `$<archiver-name>_url` to insert the + permalink to the message in the named archiver, for any archiver enabled + for the mailing list. Given by Abhilash Raj. + REST ---- * REST API version 3.1 introduced. Mostly backward compatible with version diff --git a/src/mailman/handlers/decorate.py b/src/mailman/handlers/decorate.py index 17293bdd5..1d752cee5 100644 --- a/src/mailman/handlers/decorate.py +++ b/src/mailman/handlers/decorate.py @@ -31,8 +31,8 @@ from email.mime.text import MIMEText from mailman.core.i18n import _ from mailman.email.message import Message from mailman.interfaces.handler import IHandler -from mailman.interfaces.templates import ITemplateLoader from mailman.interfaces.mailinglist import IListArchiverSet +from mailman.interfaces.templates import ITemplateLoader from mailman.utilities.string import expand from urllib.error import URLError from zope.component import getUtility @@ -60,17 +60,15 @@ def process(mlist, msg, msgdata): if member.user.display_name else member.address.original_email) d['user_optionsurl'] = member.options_url - + # Calculate the archiver permalink substitution variables. This provides + # the $<archive-name>_url placeholder for every enabled archiver. for archiver in IListArchiverSet(mlist).archivers: - if not archiver.is_enabled: - # The archiver is not enabled for the mailing list - continue - # Get the permalink of the message from the archiver - archive_url = archiver.system_archiver.permalink(mlist, msg) - if archive_url is None: - continue - d[archiver.system_archiver.name + '_url'] = archive_url - + if archiver.is_enabled: + # Get the permalink of the message from the archiver. + archive_url = archiver.system_archiver.permalink(mlist, msg) + if archive_url is not None: + placeholder = '{}_url'.format(archiver.system_archiver.name) + d[placeholder] = archive_url # These strings are descriptive for the log file and shouldn't be i18n'd d.update(msgdata.get('decoration-data', {})) try: @@ -85,7 +83,7 @@ def process(mlist, msg, msgdata): footer = None log.exception('Footer decorator URI not found ({0}): {1}'.format( mlist.fqdn_listname, mlist.footer_uri)) - # Escape hatch if both the footer and header are empty + # Escape hatch if both the footer and header are empty or None. if not header and not footer: return # Be MIME smart here. We only attach the header and footer by diff --git a/src/mailman/handlers/docs/decorate.rst b/src/mailman/handlers/docs/decorate.rst index 385429bb9..e6199f8e0 100644 --- a/src/mailman/handlers/docs/decorate.rst +++ b/src/mailman/handlers/docs/decorate.rst @@ -122,13 +122,14 @@ will remain in the header or footer unchanged. $dummy footer -Adding URL to archiver in the message footer -============================================ +Adding archiver permalink URLs in the message footer +==================================================== -You can add links to archived messages in footer using some of the pre-defined -variables. Any variable of the type ``<archiver_name>_url`` for any of the -active archivers of the list. For example, if you have Hyperkitty enabled you -can add ``${hyperkitty_url}`` to point to the message in Hyperkitty. +You can add links to archived messages in the footer using special placeholder +variables. For all available and enabled archiver for the mailing list, use a +placeholder of the format ``$<archiver_name>_url``. For example, if you have +HyperKitty enabled you can add ``${hyperkitty_url}`` to point to the message +in HyperKitty. Handling RFC 3676 'format=flowed' parameters diff --git a/src/mailman/handlers/tests/test_decorate.py b/src/mailman/handlers/tests/test_decorate.py index 03a4cdfb3..c8aba63db 100644 --- a/src/mailman/handlers/tests/test_decorate.py +++ b/src/mailman/handlers/tests/test_decorate.py @@ -21,6 +21,7 @@ __all__ = [ 'TestDecorate', ] + import os import shutil import tempfile @@ -32,13 +33,13 @@ from mailman.handlers import decorate from mailman.interfaces.archiver import IArchiver from mailman.testing.helpers import specialized_message_from_string as mfs from mailman.testing.layers import ConfigLayer -from unittest.mock import patch from zope.interface import implementer + @implementer(IArchiver) class TestArchiver: - "A test archiver" + """A test archiver""" name = 'testarchiver' is_enabled = False @@ -48,6 +49,7 @@ class TestArchiver: return 'http://example.com/link_to_message' + class TestDecorate(unittest.TestCase): """Test the cook_headers handler.""" @@ -64,26 +66,24 @@ Content-Type: text/plain; This is a test message. """) template_dir = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, template_dir) site_dir = os.path.join(template_dir, 'site', 'en') os.makedirs(site_dir) - config.push('templates', """\ + config.push('archiver', """\ [paths.testing] template_dir: {} - """.format(template_dir)) - config.push('archiver', """ [archiver.testarchiver] class: mailman.handlers.tests.test_decorate.TestArchiver enable: yes - """) - self.footer_path = os.path.join(site_dir, 'myfooter.txt') - self.addCleanup(shutil.rmtree, template_dir) + """.format(template_dir)) self.addCleanup(config.pop, 'archiver') + self.footer_path = os.path.join(site_dir, 'myfooter.txt') def test_decorate_footer_with_archive_url(self): - with open(self.footer_path, 'w') as fp: - print("${testarchiver_url}", file=fp) + with open(self.footer_path, 'w', encoding='utf-8') as fp: + print('${testarchiver_url}', file=fp) self._mlist.footer_uri = 'mailman:///myfooter.txt' self._mlist.preferred_language = 'en' decorate.process(self._mlist, self._msg, {}) - self.assertIn("http://example.com/link_to_message", + self.assertIn('http://example.com/link_to_message', self._msg.as_string()) |
