summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Sapiro2016-12-09 12:17:24 -0800
committerMark Sapiro2016-12-09 12:17:24 -0800
commitfac05445902a770fa5f1087debd5b5257e66bddd (patch)
tree082129abae105e9a0d5c20ebb94298c742ecfdda /src
parent39f3083f43a648d42b9de7c9c300e2902e0f9179 (diff)
downloadmailman-fac05445902a770fa5f1087debd5b5257e66bddd.tar.gz
mailman-fac05445902a770fa5f1087debd5b5257e66bddd.tar.zst
mailman-fac05445902a770fa5f1087debd5b5257e66bddd.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/handlers/dmarc.py12
-rw-r--r--src/mailman/handlers/tests/test_dmarc.py33
-rw-r--r--src/mailman/rules/dmarc.py2
-rw-r--r--src/mailman/rules/tests/test_dmarc.py2
4 files changed, 38 insertions, 11 deletions
diff --git a/src/mailman/handlers/dmarc.py b/src/mailman/handlers/dmarc.py
index 8bdce040f..e1f6f86b7 100644
--- a/src/mailman/handlers/dmarc.py
+++ b/src/mailman/handlers/dmarc.py
@@ -25,12 +25,12 @@ from email.header import Header, decode_header
from email.mime.message import MIMEMessage
from email.mime.text import MIMEText
from email.utils import formataddr, getaddresses, make_msgid
-from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.handler import IHandler
from mailman.interfaces.mailinglist import (
DMARCModerationAction, FromIsList, ReplyToMunging)
from mailman.utilities.string import wrap
+from public import public
from zope.interface import implementer
@@ -90,16 +90,12 @@ def munged_headers(mlist, msg, msgdata):
else:
srn += frag
# The list's real_name is a string.
- slrn = mlist.display_name
- # get translated 'via' with dummy replacements
- realname = '$realname'
- lrn = '$lrn' # noqa F841
+ lrn = mlist.display_name # noqa F841
+ realname = srn
# Ensure the i18n context is the list's preferred_language.
with _.using(mlist.preferred_language.code):
via = _('$realname via $lrn')
- # Replace the dummy replacements.
- via = re.sub('\$lrn', slrn, re.sub('\$realname', srn, via))
- # And get an RFC 2047 encoded header string.
+ # Get an RFC 2047 encoded header string.
dn = str(Header(via, mlist.preferred_language.charset))
retn = [('From', formataddr((dn, mlist.posting_address)))]
# We've made the munged From:. Now put the original in Reply-To: or Cc:
diff --git a/src/mailman/handlers/tests/test_dmarc.py b/src/mailman/handlers/tests/test_dmarc.py
index 648fbab0e..2a403c3d7 100644
--- a/src/mailman/handlers/tests/test_dmarc.py
+++ b/src/mailman/handlers/tests/test_dmarc.py
@@ -39,7 +39,7 @@ class TestDMARCMitigations(unittest.TestCase):
self._mlist.dmarc_wrapped_message_text = ''
self._mlist.from_is_list = FromIsList.none
self._mlist.reply_goes_to_list = ReplyToMunging.no_munging
- # We can use the same message text for all tests.
+ # We can use the same message text for most tests.
self._text = """\
From: anne@example.com
To: ant@example.com
@@ -242,3 +242,34 @@ Content-Type: message/rfc822
Content-Disposition: inline
""" + self._text)
+
+ def test_rfc2047_encoded_from(self):
+ self._mlist.from_is_list = FromIsList.munge_from
+ msg = mfs(self._text)
+ del msg['from']
+ msg['From'] = '=?iso-8859-1?Q?A_Pers=F3n?= <anne@example.com>'
+ dmarc.process(self._mlist, msg, {})
+ self.assertMultiLineEqual(msg.as_string(), """\
+To: ant@example.com
+Subject: A subject
+X-Mailman-Version: X.Y
+Message-ID: <some-id@example.com>
+Date: Fri, 1 Jan 2016 00:00:01 +0000
+Another-Header: To test removal in wrapper
+MIME-Version: 1.0
+Content-Type: multipart/alternative; boundary="=====abc=="
+From: =?utf-8?q?A_Pers=C3=B3n_via_Ant?= <ant@example.com>
+Reply-To: =?iso-8859-1?Q?A_Pers=F3n?= <anne@example.com>
+
+--=====abc==
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+Some things to say.
+--=====abc==
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+<html><head></head><body>Some things to say.</body></html>
+--=====abc==--
+""")
diff --git a/src/mailman/rules/dmarc.py b/src/mailman/rules/dmarc.py
index d7e826fe8..30c356c21 100644
--- a/src/mailman/rules/dmarc.py
+++ b/src/mailman/rules/dmarc.py
@@ -24,12 +24,12 @@ import dns.resolver
from dns.exception import DNSException
from email.utils import parseaddr
from lazr.config import as_timedelta
-from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.mailinglist import DMARCModerationAction
from mailman.interfaces.rules import IRule
from mailman.utilities.string import wrap
+from public import public
from urllib import error, request
from zope.interface import implementer
diff --git a/src/mailman/rules/tests/test_dmarc.py b/src/mailman/rules/tests/test_dmarc.py
index 49aeea8c6..930741997 100644
--- a/src/mailman/rules/tests/test_dmarc.py
+++ b/src/mailman/rules/tests/test_dmarc.py
@@ -19,7 +19,7 @@
from dns.rdatatype import TXT
from dns.resolver import NXDOMAIN, NoAnswer
-from mailman import public
+from public import public
from unittest import mock