Barry Warsaw pushed to branch master at mailman / Mailman
Commits: c14032bc by Mark Sapiro at 2017-06-30T03:42:06+00:00 Ignore syntactically invalid sender addresses. - - - - - 5b7eeedd by Barry Warsaw at 2017-06-30T03:42:09+00:00 Merge branch 'senders' into 'master' Ignore syntactically invalid sender addresses. Closes #229 See merge request !294 - - - - - 3 changed files: - src/mailman/docs/NEWS.rst - src/mailman/email/message.py - src/mailman/runners/tests/test_incoming.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -15,7 +15,8 @@ Here is a history of user visible changes to Mailman. Bugs ---- * A missing html_to_plain_text_command is now properly detected and logged. - (closes #345) + (Closes #345) + * Syntactically invalid sender addresses are now ignored. (Closes #229) Interfaces ---------- ===================================== src/mailman/email/message.py ===================================== --- a/src/mailman/email/message.py +++ b/src/mailman/email/message.py @@ -30,7 +30,9 @@ import email.utils from email.header import Header from email.mime.multipart import MIMEMultipart from mailman.config import config +from mailman.interfaces.address import IEmailValidator from public import public +from zope.component import getUtility COMMASPACE = ', ' @@ -96,13 +98,17 @@ class Message(email.message.Message): # Convert the header to str in case it's a Header instance. name, address = email.utils.parseaddr(str(field_value)) senders.append(address.lower()) - # Filter out None and the empty string, and convert to unicode. + # Filter out invalid addresses, None and the empty string, and convert + # to unicode. clean_senders = [] + validator = getUtility(IEmailValidator) for sender in senders: if not sender: continue if isinstance(sender, bytes): sender = sender.decode('ascii') + if not validator.is_valid(sender): + continue clean_senders.append(sender) return clean_senders ===================================== src/mailman/runners/tests/test_incoming.py ===================================== --- a/src/mailman/runners/tests/test_incoming.py +++ b/src/mailman/runners/tests/test_incoming.py @@ -69,6 +69,17 @@ To: t...@example.com items = get_queue_messages('out', expected_count=1) self.assertEqual(items[0].msgdata.get('marker'), 'posting') + def test_posting_from_invalid(self): + # A message posted to the list goes through the posting chain even if + # From: is invalid. + del self._msg['from'] + self._msg['From'] = 'a...@example.com.' + msgdata = dict(listid='test.example.com') + config.switchboards['in'].enqueue(self._msg, msgdata) + self._in.run() + items = get_queue_messages('out', expected_count=1) + self.assertEqual(items[0].msgdata.get('marker'), 'posting') + def test_owner(self): # A message posted to the list goes through the posting chain. msgdata = dict(listid='test.example.com', View it on GitLab: https://gitlab.com/mailman/mailman/compare/8f8e4f0b1075a176892d3a74dd601cefc642a870...5b7eeedd19ac69976b38aec1132b1f23d963938d --- View it on GitLab: https://gitlab.com/mailman/mailman/compare/8f8e4f0b1075a176892d3a74dd601cefc642a870...5b7eeedd19ac69976b38aec1132b1f23d963938d You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org