Barry Warsaw pushed to branch master at mailman / Mailman

Commits:
b5422749 by Abhilash Raj at 2015-08-30T10:35:26Z
Add link to archives in the message footer.

Add a list of links to archives in the message footer
defined in the footer-generic.txt

- - - - -
91aa5536 by Abhilash Raj at 2015-08-30T10:35:26Z
Add link to archiver from ListArchiverSet

Not all enabled archivers in IArchivers are enabled for lists
by default. The correct way is to search for enabled archivers
in IListArchiver set and then get the permalink from the enabled
ones

- - - - -
5ecee514 by Abhilash Raj at 2015-08-30T10:35:26Z
remove the archive_url from footer-generic.txt

- - - - -
c320a81e by Abhilash Raj at 2015-08-30T10:35:26Z
Remove unused import

- - - - -
880c3ab8 by Abhilash Raj at 2015-08-30T10:35:26Z
Choose which archiver to use in footer

- - - - -
b1a929ed by Abhilash Raj at 2015-08-30T10:35:26Z
don't add None values for archiver_url

- - - - -
fee3a42e by Abhilash Raj at 2015-08-30T10:35:26Z
vars for templates are now per archiver

So you cannot pass a dictionary as variable in templates. Create
a variable for each active archiver for the list. The variable is
of the form of <archiver_name>_url i.e. 'hyperkitty_url'

- - - - -
8ce09f90 by Abhilash Raj at 2015-08-30T10:35:26Z
Add some documentation for archiver links in footer

- - - - -
e2315375 by Abhilash Raj at 2015-08-30T10:35:26Z
Add tests for archive_url in message footer

- - - - -
4fbb1cfb by Abhilash Raj at 2015-08-30T10:35:26Z
Add changes as per barry's comments

- - - - -
53ab491e by Abhilash Raj at 2015-08-30T10:35:27Z
fix tests

- - - - -
54c6880f by Barry Warsaw at 2015-08-30T11:19:57Z
Cosmetic fixes for Abhilash's branch.

- - - - -
fd5d4e22 by Barry Warsaw at 2015-08-30T12:14:02Z
Merge branch 'maxking/mailman-hk'

* 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.

- - - - -
c5b8e9bf by Barry Warsaw at 2015-08-30T12:14:42Z
Merge branch 'master' of gitlab.com:mailman/mailman

- - - - -


4 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/handlers/decorate.py
- src/mailman/handlers/docs/decorate.rst
- + src/mailman/handlers/tests/test_decorate.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
--- 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


=====================================
src/mailman/handlers/decorate.py
=====================================
--- a/src/mailman/handlers/decorate.py
+++ b/src/mailman/handlers/decorate.py
@@ -31,6 +31,7 @@ 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.mailinglist import IListArchiverSet
 from mailman.interfaces.templates import ITemplateLoader
 from mailman.utilities.string import expand
 from urllib.error import URLError
@@ -59,19 +60,30 @@ 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 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:
         header = decorate(mlist, mlist.header_uri, d)
     except URLError:
+        header = None
         log.exception('Header decorator URI not found ({0}): {1}'.format(
             mlist.fqdn_listname, mlist.header_uri))
     try:
         footer = decorate(mlist, mlist.footer_uri, d)
     except URLError:
+        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


=====================================
src/mailman/handlers/docs/decorate.rst
=====================================
--- a/src/mailman/handlers/docs/decorate.rst
+++ b/src/mailman/handlers/docs/decorate.rst
@@ -122,6 +122,16 @@ will remain in the header or footer unchanged.
     $dummy footer
 
 
+Adding archiver permalink URLs in the message footer
+====================================================
+
+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
 ============================================
 


=====================================
src/mailman/handlers/tests/test_decorate.py
=====================================
--- /dev/null
+++ b/src/mailman/handlers/tests/test_decorate.py
@@ -0,0 +1,89 @@
+# Copyright (C) 2014-2015 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
+
+"""Test the decorate handler."""
+
+__all__ = [
+    'TestDecorate',
+    ]
+
+
+import os
+import shutil
+import tempfile
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.config import config
+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 zope.interface import implementer
+
+
+
+@implementer(IArchiver)
+class TestArchiver:
+    """A test archiver"""
+
+    name = 'testarchiver'
+    is_enabled = False
+
+    @staticmethod
+    def permalink(mlist, msg):
+        return 'http://example.com/link_to_message'
+
+
+
+class TestDecorate(unittest.TestCase):
+    """Test the cook_headers handler."""
+
+    layer = ConfigLayer
+
+    def setUp(self):
+        self._mlist = create_list('t...@example.com')
+        self._msg = mfs("""\
+To: t...@example.com
+From: aper...@example.com
+Message-ID: <somerandomid.example.com>
+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('archiver', """\
+        [paths.testing]
+        template_dir: {}
+        [archiver.testarchiver]
+        class: mailman.handlers.tests.test_decorate.TestArchiver
+        enable: yes
+        """.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', 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._msg.as_string())



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/352096f9903961915921ba2adfbe80d0467fdfb5...c5b8e9bfc0757b51a5ee5d866d247cbb9139c244
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to