diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2022-11-28 08:25:27 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2022-11-28 08:27:13 +0200 |
commit | 23e81540ca53b1532a737c322c8ed4e76590b519 (patch) | |
tree | 3d150846ddd7c5aae2e33b6f9fce99b192e168ae | |
parent | ca0dcfca2ad25541b9553d7110090f9ba49092d8 (diff) |
To work around DMARC rejection rules, mailman may encapsulate the
original message in a message/rfc822 part. Support this.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rwxr-xr-x | patch-save.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/patch-save.py b/patch-save.py index a9b9a3c..8508d22 100755 --- a/patch-save.py +++ b/patch-save.py @@ -51,14 +51,25 @@ def main(argv): parser = email.parser.BytesParser(policy=email.policy.default) msg = parser.parse(sys.stdin.buffer) - # mailman can mangle the From header to work around DMARC rejection rules. - # It then formats From as "Name via mailing-list <mailing-list@domain>" and - # stores the original sender in the Reply-to header. Restore the original - # author in the From header to please git-am. - from_header = msg.get('From') - reply_to = msg.get('Reply-to') - if reply_to and ' via ' in from_header: - msg.replace_header('From', reply_to) + # Handle mailman message mangling used to work around DMARC rejection rules: + # + # - mailman may encapsulate original messages in a message/rfc822 part. + # That's an easy case, simply extract the encapsulated message. Any + # additional mangling of the outer message (such as From header mangling) + # can be ignored. + # + # - mailman may mangle the From header. It then formats From as "Name via + # mailing-list <mailing-list@domain>" and stores the original sender in + # the Reply-to header. Restore the original author in the From header to + # please git-am. + + if msg.get_content_type() == 'message/rfc822': + msg = next(msg.iter_parts()) + else: + from_header = msg.get('From') + reply_to = msg.get('Reply-to') + if reply_to and ' via ' in from_header: + msg.replace_header('From', reply_to) subject = msg.get('Subject') if not subject: |