Skip to content

Preserve content encoding of unaltered mails

georgeto requested to merge georgeto/mailman:preserve-encoding into master

I configured my Mailman3 to not decorate mails, in order to keep existing DKIM signatures intact. However, I observed that Mailman3 re-encodes mails with an Content-Transfer-Encoding of 8bit into base64, which obviously invalidates the mail's DKIM signature.


The EmailMessage.as_string() method 'is restricted to producing messages serialized as "7 bit clean" when utf8 is False, which is the default'. This means that the content of a mail may be re-encoded if the Content-Transfer-Encoding of the mail is not "7 bit clean". This is problematic for DKIM preserving Mailman3 configurations, because the re-encoding invalidates DKIM signatures.

Therefore, we use EmailMessage.as_bytes(), which does not have the "7 bit clean" limitation described earlier, and honors an existing Content-Transfer-Encoding. Furthermore, encoding the message as a byte string has the advantage that the preprocessing step that replaces all non-ASCII characters with question marks before passing the message to smtplib.SMTP.sendmail becomes obsolete.

Merge request reports