summaryrefslogtreecommitdiff
path: root/src/mailman/utilities/tests/test_email.py
diff options
context:
space:
mode:
authortoshio2012-03-14 05:30:52 +0000
committertoshio2012-03-14 05:30:52 +0000
commitd1a9979ecf35d05ed115651dcc6b8680af08b954 (patch)
treecde5caa9a9c20467b4cb3768b564d08e6a368b1a /src/mailman/utilities/tests/test_email.py
parentccde42a936f6c87032c7afd80f33ca5f3fa00b54 (diff)
parentbcc42e2201c7172848185e5675a7b79e3d28aa0f (diff)
downloadmailman-d1a9979ecf35d05ed115651dcc6b8680af08b954.tar.gz
mailman-d1a9979ecf35d05ed115651dcc6b8680af08b954.tar.zst
mailman-d1a9979ecf35d05ed115651dcc6b8680af08b954.zip
Diffstat (limited to 'src/mailman/utilities/tests/test_email.py')
-rw-r--r--src/mailman/utilities/tests/test_email.py75
1 files changed, 72 insertions, 3 deletions
diff --git a/src/mailman/utilities/tests/test_email.py b/src/mailman/utilities/tests/test_email.py
index 833d631b5..478322aaf 100644
--- a/src/mailman/utilities/tests/test_email.py
+++ b/src/mailman/utilities/tests/test_email.py
@@ -15,22 +15,27 @@
# You should have received a copy of the GNU General Public License along with
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
-"""Testing app.bounces functions."""
+"""Testing functions in the email utilities."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestEmail',
]
import unittest
-from mailman.utilities.email import split_email
+from mailman.testing.helpers import (
+ specialized_message_from_string as mfs)
+from mailman.utilities.email import add_message_hash, split_email
class TestEmail(unittest.TestCase):
+ """Testing functions in the email utilities."""
+
def test_normal_split(self):
self.assertEqual(split_email('anne@example.com'),
('anne', ['example', 'com']))
@@ -39,3 +44,67 @@ class TestEmail(unittest.TestCase):
def test_no_at_split(self):
self.assertEqual(split_email('anne'), ('anne', None))
+
+ def test_adding_the_message_hash(self):
+ # When the message has a Message-ID header, this will add the
+ # X-Mailman-Hash-ID header.
+ msg = mfs("""\
+Message-ID: <aardvark>
+
+""")
+ add_message_hash(msg)
+ self.assertEqual(msg['x-message-id-hash'],
+ '75E2XSUXAFQGWANWEROVQ7JGYMNWHJBT')
+
+ def test_remove_hash_headers_first(self):
+ # Any existing X-Mailman-Hash-ID header is removed first.
+ msg = mfs("""\
+Message-ID: <aardvark>
+X-Message-ID-Hash: abc
+
+""")
+ add_message_hash(msg)
+ headers = msg.get_all('x-message-id-hash')
+ self.assertEqual(len(headers), 1)
+ self.assertEqual(headers[0], '75E2XSUXAFQGWANWEROVQ7JGYMNWHJBT')
+
+ def test_hash_header_left_alone_if_no_message_id(self):
+ # If the original message has no Message-ID header, then any existing
+ # X-Message-ID-Hash headers are left intact.
+ msg = mfs("""\
+X-Message-ID-Hash: abc
+
+""")
+ add_message_hash(msg)
+ headers = msg.get_all('x-message-id-hash')
+ self.assertEqual(len(headers), 1)
+ self.assertEqual(headers[0], 'abc')
+
+ def test_angle_brackets_dont_contribute_to_hash(self):
+ # According to RFC 5322, the [matching] angle brackets do not
+ # contribute to the hash.
+ msg = mfs("""\
+Message-ID: aardvark
+
+""")
+ add_message_hash(msg)
+ self.assertEqual(msg['x-message-id-hash'],
+ '75E2XSUXAFQGWANWEROVQ7JGYMNWHJBT')
+
+ def test_mismatched_angle_brackets_do_contribute_to_hash(self):
+ # According to RFC 5322, the [matching] angle brackets do not
+ # contribute to the hash.
+ msg = mfs("""\
+Message-ID: <aardvark
+
+""")
+ add_message_hash(msg)
+ self.assertEqual(msg['x-message-id-hash'],
+ 'AOJ545GHRYD2Y3RUFG2EWMPHUABTG4SM')
+ msg = mfs("""\
+Message-ID: aardvark>
+
+""")
+ add_message_hash(msg)
+ self.assertEqual(msg['x-message-id-hash'],
+ '5KH3RA7ZM4VM6XOZXA7AST2XN2X4S3WY')