Barry Warsaw pushed to branch master at mailman / Mailman Core
Commits:
c53b2c91 by Aurélien Bompard at 2017-10-06T17:46:27+02:00
Protect against messages without a sender
Fixes: #414
- - - - -
83f5bfbc by Barry Warsaw at 2017-10-12T14:13:36+00:00
Merge branch 'fix/empty-sender' into 'master'
Protect against messages without a sender
Closes #414
See merge request mailman/mailman!324
- - - - -
2 changed files:
- src/mailman/rules/moderation.py
- src/mailman/rules/tests/test_moderation.py
Changes:
=====================================
src/mailman/rules/moderation.py
=====================================
--- a/src/mailman/rules/moderation.py
+++ b/src/mailman/rules/moderation.py
@@ -117,6 +117,13 @@ class NonmemberModeration:
for sender in msg.senders:
if ban_manager.is_banned(sender):
return False
+ if len(msg.senders) == 0:
+ with _.defer_translation():
+ # This will be translated at the point of use.
+ reason = _('No sender was found in the message.')
+ _record_action(
+ msgdata, mlist.default_nonmember_action, 'No sender', reason)
+ return True
# Every sender email must be a member or nonmember directly. If it is
# neither, make the email a nonmembers.
for sender in msg.senders:
@@ -141,8 +148,9 @@ class NonmemberModeration:
# Check the '*_these_nonmembers' properties first. XXX These are
# legacy attributes from MM2.1; their database type is 'pickle' and
# they should eventually get replaced.
- for action in ('accept', 'hold', 'reject', 'discard'):
- legacy_attribute_name = '{}_these_nonmembers'.format(action)
+ for action_name in ('accept', 'hold', 'reject', 'discard'):
+ legacy_attribute_name = '{}_these_nonmembers'.format(
+ action_name)
checklist = getattr(mlist, legacy_attribute_name)
for addr in checklist:
if ((addr.startswith('^') and re.match(addr, sender))
@@ -151,8 +159,8 @@ class NonmemberModeration:
# This will be translated at the point of use.
reason = (
_('The sender is in the nonmember {} list'),
- action)
- _record_action(msgdata, action, sender, reason)
+ action_name)
+ _record_action(msgdata, action_name, sender, reason)
return True
action = (mlist.default_nonmember_action
if nonmember.moderation_action is None
=====================================
src/mailman/rules/tests/test_moderation.py
=====================================
--- a/src/mailman/rules/tests/test_moderation.py
+++ b/src/mailman/rules/tests/test_moderation.py
@@ -306,3 +306,25 @@ A message body.
""")
result = rule.check(self._mlist, msg, {})
self.assertFalse(result)
+
+ def test_no_senders(self):
+ rule = moderation.NonmemberModeration()
+ # Message without a From
+ msg = mfs("""\
+To: [email protected]
+Subject: A test message
+Message-ID: <ant>
+MIME-Version: 1.0
+
+A message body.
+""")
+ self.assertEqual(msg.senders, [])
+ msgdata = {}
+ # The NonmemberModeration rule should hit.
+ result = rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result, 'NonmemberModeration rule should hit')
+ self.assertEqual(msgdata, {
+ 'member_moderation_action': Action.hold,
+ 'moderation_reasons': ['No sender was found in the message.'],
+ 'moderation_sender': 'No sender',
+ })
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/b2de80c4217d7b425f7047bc459b86f1bbb0f3e9...83f5bfbc8c5d9184ef2883f8eebc4e3f787d3da0
---
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/b2de80c4217d7b425f7047bc459b86f1bbb0f3e9...83f5bfbc8c5d9184ef2883f8eebc4e3f787d3da0
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