From 80ac803cb2816dde0503671fd117ed134680de53 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Tue, 13 Mar 2012 21:03:01 -0700 Subject: * The LMTP server now requires that the incoming message have a `Message-ID`, otherwise it rejects the message with a 550 error. Also, the LMTP server adds the `X-Message-ID-Hash` header automatically. The `inject` cli command will also add the `X-Message-ID-Hash` header, but it will craft a `Message-ID` header first if one is missing from the injected text. Also, `inject` will always set the correct value for the `original_size` attribute on the message object, instead of trusting a possibly incorrect value if it's already set. The individual `IArchiver` implementations no longer set the `X-Message-ID-Hash` header. --- src/mailman/utilities/email.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/mailman/utilities/email.py') diff --git a/src/mailman/utilities/email.py b/src/mailman/utilities/email.py index 4b1023ce1..38c9980a2 100644 --- a/src/mailman/utilities/email.py +++ b/src/mailman/utilities/email.py @@ -21,10 +21,17 @@ from __future__ import absolute_import, unicode_literals __metaclass__ = type __all__ = [ + 'add_message_hash', 'split_email', ] +from base64 import b32encode +from hashlib import sha1 + + + + def split_email(address): """Split an email address into a user name and domain. @@ -39,3 +46,29 @@ def split_email(address): # There was no at-sign in the email address. return local_part, None return local_part, domain.split('.') + + +def add_message_hash(msg): + """Add a X-Message-ID-Hash header derived from Message-ID. + + This function works by side-effect; the original message is mutated. Any + existing X-Message-ID-Headers are deleted if a Message-ID header is + found. If no Message-ID header is found, the original message is not + modified. + + :param msg: An email message + :type msg: `email.message.Message` or derived + """ + message_id = msg.get('message-id') + if message_id is None: + return + # The angle brackets are not part of the Message-ID. See RFC 2822 + # and http://wiki.list.org/display/DEV/Stable+URLs + if message_id.startswith('<') and message_id.endswith('>'): + message_id = message_id[1:-1] + else: + message_id = message_id.strip() + digest = sha1(message_id).digest() + message_id_hash = b32encode(digest) + del msg['x-message-id-hash'] + msg['X-Message-ID-Hash'] = message_id_hash -- cgit v1.2.3-70-g09d2