Peter Münster writes:
Probably related: Even without any setting in "Alter Messages", messages with attachment from Gmail are altered, so that DKIM signatures are invalidated:
I think they do this on purpose. Gmail is producing invalid MIME[1]. As you're supposed to do on the internet, Python's email module is accepting it because even though it's technically invalid, it's clear what the intended semantics are. Then as you're supposed to do on the internet, Python produces valid MIME when it reconstructs the message.
I don't know about those other whitespace issues; probably those could be preserved.
Just an idea: you could add to the message object a field like "orig-body", that keeps the unmodified body.
You could, but that would mean tripling or quadrupling the size of many message objects (I've seen PNGs encoded in quoted-pair!) And you'd have to do it for all message objects in the Mailman queues, because Mailman does this conversion as soon as the message arrives, before it knows enough about the message to know if it's really necessary. Then you'd need some kind of API for callers to tell the Email package when to do this, and then when to use it instead of the parsed version in constructing the outgoing message.
I think it's much simpler to just do what Google wants you to do, and mutilate the From field of Gmail authors.
FWIW, if I were going to try to deal with this, I would probably do it differently, adding these peculiarities to the list of things Email considers to be "message defects", and then have a "reproduce defects" flag for the reassemble functions. That would also fix some other things that people sometimes dislike, like Mailman choosing to fold headers in a different place from the orginal.
Footnotes: [1] I'm not going to read the RFCs now to make sure, but the thing is that the newlines on either side of the divider are parsed as part of the divider, not as line separators. So if you have two dividers in a row, there needs to be two newlines (at least) between them, one for the end of the first divider, one for the beginning of the second.