Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core

Commits:
a6b2de5a by Mark Sapiro at 2018-05-12T20:00:07Z
Fixed dmarc rule to handle From: as a Header object.

- - - - -
a3d1aa05 by Mark Sapiro at 2018-05-13T01:49:20Z
Merge branch 'dmarc' into 'master'

Fixed dmarc rule to handle From: as a Header object.

Closes #477

See merge request mailman/mailman!384
- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/rules/dmarc.py
- src/mailman/rules/tests/test_dmarc.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -74,6 +74,8 @@ Bugs
   are detected and ``replaced``.  (Closes #409)
 * The help for ``mailman qfile`` has been fixed to reference ``mailman qfile``
   rather than the non-existent ``bin/dumpdb``.  (Closes #475)
+* The dmarc rule has been fixed to not throw a TypeError when msg.get('from')
+  returns a header instance.  (Closes #477)
 
 Command line
 ------------


=====================================
src/mailman/rules/dmarc.py
=====================================
--- a/src/mailman/rules/dmarc.py
+++ b/src/mailman/rules/dmarc.py
@@ -310,7 +310,7 @@ class DMARCMitigation:
         if mlist.dmarc_mitigate_action is DMARCMitigateAction.no_mitigation:
             # Don't bother to check if we're not going to do anything.
             return False
-        display_name, address = parseaddr(msg.get('from'))
+        display_name, address = parseaddr(str(msg.get('from', '')))
         if maybe_mitigate(mlist, address):
             # If dmarc_mitigate_action is discard or reject, this rule fires
             # and jumps to the 'moderation' chain to do the actual discard.


=====================================
src/mailman/rules/tests/test_dmarc.py
=====================================
--- a/src/mailman/rules/tests/test_dmarc.py
+++ b/src/mailman/rules/tests/test_dmarc.py
@@ -25,6 +25,7 @@ from datetime import timedelta
 from dns.exception import DNSException
 from dns.rdatatype import CNAME, TXT
 from dns.resolver import NXDOMAIN, NoAnswer, NoNameservers
+from email import message_from_bytes
 from http.server import BaseHTTPRequestHandler, HTTPServer
 from lazr.config import as_timedelta
 from mailman.app.lifecycle import create_list
@@ -217,6 +218,21 @@ To: [email protected]
         with get_dns_resolver():
             self.assertFalse(rule.check(mlist, msg, {}))
 
+    def test_non_ascii_in_from_address(self):
+        # Non-ascii headers with message_from_bytes can return a Header
+        # objest on msg.get().
+        mlist = create_list('[email protected]')
+        # Use action reject.  The rule only hits on reject and discard.
+        mlist.dmarc_mitigate_action = DMARCMitigateAction.reject
+        msg = message_from_bytes(b"""\
+From: Ann\xe9 <[email protected]>
+To: [email protected]
+
+""")
+        rule = dmarc.DMARCMitigation()
+        with get_dns_resolver():
+            self.assertFalse(rule.check(mlist, msg, {}))
+
     def test_dmarc_dns_exception(self):
         mlist = create_list('[email protected]')
         # Use action reject.  The rule only hits on reject and discard.



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/aa1edcd276a3bb634ddd96dd64c70d00e1e2d1f8...a3d1aa053683b96fe1d974a68d0190048753b859

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/aa1edcd276a3bb634ddd96dd64c70d00e1e2d1f8...a3d1aa053683b96fe1d974a68d0190048753b859
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to