aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xMailman/Handlers/CookHeaders.py41
-rw-r--r--NEWS3
2 files changed, 39 insertions, 5 deletions
diff --git a/Mailman/Handlers/CookHeaders.py b/Mailman/Handlers/CookHeaders.py
index 59eb67b7..84d3032d 100755
--- a/Mailman/Handlers/CookHeaders.py
+++ b/Mailman/Handlers/CookHeaders.py
@@ -29,6 +29,7 @@ from email.Header import Header, decode_header, make_header
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 @@ def process(mlist, msg, msgdata):
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 @@ def prefix_subject(mlist, msg, msgdata):
# 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
diff --git a/NEWS b/NEWS
index 0dfc6630..70a054eb 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,9 @@ Here is a history of user visible changes to Mailman.
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)