From d880937d448a1fcdd94006659e54b144d0b912f6 Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 28 Jul 2025 16:16:14 +0200 Subject: [PATCH 01/23] doc: added maddy-chatmail to README (#605) * doc: added maddy-chatmail to README * Update README.md Co-authored-by: holger krekel --------- Co-authored-by: holger krekel --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index bc51bf9..7ba08fd 100644 --- a/README.md +++ b/README.md @@ -541,3 +541,6 @@ Here are some related projects that you may be interested in: progress](https://github.com/mjl-/mox/issues/251) to modify it to support all of the features and configuration settings required to operate as a chatmail relay. +- [Maddy-Chatmail](https://github.com/sadraiiali/maddy_chatmail): a plugin for the + [Maddy email server](https://maddy.email/) which aims to implement the + chatmail relay features and configuration options. From 577c04d537bab349c6614ea41084c4f6b0beb2a6 Mon Sep 17 00:00:00 2001 From: cliffmccarthy <16453869+cliffmccarthy@users.noreply.github.com> Date: Mon, 28 Jul 2025 16:30:33 -0500 Subject: [PATCH 02/23] feat: Add try blocks around Git commands in cmdeploy/__init__.py - Added 'try' blocks around the 'git rev-parse' and 'git diff' commands that are run in deploy_chatmail(). If there is an error running rev-parse, git_hash is set to "unknown". If there is an error running diff, git_diff is set to the null string. - This allows the deployment process work in two scenarios that would otherwise fail with an exception: - Systems where the 'git' command is not available. - When running with a copy of the tree content of chatmail/relay, but without a copy of the .git directory. --- cmdeploy/src/cmdeploy/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index cd149a9..cb89475 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -816,8 +816,14 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: name="Ensure cron is installed", packages=["cron"], ) - git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode() - git_diff = subprocess.check_output(["git", "diff"]).decode() + try: + git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode() + except Exception: + git_hash = "unknown\n" + try: + git_diff = subprocess.check_output(["git", "diff"]).decode() + except Exception: + git_diff = "" files.put( name="Upload chatmail relay git commiit hash", src=StringIO(git_hash + git_diff), From 1e059749704351a51f4f9985ce5c1f50dbd3430f Mon Sep 17 00:00:00 2001 From: cliffmccarthy <16453869+cliffmccarthy@users.noreply.github.com> Date: Sat, 26 Jul 2025 09:27:59 -0500 Subject: [PATCH 03/23] feat: Make sure build-essential is installed - The Python modules installed by initenv.sh require a compiler to build. - Revised initenv.sh to check whether build-essential is installed before proceeding, if the system is based on Debian or Ubuntu. --- scripts/initenv.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/initenv.sh b/scripts/initenv.sh index b4dab1b..7194f44 100755 --- a/scripts/initenv.sh +++ b/scripts/initenv.sh @@ -9,6 +9,11 @@ if command -v lsb_release 2>&1 >/dev/null; then echo "You need to install python3-dev for installing the other dependencies." exit 1 fi + if ! dpkg -l | grep build-essential 2>&1 >/dev/null + then + echo "You need to install build-essential for building Python dependencies." + exit 1 + fi ;; esac fi From 3ce350de9e4a7e865da3fbe9a7c93a20cff12d7e Mon Sep 17 00:00:00 2001 From: cliffmccarthy <16453869+cliffmccarthy@users.noreply.github.com> Date: Fri, 8 Aug 2025 08:52:19 -0500 Subject: [PATCH 04/23] feat: Check whether GCC is installed in initenv.sh - Before proceeding with installation of Python dependencies, check whether the 'gcc' command is available by running it with the --version argument. If it is not available, print a helpful message and exit. - For the current set of Python dependencies, without GCC, the build process fails when building the crypt-r package. According to the error message, on my system the exact command it tries to run is 'x86_64-linux-gnu-gcc', but rather than depend on this variant specifically, the script checks for the generic 'gcc' command, so as to avoid coupling the check to an architecture or operating system. Similar problems arise if we attempt to check for packages by name; the compiler binary is provided by 'gcc-11', but the symlinks that provide the unversioned commands (as used by the Python build) come from a package named 'gcc'. Trying to be too precise in what we check for could lead to unnecessary failures in some environments, or become a maintenance challenge in the future. For that reason, this change simply attempts to run 'gcc' and uses that as a probably-sufficient proxy for having what the Python package install will need. --- CHANGELOG.md | 3 +++ scripts/initenv.sh | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e754da0..e3e520d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## untagged +- Check whether GCC is installed in initenv.sh + ([#608](https://github.com/chatmail/relay/pull/608)) + - Expire push notification tokens after 90 days ([#583](https://github.com/chatmail/relay/pull/583)) diff --git a/scripts/initenv.sh b/scripts/initenv.sh index 7194f44..db70250 100755 --- a/scripts/initenv.sh +++ b/scripts/initenv.sh @@ -9,9 +9,9 @@ if command -v lsb_release 2>&1 >/dev/null; then echo "You need to install python3-dev for installing the other dependencies." exit 1 fi - if ! dpkg -l | grep build-essential 2>&1 >/dev/null + if ! gcc --version 2>&1 >/dev/null then - echo "You need to install build-essential for building Python dependencies." + echo "You need to install gcc for building Python dependencies." exit 1 fi ;; From 6b73f6933a0d7363ecac668fa9088455f7049aab Mon Sep 17 00:00:00 2001 From: cliffmccarthy <16453869+cliffmccarthy@users.noreply.github.com> Date: Sun, 10 Aug 2025 11:27:43 -0500 Subject: [PATCH 05/23] docs: Add ARCHITECTURE.md with diagram of components - For starters, this file is just a diagram of components of a chatmail server. In the future, this document can grow into a more complete description of the architecture of the server, the deployment process, and the design intent behind what is and isn't in the code base. - The name ARCHITECTURE.md is inspired by this article, which also has good suggestions about what to put in the file: https://matklad.github.io/2021/02/06/ARCHITECTURE.md.html --- ARCHITECTURE.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ARCHITECTURE.md diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 0000000..7d3b2b9 --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,37 @@ +This diagram shows components of the chatmail server: + +```mermaid +graph LR; + cmdeploy --> sshd; + cron --> expunge; + cron --> acmetool; + cron --> chatmail-metrics; + chatmail-metrics --> /var/www/html; + acmetool --> certs; + acmetool --> acmetool-redirector; + acmetool-redirector --> certs; + nginx --> /var/www/html; + nginx --> certs; + nginx --> newemail.py; + nginx --> |465|postfix; + nginx --> autoconfig.xml; + nginx --> |993|dovecot; + autoconfig.xml --> postfix; + autoconfig.xml --> dovecot; + postfix --> certs; + postfix --> /home/vmail/mail; + postfix --> |10080,10081|filtermail; + postfix --> echobot; + postfix --> |doveauth.socket|doveauth; + dovecot --> certs; + dovecot --> |doveauth.socket|doveauth; + dovecot --> /home/vmail/mail; + dovecot --> |metadata.socket|chatmail-metadata; + doveauth --> /home/vmail/mail; + expunge --> /home/vmail/mail; + chatmail-metadata --> iroh-relay; +``` + +(Arrows in this diagram do not have a specific formal meaning; they +signify "depends on", or "uses", or "sends data to", or just "relates +to".) From c975aa3bd1355b5b0d028ff8063a70a9295de9a1 Mon Sep 17 00:00:00 2001 From: cliffmccarthy <16453869+cliffmccarthy@users.noreply.github.com> Date: Fri, 15 Aug 2025 18:04:30 -0500 Subject: [PATCH 06/23] docs: Indicate draft status in ARCHITECTURE.md - Suggested in review by hpk42. --- ARCHITECTURE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 7d3b2b9..e6b188e 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -1,4 +1,5 @@ -This diagram shows components of the chatmail server: +This diagram shows components of the chatmail server; this is a draft +overview as of mid-August 2025: ```mermaid graph LR; From 2de8b155c2783562882d19f1499bd70444513fa6 Mon Sep 17 00:00:00 2001 From: cliffmccarthy <16453869+cliffmccarthy@users.noreply.github.com> Date: Mon, 18 Aug 2025 12:09:03 -0500 Subject: [PATCH 07/23] docs: Rework architecture diagram based on review feedback - Implemented changes suggested in review by missytake: - Removed relation between acmetool-redirector and certs. - Added internal nginx listening on port 8443. - Changed direction of arrows between certs and the services that use them. This makes the arrow show the direction of information flow, rather than a "depends on" relation. - For filesystem paths, added a descriptive name to the node. - Replaced most arrows with plain lines, to simply show that a relationship exists between the two nodes. This also reduces visual clutter, since the graph is pretty dense with information already. - Split nginx and certs into two nodes, to reduce entanglement in the graph. These "linked" nodes are given a different shape and filled with a different colour, to highlight the fact that they are the same node. - Revised text about the meaning of edges in the graph. --- ARCHITECTURE.md | 74 ++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index e6b188e..a4191ca 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -3,36 +3,48 @@ overview as of mid-August 2025: ```mermaid graph LR; - cmdeploy --> sshd; - cron --> expunge; - cron --> acmetool; - cron --> chatmail-metrics; - chatmail-metrics --> /var/www/html; - acmetool --> certs; - acmetool --> acmetool-redirector; - acmetool-redirector --> certs; - nginx --> /var/www/html; - nginx --> certs; - nginx --> newemail.py; - nginx --> |465|postfix; - nginx --> autoconfig.xml; - nginx --> |993|dovecot; - autoconfig.xml --> postfix; - autoconfig.xml --> dovecot; - postfix --> certs; - postfix --> /home/vmail/mail; - postfix --> |10080,10081|filtermail; - postfix --> echobot; - postfix --> |doveauth.socket|doveauth; - dovecot --> certs; - dovecot --> |doveauth.socket|doveauth; - dovecot --> /home/vmail/mail; - dovecot --> |metadata.socket|chatmail-metadata; - doveauth --> /home/vmail/mail; - expunge --> /home/vmail/mail; - chatmail-metadata --> iroh-relay; + cmdeploy --- sshd; + letsencrypt --- |80|acmetool-redirector; + acmetool-redirector --- |443|nginx-right(["`nginx + (external)`"]); + nginx-external --- |465|postfix; + nginx-external(["`nginx + (external)`"]) --- |8443|nginx-internal["`nginx + (internal)`"]; + nginx-internal --- website["`Website + /var/www/html`"]; + nginx-internal --- newemail.py; + nginx-internal --- autoconfig.xml; + certs-nginx[("`TLS certs + /var/lib/acme`")] --> nginx-internal; + cron --- chatmail-metrics; + cron --- acmetool; + cron --- expunge; + chatmail-metrics --- website; + acmetool --> certs[("`TLS certs + /var/lib/acme`")]; + nginx-external --- |993|dovecot; + autoconfig.xml --- postfix; + autoconfig.xml --- dovecot; + postfix --- echobot; + postfix --- |10080,10081|filtermail; + postfix --- users["`User data + home/vmail/mail`"]; + postfix --- |doveauth.socket|doveauth; + dovecot --- |doveauth.socket|doveauth; + dovecot --- users; + dovecot --- |metadata.socket|chatmail-metadata; + doveauth --- users; + expunge --- users; + chatmail-metadata --- iroh-relay; + certs-nginx --> postfix; + certs-nginx --> dovecot; + style certs fill:#ff6; + style certs-nginx fill:#ff6; + style nginx-external fill:#fc9; + style nginx-right fill:#fc9; ``` -(Arrows in this diagram do not have a specific formal meaning; they -signify "depends on", or "uses", or "sends data to", or just "relates -to".) +The edges in this graph should not be taken too literally; they +reflect some sort of communication path or dependency relationship +between components of the chatmail server. From 915bd39dd5881f7e9ce66d416460df00e675d5ad Mon Sep 17 00:00:00 2001 From: missytake Date: Sun, 29 Jun 2025 18:50:26 +0200 Subject: [PATCH 08/23] CI: fail on lint issues --- .github/workflows/test-and-deploy-ipv4only.yaml | 2 +- .github/workflows/test-and-deploy.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-and-deploy-ipv4only.yaml b/.github/workflows/test-and-deploy-ipv4only.yaml index f3e9eda..3b86e2b 100644 --- a/.github/workflows/test-and-deploy-ipv4only.yaml +++ b/.github/workflows/test-and-deploy-ipv4only.yaml @@ -71,7 +71,7 @@ jobs: ssh -o StrictHostKeyChecking=accept-new -v root@staging-ipv4.testrun.org chown root:root -R /var/lib/acme || true - name: run formatting checks - run: cmdeploy fmt -v + run: cmdeploy fmt -v --check - name: run deploy-chatmail offline tests run: pytest --pyargs cmdeploy diff --git a/.github/workflows/test-and-deploy.yaml b/.github/workflows/test-and-deploy.yaml index 53aa79a..d9a586c 100644 --- a/.github/workflows/test-and-deploy.yaml +++ b/.github/workflows/test-and-deploy.yaml @@ -71,7 +71,7 @@ jobs: ssh -o StrictHostKeyChecking=accept-new -v root@staging2.testrun.org chown root:root -R /var/lib/acme || true - name: run formatting checks - run: cmdeploy fmt -v + run: cmdeploy fmt -v --check - name: run deploy-chatmail offline tests run: pytest --pyargs cmdeploy From 5410c1bebc03dd30c9f8052c298769a2db7fd086 Mon Sep 17 00:00:00 2001 From: missytake Date: Sun, 29 Jun 2025 18:56:20 +0200 Subject: [PATCH 09/23] CI: remove lint checks from test deployments --- .github/workflows/test-and-deploy-ipv4only.yaml | 3 --- .github/workflows/test-and-deploy.yaml | 3 --- 2 files changed, 6 deletions(-) diff --git a/.github/workflows/test-and-deploy-ipv4only.yaml b/.github/workflows/test-and-deploy-ipv4only.yaml index 3b86e2b..3871f73 100644 --- a/.github/workflows/test-and-deploy-ipv4only.yaml +++ b/.github/workflows/test-and-deploy-ipv4only.yaml @@ -70,9 +70,6 @@ jobs: rsync -avz dkimkeys-restore/dkimkeys root@staging-ipv4.testrun.org:/etc/ || true ssh -o StrictHostKeyChecking=accept-new -v root@staging-ipv4.testrun.org chown root:root -R /var/lib/acme || true - - name: run formatting checks - run: cmdeploy fmt -v --check - - name: run deploy-chatmail offline tests run: pytest --pyargs cmdeploy diff --git a/.github/workflows/test-and-deploy.yaml b/.github/workflows/test-and-deploy.yaml index d9a586c..c78923e 100644 --- a/.github/workflows/test-and-deploy.yaml +++ b/.github/workflows/test-and-deploy.yaml @@ -70,9 +70,6 @@ jobs: rsync -avz dkimkeys-restore/dkimkeys root@staging2.testrun.org:/etc/ || true ssh -o StrictHostKeyChecking=accept-new -v root@staging2.testrun.org chown root:root -R /var/lib/acme || true - - name: run formatting checks - run: cmdeploy fmt -v --check - - name: run deploy-chatmail offline tests run: pytest --pyargs cmdeploy From d690c22c067bd58fcba8d2646303c2f2eb66d847 Mon Sep 17 00:00:00 2001 From: missytake Date: Wed, 20 Aug 2025 19:04:38 +0200 Subject: [PATCH 10/23] cmdeploy: print echobot link at the end of cmdeploy run --- cmdeploy/src/cmdeploy/cmdeploy.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index 5918773..ffb6c13 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -89,6 +89,8 @@ def run_cmd(args, out): try: retcode = out.check_call(cmd, env=env) if retcode == 0: + print("\nYou can try out the relay by talking to this echo bot: ") + print(sshexec(call=remote.rshell.shell, kwargs=dict(command="cat /var/lib/echobot/invite-link.txt"))) out.green("Deploy completed, call `cmdeploy dns` next.") elif not remote_data["acme_account_url"]: out.red("Deploy completed but letsencrypt not configured") From 84e0376762039c4aa798c76b62ca3df4e66ae706 Mon Sep 17 00:00:00 2001 From: missytake Date: Wed, 20 Aug 2025 22:43:11 +0200 Subject: [PATCH 11/23] cmdeploy: get SSHExec again, timeout is likely --- cmdeploy/src/cmdeploy/cmdeploy.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index ffb6c13..cd72aa3 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -90,6 +90,7 @@ def run_cmd(args, out): retcode = out.check_call(cmd, env=env) if retcode == 0: print("\nYou can try out the relay by talking to this echo bot: ") + sshexec = args.get_sshexec() print(sshexec(call=remote.rshell.shell, kwargs=dict(command="cat /var/lib/echobot/invite-link.txt"))) out.green("Deploy completed, call `cmdeploy dns` next.") elif not remote_data["acme_account_url"]: From 6fde0626130d67f71f20ce8e60df8351ec3b9322 Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 25 Aug 2025 15:12:40 +0200 Subject: [PATCH 12/23] fix lint --- cmdeploy/src/cmdeploy/cmdeploy.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index cd72aa3..bca3878 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -91,7 +91,12 @@ def run_cmd(args, out): if retcode == 0: print("\nYou can try out the relay by talking to this echo bot: ") sshexec = args.get_sshexec() - print(sshexec(call=remote.rshell.shell, kwargs=dict(command="cat /var/lib/echobot/invite-link.txt"))) + print( + sshexec( + call=remote.rshell.shell, + kwargs=dict(command="cat /var/lib/echobot/invite-link.txt"), + ) + ) out.green("Deploy completed, call `cmdeploy dns` next.") elif not remote_data["acme_account_url"]: out.red("Deploy completed but letsencrypt not configured") From 7e81495b510ea6a75a464486281628d633520e97 Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 28 Apr 2025 15:44:10 +0200 Subject: [PATCH 13/23] cmdeploy: exit if a necessary port is occupied by an unexpected process --- cmdeploy/src/cmdeploy/__init__.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index cb89475..b856702 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -675,10 +675,28 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: # to use 127.0.0.1 as the resolver. from cmdeploy.cmdeploy import Out - process_on_53 = host.get_fact(Port, port=53) - if process_on_53 not in (None, "unbound"): - Out().red(f"Can't install unbound: port 53 is occupied by: {process_on_53}") - exit(1) + port_services = [ + ("master", 25), + ("unbound", 53), + ("acmetool", 80), + ("imap-login", 143), + ("nginx", 443), + ("master", 465), + ("master", 587), + ("imap-login", 993), + ("iroh-relay", 3340), + ("nginx", 8443), + ("master", 10025), + ("master", 10026), + ("filtermail", 10080), + ("filtermail", 10081), + ] + for service, port in port_services: + running_service = host.get_fact(Port, port=port) + if running_service not in (service, None): + Out().red(f"Can't install chatmail relay: port {port} is occupied by: {running_service}") + exit(1) + apt.packages( name="Install unbound", packages=["unbound", "unbound-anchor", "dnsutils"], From a49aa0e655d40433584fec05ea72861e4e26047f Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 28 Apr 2025 15:51:02 +0200 Subject: [PATCH 14/23] acmetool: remove outdated systemctl stop nginx --- cmdeploy/src/cmdeploy/acmetool/__init__.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cmdeploy/src/cmdeploy/acmetool/__init__.py b/cmdeploy/src/cmdeploy/acmetool/__init__.py index 19a3795..b5b593d 100644 --- a/cmdeploy/src/cmdeploy/acmetool/__init__.py +++ b/cmdeploy/src/cmdeploy/acmetool/__init__.py @@ -54,12 +54,6 @@ def deploy_acmetool(email="", domains=[]): group="root", mode="644", ) - if host.get_fact(SystemdStatus).get("nginx.service"): - systemd.service( - name="Stop nginx service to free port 80", - service="nginx", - running=False, - ) systemd.service( name="Setup acmetool-redirector service", From a1eeea4632df4e487919f19d09b1bf97bb82a7ad Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 28 Apr 2025 15:52:47 +0200 Subject: [PATCH 15/23] acmetool: remove unused imports --- cmdeploy/src/cmdeploy/acmetool/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmdeploy/src/cmdeploy/acmetool/__init__.py b/cmdeploy/src/cmdeploy/acmetool/__init__.py index b5b593d..28d4fd8 100644 --- a/cmdeploy/src/cmdeploy/acmetool/__init__.py +++ b/cmdeploy/src/cmdeploy/acmetool/__init__.py @@ -1,7 +1,5 @@ import importlib.resources -from pyinfra import host -from pyinfra.facts.systemd import SystemdStatus from pyinfra.operations import apt, files, server, systemd From 180ddb816880f37671ce6ef1d21291cf1de8882c Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 28 Apr 2025 15:54:47 +0200 Subject: [PATCH 16/23] doc: add changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e520d..4727133 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ - filtermail: respect config message size limit ([#572](https://github.com/chatmail/relay/pull/572)) +- Don't deploy if one of the ports used for chatmail relay services is occupied by an unexpected process + ([#568](https://github.com/chatmail/relay/pull/568)) + - Add config value after how many days large files are deleted ([#555](https://github.com/chatmail/relay/pull/555)) From d8cbe9d6af4aaaeee37384c4728bbf7385ea985a Mon Sep 17 00:00:00 2001 From: missytake Date: Sat, 24 May 2025 08:55:00 +0200 Subject: [PATCH 17/23] cmdeploy: use ports from config for port checking --- cmdeploy/src/cmdeploy/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index b856702..72600b3 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -686,10 +686,10 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: ("imap-login", 993), ("iroh-relay", 3340), ("nginx", 8443), - ("master", 10025), - ("master", 10026), - ("filtermail", 10080), - ("filtermail", 10081), + ("master", config.postfix_reinject_port), + ("master", config.postfix_reinject_port_incoming), + ("filtermail", config.filtermail_smtp_port), + ("filtermail", config.filtermail_smtp_port_incoming), ] for service, port in port_services: running_service = host.get_fact(Port, port=port) From 73831c74d91eed010266fd0a630fa9ba2fe11ee7 Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 25 Aug 2025 23:38:25 +0200 Subject: [PATCH 18/23] cmdeploy: fix lint --- cmdeploy/src/cmdeploy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index 72600b3..fa4d362 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -694,7 +694,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: for service, port in port_services: running_service = host.get_fact(Port, port=port) if running_service not in (service, None): - Out().red(f"Can't install chatmail relay: port {port} is occupied by: {running_service}") + Out().red(f"Deploy failed: port {port} is occupied by: {running_service}") exit(1) apt.packages( From 7fdaffe8298f4d365fea70c7db5fe3e098b30d10 Mon Sep 17 00:00:00 2001 From: missytake Date: Fri, 29 Aug 2025 16:04:19 +0200 Subject: [PATCH 19/23] cmdeploy: on Ubuntu, postfix calls its port 25 process 'smtpd' --- cmdeploy/src/cmdeploy/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index fa4d362..042957d 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -676,7 +676,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: from cmdeploy.cmdeploy import Out port_services = [ - ("master", 25), + (["master", "smtpd"], 25), ("unbound", 53), ("acmetool", 80), ("imap-login", 143), @@ -692,10 +692,12 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: ("filtermail", config.filtermail_smtp_port_incoming), ] for service, port in port_services: + print(f"Checking if port {port} is available for {service}...") running_service = host.get_fact(Port, port=port) - if running_service not in (service, None): - Out().red(f"Deploy failed: port {port} is occupied by: {running_service}") - exit(1) + if running_service: + if running_service not in service: + Out().red(f"Deploy failed: port {port} is occupied by: {running_service}") + exit(1) apt.packages( name="Install unbound", From ba06a4ff70e8c9a7ee41cd3e0e2b67705e8e4d71 Mon Sep 17 00:00:00 2001 From: missytake Date: Fri, 29 Aug 2025 16:19:03 +0200 Subject: [PATCH 20/23] cmdeploy: postfix runs on other ports as well, of course --- cmdeploy/src/cmdeploy/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index 042957d..9a4e422 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -681,13 +681,13 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: ("acmetool", 80), ("imap-login", 143), ("nginx", 443), - ("master", 465), - ("master", 587), + (["master", "smtpd"], 465), + (["master", "smtpd"], 587), ("imap-login", 993), ("iroh-relay", 3340), ("nginx", 8443), - ("master", config.postfix_reinject_port), - ("master", config.postfix_reinject_port_incoming), + (["master", "smtpd"], config.postfix_reinject_port), + (["master", "smtpd"], config.postfix_reinject_port_incoming), ("filtermail", config.filtermail_smtp_port), ("filtermail", config.filtermail_smtp_port_incoming), ] From 3b73457de3140ec28d42fc089bd332903202d042 Mon Sep 17 00:00:00 2001 From: missytake Date: Tue, 19 Aug 2025 10:46:23 +0200 Subject: [PATCH 21/23] www: introduce www_folder config item fix #529 --- CHANGELOG.md | 3 +++ README.md | 12 ++++++++++++ chatmaild/src/chatmaild/config.py | 1 + cmdeploy/src/cmdeploy/__init__.py | 26 +++++++++++++++++++------- cmdeploy/src/cmdeploy/www.py | 5 ++++- 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4727133..da339af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## untagged +- Make www upload path configurable + ([#618](https://github.com/chatmail/relay/pull/618)) + - Check whether GCC is installed in initenv.sh ([#608](https://github.com/chatmail/relay/pull/608)) diff --git a/README.md b/README.md index 7ba08fd..9f60d11 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,18 @@ This starts a local live development cycle for chatmail web pages: - Starts a browser window automatically where you can "refresh" as needed. +#### Custom web pages + +You can skip uploading a web page +by setting `www_folder=disabled` in `chatmail.ini`. + +If you want to manage your web pages outside this git repository, +you can set `www_folder` in `chatmail.ini` to a custom directory on your computer. +`cmdeploy run` will upload it as the server's home page, +and if it contains a `src/index.md` file, +will build it with hugo. + + ## Mailbox directory layout Fresh chatmail addresses have a mailbox directory that contains: diff --git a/chatmaild/src/chatmaild/config.py b/chatmaild/src/chatmaild/config.py index 0cac3ea..ec32314 100644 --- a/chatmaild/src/chatmaild/config.py +++ b/chatmaild/src/chatmaild/config.py @@ -33,6 +33,7 @@ class Config: self.password_min_length = int(params["password_min_length"]) self.passthrough_senders = params["passthrough_senders"].split() self.passthrough_recipients = params["passthrough_recipients"].split() + self.www_folder = params.get("www_folder") self.filtermail_smtp_port = int(params["filtermail_smtp_port"]) self.filtermail_smtp_port_incoming = int( params["filtermail_smtp_port_incoming"] diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index 9a4e422..6aa7c5b 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -11,7 +11,7 @@ from io import StringIO from pathlib import Path from chatmaild.config import Config, read_config -from pyinfra import facts, host +from pyinfra import facts, host, logger from pyinfra.api import FactBase from pyinfra.facts.files import File from pyinfra.facts.server import Sysctl @@ -751,12 +751,24 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: packages=["fcgiwrap"], ) - www_path = importlib.resources.files(__package__).joinpath("../../../www").resolve() - - build_dir = www_path.joinpath("build") - src_dir = www_path.joinpath("src") - build_webpages(src_dir, build_dir, config) - files.rsync(f"{build_dir}/", "/var/www/html", flags=["-avz"]) + reporoot = importlib.resources.files(__package__).joinpath("../../../").resolve() + www_path = Path(config.www_folder) + # if www_folder was not set, use default directory + if not config.www_folder: + www_path = reporoot.joinpath("www") + # if www_folder was set to a non-existing folder, skip upload + if not www_path.is_dir(): + logger.warning("Building web pages is disabled in chatmail.ini, skipping") + else: + build_dir = www_path.joinpath("build") + src_dir = www_path.joinpath("src") + # if www_folder is a hugo page, build it + if src_dir.joinpath("index.md").is_file(): + build_webpages(src_dir, build_dir, config) + # if it is not a hugo page, upload it as is + else: + build_dir = www_path + files.rsync(f"{build_dir}/", "/var/www/html", flags=["-avz"]) _install_remote_venv_with_chatmaild(config) debug = False diff --git a/cmdeploy/src/cmdeploy/www.py b/cmdeploy/src/cmdeploy/www.py index 9dd404b..253cc52 100644 --- a/cmdeploy/src/cmdeploy/www.py +++ b/cmdeploy/src/cmdeploy/www.py @@ -3,6 +3,7 @@ import importlib.resources import time import traceback import webbrowser +from pathlib import Path import markdown from chatmaild.config import read_config @@ -106,7 +107,9 @@ def main(): config = read_config(inipath) config.webdev = True assert config.mail_domain - www_path = reporoot.joinpath("www") + www_path = Path(config.www_folder) + if not config.www_folder: + www_path = reporoot.joinpath("www") src_path = www_path.joinpath("src") stats = None build_dir = www_path.joinpath("build") From d6fb38750a271c30f4ccdb9a70511b8d9ecc5830 Mon Sep 17 00:00:00 2001 From: missytake Date: Tue, 19 Aug 2025 12:39:58 +0200 Subject: [PATCH 22/23] www: make www_folder behavior testable --- chatmaild/src/chatmaild/config.py | 2 +- cmdeploy/src/cmdeploy/__init__.py | 18 +++-------- cmdeploy/src/cmdeploy/tests/test_cmdeploy.py | 27 ++++++++++++++++ cmdeploy/src/cmdeploy/www.py | 34 +++++++++++++------- 4 files changed, 55 insertions(+), 26 deletions(-) diff --git a/chatmaild/src/chatmaild/config.py b/chatmaild/src/chatmaild/config.py index ec32314..ae5f442 100644 --- a/chatmaild/src/chatmaild/config.py +++ b/chatmaild/src/chatmaild/config.py @@ -33,7 +33,7 @@ class Config: self.password_min_length = int(params["password_min_length"]) self.passthrough_senders = params["passthrough_senders"].split() self.passthrough_recipients = params["passthrough_recipients"].split() - self.www_folder = params.get("www_folder") + self.www_folder = params.get("www_folder", "") self.filtermail_smtp_port = int(params["filtermail_smtp_port"]) self.filtermail_smtp_port_incoming = int( params["filtermail_smtp_port_incoming"] diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index 6aa7c5b..4523be1 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -618,7 +618,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: check_config(config) mail_domain = config.mail_domain - from .www import build_webpages + from .www import build_webpages, get_paths server.group(name="Create vmail group", group="vmail", system=True) server.user(name="Create vmail user", user="vmail", group="vmail", system=True) @@ -751,24 +751,16 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: packages=["fcgiwrap"], ) - reporoot = importlib.resources.files(__package__).joinpath("../../../").resolve() - www_path = Path(config.www_folder) - # if www_folder was not set, use default directory - if not config.www_folder: - www_path = reporoot.joinpath("www") + www_path, src_dir, build_dir = get_paths(config) # if www_folder was set to a non-existing folder, skip upload if not www_path.is_dir(): logger.warning("Building web pages is disabled in chatmail.ini, skipping") else: - build_dir = www_path.joinpath("build") - src_dir = www_path.joinpath("src") # if www_folder is a hugo page, build it - if src_dir.joinpath("index.md").is_file(): - build_webpages(src_dir, build_dir, config) + if build_dir: + www_path = build_webpages(src_dir, build_dir, config) # if it is not a hugo page, upload it as is - else: - build_dir = www_path - files.rsync(f"{build_dir}/", "/var/www/html", flags=["-avz"]) + files.rsync(f"{www_path}/", "/var/www/html", flags=["-avz"]) _install_remote_venv_with_chatmaild(config) debug = False diff --git a/cmdeploy/src/cmdeploy/tests/test_cmdeploy.py b/cmdeploy/src/cmdeploy/tests/test_cmdeploy.py index 3084c8e..bdbc3db 100644 --- a/cmdeploy/src/cmdeploy/tests/test_cmdeploy.py +++ b/cmdeploy/src/cmdeploy/tests/test_cmdeploy.py @@ -1,8 +1,10 @@ +import importlib import os import pytest from cmdeploy.cmdeploy import get_parser, main +from cmdeploy.www import get_paths @pytest.fixture(autouse=True) @@ -27,3 +29,28 @@ class TestCmdline: assert main(["init", "chat.example.org"]) == 1 out, err = capsys.readouterr() assert "path exists" in out.lower() + + +def test_www_folder(example_config, tmp_path): + reporoot = importlib.resources.files(__package__).joinpath("../../../../").resolve() + assert not example_config.www_folder + www_path, src_dir, build_dir = get_paths(example_config) + assert www_path.absolute() == reporoot.joinpath("www").absolute() + assert src_dir == reporoot.joinpath("www").joinpath("src") + assert build_dir == reporoot.joinpath("www").joinpath("build") + example_config.www_folder = "disabled" + www_path, _, _ = get_paths(example_config) + assert not www_path.is_dir() + example_config.www_folder = str(tmp_path) + www_path, src_dir, build_dir = get_paths(example_config) + assert www_path == tmp_path + assert not src_dir.exists() + assert not build_dir + src_path = tmp_path.joinpath("src") + os.mkdir(src_path) + with open(src_path / "index.md", "w") as f: + f.write("# Test") + www_path, src_dir, build_dir = get_paths(example_config) + assert www_path == tmp_path + assert src_dir == src_path + assert build_dir == tmp_path.joinpath("build") diff --git a/cmdeploy/src/cmdeploy/www.py b/cmdeploy/src/cmdeploy/www.py index 253cc52..c013d74 100644 --- a/cmdeploy/src/cmdeploy/www.py +++ b/cmdeploy/src/cmdeploy/www.py @@ -31,9 +31,25 @@ def prepare_template(source): return render_vars, page_layout -def build_webpages(src_dir, build_dir, config): +def get_paths(config) -> (Path, Path, Path): + reporoot = importlib.resources.files(__package__).joinpath("../../../").resolve() + www_path = Path(config.www_folder) + # if www_folder was not set, use default directory + if config.www_folder == "": + www_path = reporoot.joinpath("www") + src_dir = www_path.joinpath("src") + # if www_folder is a hugo page, build it + if src_dir.joinpath("index.md").is_file(): + build_dir = www_path.joinpath("build") + # if it is not a hugo page, upload it as is + else: + build_dir = None + return www_path, src_dir, build_dir + + +def build_webpages(src_dir, build_dir, config) -> Path: try: - _build_webpages(src_dir, build_dir, config) + return _build_webpages(src_dir, build_dir, config) except Exception: print(traceback.format_exc()) @@ -107,17 +123,11 @@ def main(): config = read_config(inipath) config.webdev = True assert config.mail_domain - www_path = Path(config.www_folder) - if not config.www_folder: - www_path = reporoot.joinpath("www") - src_path = www_path.joinpath("src") - stats = None - build_dir = www_path.joinpath("build") - src_dir = www_path.joinpath("src") - index_path = build_dir.joinpath("index.html") # start web page generation, open a browser and wait for changes - build_webpages(src_dir, build_dir, config) + www_path, src_path, build_dir = get_paths(config) + build_dir = build_webpages(src_path, build_dir, config) + index_path = build_dir.joinpath("index.html") webbrowser.open(str(index_path)) stats = snapshot_dir_stats(src_path) print(f"\nOpened URL: file://{index_path.resolve()}\n") @@ -138,7 +148,7 @@ def main(): changenum += 1 stats = newstats - build_webpages(src_dir, build_dir, config) + build_webpages(src_path, build_dir, config) print(f"[{changenum}] regenerated web pages at: {index_path}") print(f"URL: file://{index_path.resolve()}\n\n") count = 0 From abd50e20ed42bd013326566a2f2b8ac970b98e6e Mon Sep 17 00:00:00 2001 From: missytake Date: Thu, 11 Sep 2025 20:22:11 +0200 Subject: [PATCH 23/23] cmdeploy: suppress SSH login info message --- cmdeploy/src/cmdeploy/cmdeploy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index bca3878..145c4bf 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -90,7 +90,7 @@ def run_cmd(args, out): retcode = out.check_call(cmd, env=env) if retcode == 0: print("\nYou can try out the relay by talking to this echo bot: ") - sshexec = args.get_sshexec() + sshexec = SSHExec(args.config.mail_domain, verbose=args.verbose) print( sshexec( call=remote.rshell.shell,