diff --git a/setup.cfg b/setup.cfg index 3db15f6..0a262f4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = extra-mailman-archivers -version = 0.0.3 +version = 0.0.4 author = Max Erenberg author_email = merenber@csclub.uwaterloo.ca description = Some extra archivers for Mailman 3 diff --git a/src/extra_mailman_archivers/pipermail.py b/src/extra_mailman_archivers/pipermail.py index 4b9e15a..e4f5a05 100644 --- a/src/extra_mailman_archivers/pipermail.py +++ b/src/extra_mailman_archivers/pipermail.py @@ -31,6 +31,7 @@ from io import BytesIO import logging import os import tempfile +import time from flufl.lock import Lock from mailman.config import config @@ -90,6 +91,15 @@ class Pipermail: :type mlist: mailman.interfaces.mailinglist.IMailingList :type message: mailman.email.message.Message """ + + # Workaround for a bug in Mailman which sets unixfrom to an email + # address instead of an mbox header + # https://gitlab.com/mailman/mailman/-/blob/master/src/mailman/runners/lmtp.py#L139 + old_unixfrom = msg.get_unixfrom() + if old_unixfrom is not None and not old_unixfrom.startswith('From '): + # Adapted from https://github.com/python/cpython/blob/3.9/Lib/email/generator.py + msg.set_unixfrom('From ' + old_unixfrom + ' ' + time.ctime(time.time())) + # Mangle the 'From ' lines and add the Unix envelope header. fp = BytesIO() g = BytesGenerator(fp, mangle_from_=True) @@ -135,5 +145,6 @@ class Pipermail: finally: lock.unlock(unconditionally=True) os.unlink(tempfile_name) + msg.set_unixfrom(old_unixfrom) return None