qmail-lmtp forwards LF instead of CRLF, then Mailman3 returns error "Line too long (see RFC5321 4.5.3.1.6)"
After updating several components in the mail setup, Mailman3 mailing lists did not work anymore. As both my hosting provider and myself updated things and no mails were sent to the lists for quite some time (very low volume setup), I cannot point at the component that introduced the change.
However, in my analysis I found out that qmail forwards the mail content on stdin with LF-only line breaks. Mailman3 conforms to the standard and expects CRLF and consequently fails with SMTP error code 500, "Line too long (see RFC5321 4.5.3.1.6)".
Thus, in qmail-lmtp I changed
lmtp.sendmail(
os.environ['SENDER'],
os.environ['EXT' + arg_ext] + "@" + os.environ['HOST'],
sys.stdin.buffer.read()
)
to
content = sys.stdin.buffer.read()
# SMTP requires CRLF, so normalize to that. Error message without this:
# "Line too long (see RFC5321 4.5.3.1.6)"
content = content.replace(b'\r\n', b'\n').replace(b'\r', b'\n').replace(b'\n', b'\r\n')
lmtp.sendmail(
os.environ['SENDER'],
os.environ['EXT' + arg_ext] + "@" + os.environ['HOST'],
content
)
Neither a Python nor an email expert, so this might not be the best way or correct component to fix the issue. However, it at least works for me and mailing lists work again.
Edited by dallmair