diff options
| author | Aurélien Bompard | 2015-11-20 09:11:56 +0100 |
|---|---|---|
| committer | Barry Warsaw | 2016-11-28 20:31:09 -0500 |
| commit | b570b76724c6341921ebe531071904df312d39e6 (patch) | |
| tree | e5faec0fc5a98e6adb0bd4e3288d293891458d18 | |
| parent | 432088db522219d6caa6c2cfede3df45acb6f3e0 (diff) | |
| download | mailman-b570b76724c6341921ebe531071904df312d39e6.tar.gz mailman-b570b76724c6341921ebe531071904df312d39e6.tar.zst mailman-b570b76724c6341921ebe531071904df312d39e6.zip | |
Fix a crash with the suspicious rule and Header instances
| -rw-r--r-- | src/mailman/rules/suspicious.py | 4 | ||||
| -rw-r--r-- | src/mailman/rules/tests/test_suspicious.py | 52 |
2 files changed, 55 insertions, 1 deletions
diff --git a/src/mailman/rules/suspicious.py b/src/mailman/rules/suspicious.py index f349a313e..acb17334a 100644 --- a/src/mailman/rules/suspicious.py +++ b/src/mailman/rules/suspicious.py @@ -87,6 +87,8 @@ def has_matching_bounce_header(mlist, msg): """ for header, cre, line in _parse_matching_header_opt(mlist): for value in msg.get_all(header, []): - if cre.search(value): + # Convert the header value to string because it may be an + # email.header.Header instance. + if cre.search(str(value)): return True return False diff --git a/src/mailman/rules/tests/test_suspicious.py b/src/mailman/rules/tests/test_suspicious.py new file mode 100644 index 000000000..1be0eb8e7 --- /dev/null +++ b/src/mailman/rules/tests/test_suspicious.py @@ -0,0 +1,52 @@ +# Copyright (C) 2015 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Test the `suspicious` rule.""" + +__all__ = [ + 'TestSuspicious', + ] + + +import os +import unittest +from email.header import Header + +from mailman.app.lifecycle import create_list +from mailman.email.message import Message +from mailman.rules import suspicious +from mailman.testing.layers import ConfigLayer + + + +class TestSuspicious(unittest.TestCase): + """Test the suspicous rule.""" + + layer = ConfigLayer + + def setUp(self): + self._mlist = create_list('test@example.com') + self._rule = suspicious.SuspiciousHeader() + + def test_header_instance(self): + # Check the case where the subject is a Header instance + msg = Message() + msg["From"] = Header("user@example.com") + self._mlist.bounce_matching_headers = 'from: spam@example.com' + result = self._rule.check(self._mlist, msg, {}) + self.assertFalse(result) + |
