diff --git a/docs/courier-mailman-mta.md b/docs/courier-mailman-mta.md new file mode 100644 index 0000000..6cff303 --- /dev/null +++ b/docs/courier-mailman-mta.md @@ -0,0 +1,3 @@ +# courier-mailman-mta.py + +This is our current version trying to communicate between courier and mailman3. \ No newline at end of file diff --git a/journal/2024-05-29.md b/journal/2024-05-29.md new file mode 100644 index 0000000..f4c17f4 --- /dev/null +++ b/journal/2024-05-29.md @@ -0,0 +1 @@ +# 2024-05-29 diff --git a/source/courier-mailman-mta.py b/source/courier-mailman-mta.py new file mode 100644 index 0000000..fe19956 --- /dev/null +++ b/source/courier-mailman-mta.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# +# Written by Thomas Schneider +# This script is placed in public domain. If this is not applicable, consider +# it licensed under the CC-0: +# + +try: + import os + import sys + import smtplib + + lmtp_host = sys.argv[3] if len(sys.argv) > 3 else 'localhost' + lmtp = smtplib.LMTP(lmtp_host, int(sys.argv[1])) + + try: + # Unfortunately qmail sends to local bare LF for end line, while + # SMTP requires CRLF, so normalize to that. Error message without this: + # "Line too long (see RFC5321 4.5.3.1.6)" + # https://gitlab.com/mailman/mailman/-/issues/1133 + content = sys.stdin.buffer.read() + content = content.replace(b'\r\n', b'\n').replace(b'\r', b'\n').replace(b'\n', b'\r\n') + + # See + # for qmail command docs and supplied environment variables. + # We need to replace "1" with an empty string, as qmail only supports EXT, + # EXT2, EXT3, EXT4. + arg_ext = sys.argv[2] if sys.argv[2] != "1" else "" + lmtp.sendmail( + os.environ['SENDER'], + os.environ['EXT' + arg_ext] + "@" + os.environ['HOST'], + #sys.stdin.buffer.read() + content + ) + except smtplib.SMTPResponseException as e: + if 400 <= e.smtp_code < 500: + exit(111) + # otherwise, it's either a 5xx aka permanent error or something else + # is already b0rked, thus raise -> exit(100) -> have qmail return a + # 5xx error + else: + raise +except: + exit(100) \ No newline at end of file