lists.sr.ht: Allow to serve lmtp on tcp and smtp on unix socket v1 PROPOSED

Philippe Pepiot
Philippe Pepiot: 1
 Allow to serve lmtp on tcp and smtp on unix socket

 2 files changed, 13 insertions(+), 8 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/8214/mbox | git am -3
Learn more about email & git

[PATCH lists.sr.ht] Allow to serve lmtp on tcp and smtp on unix socket Export this patch

Philippe Pepiot
We previously used "sock" parameter to determine if protocol should be
lmtp (unix socket) or smtp (tcp).
Since it make sense to serve both protocols on tcp or unix socket, introduce a
new "protocol" parameter to switch between lmtp and smtp.

Also evaluate "sock-group" option only when using unix socket, so the
option is no longer mandatory for tcp where it's unused.
 config.example.ini |  4 +++-
 listssrht-lmtp     | 17 ++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/config.example.ini b/config.example.ini
index 3d4d7ed..dae3c4f 100644
--- a/config.example.ini
+++ b/config.example.ini
@@ -90,9 +90,11 @@ msgauth-server=mail.sr.ht.local

# Protocol used by the daemon. Either lmtp or smtp.
# Path for the lmtp daemon's unix socket. Direct incoming mail to this socket.
# Alternatively, specify IP:PORT and an SMTP server will be run instead.
# Alternatively, specify IP:PORT will run the server using tcp.
# The lmtp daemon will make the unix socket group-read/write for users in this
diff --git a/listssrht-lmtp b/listssrht-lmtp
index 5b8cea8..d4f5b76 100755
--- a/listssrht-lmtp
+++ b/listssrht-lmtp
@@ -289,21 +289,24 @@ class MailHandler:
        return "250 Message accepted for delivery"

async def create_server():
    sock_gid = getgrnam(cfg("lists.sr.ht::worker", "sock-group")).gr_gid
    pg = await asyncpg.create_pool(dsn=cfg("lists.sr.ht", "connection-string"))
    handler = MailHandler(pg)
    protocol = cfg("lists.sr.ht::worker", "protocol")
    if protocol == "smtp":
        def serve():
            return SMTP(handler, enable_SMTPUTF8=True)
        def serve():
            return LMTP(handler, enable_SMTPUTF8=True)
    sock = cfg("lists.sr.ht::worker", "sock")
    if "/" in sock:
        await loop.create_unix_server(
                lambda: LMTP(handler, enable_SMTPUTF8=True),
        sock_gid = getgrnam(cfg("lists.sr.ht::worker", "sock-group")).gr_gid
        await loop.create_unix_server(serve, path=sock)
        os.chmod(sock, 0o775)
        os.chown(sock, os.getuid(), sock_gid)
        host, port = sock.split(":")
        await loop.create_server(
                lambda: SMTP(handler, enable_SMTPUTF8=True),
                host=host, port=int(port))
        await loop.create_server(serve, host=host, port=int(port))

def sigint_handler():
    print("Exiting due to SIGINT")
As a fallback, can you use LMTP for unix sockets and SMTP for tcp
sockets if the option is unset?
View this thread in the archives