From 32d5d3d557127e1f9b2f0771ddbabeae11a8e813 Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Tue, 20 Jun 2023 21:45:14 -0400 Subject: [PATCH] add deploy configs --- deploy_configs/mail4one.conf | 3 +++ deploy_configs/mail4one.service | 22 ++++++++++++++++++++++ deploy_configs/mail4one_cert_copy.sh | 18 ++++++++++++++++++ mail4one/smtp.py | 2 +- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 deploy_configs/mail4one.conf create mode 100644 deploy_configs/mail4one.service create mode 100755 deploy_configs/mail4one_cert_copy.sh diff --git a/deploy_configs/mail4one.conf b/deploy_configs/mail4one.conf new file mode 100644 index 0000000..cd6878f --- /dev/null +++ b/deploy_configs/mail4one.conf @@ -0,0 +1,3 @@ +# See sysusers.d(5) for details. + +u mail4one - "Personal Mail server" diff --git a/deploy_configs/mail4one.service b/deploy_configs/mail4one.service new file mode 100644 index 0000000..08bbcc8 --- /dev/null +++ b/deploy_configs/mail4one.service @@ -0,0 +1,22 @@ +# mail4one.service + +[Unit] +Description=Personal Mail server +Documentation=https://gitea.balki.me/balki/mail4one +After=network.target network-online.target +Requires=network-online.target + +[Service] +User=mail4one +ExecStart=/usr/local/bin/mail4one --config /etc/mail4one/config.json +PrivateTmp=true +ProtectSystem=full +AmbientCapabilities=CAP_NET_BIND_SERVICE + +StateDirectory=mail4one +LogsDirectory=mail4one +WorkingDirectory=/var/lib/mail4one +ProtectHome=yes + +[Install] +WantedBy=multi-user.target diff --git a/deploy_configs/mail4one_cert_copy.sh b/deploy_configs/mail4one_cert_copy.sh new file mode 100755 index 0000000..fac73c3 --- /dev/null +++ b/deploy_configs/mail4one_cert_copy.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# certbot deploy hook to copy certificates to mail4one when renewed. +# This file is supposed to be copied to /etc/letsencrypt/renewal-hooks/deploy/ +# Change the mail domain to the one on MX record + +set -x + + +if [ "$RENEWED_DOMAINS" = "mail.mydomain.com" ] +then + mkdir -p /var/lib/mail4one/certs + chmod 500 /var/lib/mail4one/certs + chown mail4one:mail4one /var/lib/mail4one/certs + cp "$RENEWED_LINEAGE/fullchain.pem" /var/lib/mail4one/certs/ + cp "$RENEWED_LINEAGE/privkey.pem" /var/lib/mail4one/certs/ + systemctl restart mail4one.service +fi diff --git a/mail4one/smtp.py b/mail4one/smtp.py index 5c04864..a6cb3af 100644 --- a/mail4one/smtp.py +++ b/mail4one/smtp.py @@ -41,7 +41,7 @@ class MyHandler(AsyncMessage): async def handle_message(self, m: Message): # type: ignore[override] all_mboxes: set[str] = set() for addr in self.rcpt_tos: - for mbox in self.mbox_finder(addr): + for mbox in self.mbox_finder(addr.lower()): all_mboxes.add(mbox) if not all_mboxes: logger.warning(f"dropping message from: {self.peer}")