diff options
-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: |