------------------------------------------------------------
revno: 1685
fixes bug: https://launchpad.net/bugs/1643210
committer: Mark Sapiro <m...@msapiro.net>
branch nick: 2.1
timestamp: Thu 2016-11-24 08:24:14 -0800
message:
  Properly RFC 2047 encode the display name in DMARC munged From:.
modified:
  Mailman/Handlers/CookHeaders.py
  NEWS


--
lp:mailman/2.1
https://code.launchpad.net/~mailman-coders/mailman/2.1

Your team Mailman Checkins is subscribed to branch lp:mailman/2.1.
To unsubscribe from this branch go to 
https://code.launchpad.net/~mailman-coders/mailman/2.1/+edit-subscription
=== modified file 'Mailman/Handlers/CookHeaders.py'
--- Mailman/Handlers/CookHeaders.py	2016-03-02 09:57:16 +0000
+++ Mailman/Handlers/CookHeaders.py	2016-11-24 16:24:14 +0000
@@ -29,6 +29,7 @@
 from email.Utils import parseaddr, formataddr, getaddresses
 from email.Errors import HeaderParseError
 
+from Mailman import i18n
 from Mailman import mm_cfg
 from Mailman import Utils
 from Mailman.i18n import _
@@ -154,12 +155,37 @@
                 realname = email
         # Remove domain from realname if it looks like an email address
         realname = re.sub(r'@([^ .]+\.)+[^ .]+$', '---', realname)
-        # RFC 2047 encode realname if necessary.
-        realname = str(uheader(mlist, realname))
-        lrn = mlist.real_name
+        # Make a display name and RFC 2047 encode it if necessary.  This is
+        # difficult and kludgy. If the realname came from From: it should be
+        # ascii or RFC 2047 encoded. If it came from the list, it should be
+        # in the charset of the list's preferred language or possibly unicode.
+        # if it's from the email address, it should be ascii. In any case,
+        # make it a unicode.
+        if isinstance(realname, unicode):
+            urn = realname
+        else:
+            rn, cs = ch_oneline(realname)
+            urn = unicode(rn, cs, errors='replace')
+        # likewise, the list's real_name which should be ascii, but use the
+        # charset of the list's preferred_language which should be a superset.
+        lcs = Utils.GetCharSet(mlist.preferred_language)
+        ulrn = unicode(mlist.real_name, lcs, errors='replace')
+        # get translated 'via' with dummy replacements
+        realname = '%(realname)s'
+        lrn = '%(lrn)s'
+        # We want the i18n context to be the list's preferred_language.  It
+        # could be the poster's.
+        otrans = i18n.get_translation()
+        i18n.set_language(mlist.preferred_language)
+        via = _('%(realname)s via %(lrn)s')
+        i18n.set_translation(otrans)
+        uvia = unicode(via, lcs, errors='replace')
+        # Replace the dummy replacements.
+        uvia = re.sub(u'%\(lrn\)s', ulrn, re.sub(u'%\(realname\)s', urn, uvia))
+        # And get an RFC 2047 encoded header string.
+        dn = str(Header(uvia, lcs))
         change_header('From',
-                      formataddr((_('%(realname)s via %(lrn)s'),
-                                 mlist.GetListEmail())),
+                      formataddr((dn, mlist.GetListEmail())),
                       mlist, msg, msgdata)
     else:
         # Use this as a flag
@@ -400,7 +426,12 @@
     # At this point, subject may become null if someone post mail with
     # subject: [subject prefix]
     if subject.strip() == '':
+        # We want the i18n context to be the list's preferred_language.  It
+        # could be the poster's.
+        otrans = i18n.get_translation()
+        i18n.set_language(mlist.preferred_language)
         subject = _('(no subject)')
+        i18n.set_translation(otrans)
         cset = Utils.GetCharSet(mlist.preferred_language)
         subject = unicode(subject, cset)
     # and substitute %d in prefix with post_id

=== modified file 'NEWS'
--- NEWS	2016-11-23 21:27:00 +0000
+++ NEWS	2016-11-24 16:24:14 +0000
@@ -23,6 +23,9 @@
 
   Bug fixes and other patches
 
+    - Fixed an issue with properly RFC 2047 encoding the display name in the
+      From: header for messages with DMARC mitigations.  (LP: #1643210)
+
     - Fixed an issue causing UnicodeError in sending digests following a
       change of a list's preferred_language.  (LP: #1644356)
 

_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to