mirror of
https://github.com/chatmail/relay.git
synced 2026-05-12 00:54:37 +00:00
Compare commits
15 Commits
j4n/initen
...
link2xt/an
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b164c4d1b2 | ||
|
|
44fe2dc08f | ||
|
|
8721600d13 | ||
|
|
dfed2b4681 | ||
|
|
f5fd286663 | ||
|
|
16b00da373 | ||
|
|
75606f5eb8 | ||
|
|
d256538f81 | ||
|
|
fdf8e5e345 | ||
|
|
81a161d433 | ||
|
|
454ac6248a | ||
|
|
85915652b3 | ||
|
|
1e8c56e08a | ||
|
|
a65f082817 | ||
|
|
6c18d37772 |
6
.github/workflows/ci.yaml
vendored
6
.github/workflows/ci.yaml
vendored
@@ -9,6 +9,8 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
# Newest push wins: Prevents multiple runs from clashing and wasting runner efforts
|
# Newest push wins: Prevents multiple runs from clashing and wasting runner efforts
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
@@ -25,8 +27,9 @@ jobs:
|
|||||||
# Otherwise `test_deployed_state` will be unhappy.
|
# Otherwise `test_deployed_state` will be unhappy.
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
persist-credentials: false
|
||||||
- name: download filtermail
|
- name: download filtermail
|
||||||
run: curl -L https://github.com/chatmail/filtermail/releases/download/v0.6.1/filtermail-x86_64 -o /usr/local/bin/filtermail && chmod +x /usr/local/bin/filtermail
|
run: curl -L https://github.com/chatmail/filtermail/releases/download/v0.6.4/filtermail-x86_64 -o /usr/local/bin/filtermail && chmod +x /usr/local/bin/filtermail
|
||||||
- name: run chatmaild tests
|
- name: run chatmaild tests
|
||||||
working-directory: chatmaild
|
working-directory: chatmaild
|
||||||
run: pipx run tox
|
run: pipx run tox
|
||||||
@@ -38,6 +41,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- name: initenv
|
- name: initenv
|
||||||
run: scripts/initenv.sh
|
run: scripts/initenv.sh
|
||||||
|
|||||||
37
.github/workflows/docker-dispatch.yaml
vendored
Normal file
37
.github/workflows/docker-dispatch.yaml
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Notify the docker repo to build and test a new image after relay CI passes.
|
||||||
|
#
|
||||||
|
# Sends a repository_dispatch event to chatmail/docker with the relay ref
|
||||||
|
# and short SHA, which triggers docker-ci.yaml to build, push to GHCR,
|
||||||
|
# and run integration tests via cmlxc.
|
||||||
|
|
||||||
|
name: Trigger Docker build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
dispatch:
|
||||||
|
name: Dispatch build to chatmail/docker
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.repository == 'chatmail/relay'
|
||||||
|
steps:
|
||||||
|
- name: Compute short SHA
|
||||||
|
id: sha
|
||||||
|
run: echo "short=$(echo '${{ github.sha }}' | cut -c1-7)" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Send repository_dispatch
|
||||||
|
uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.CHATMAIL_DOCKER_DISPATCH_TOKEN }}
|
||||||
|
repository: chatmail/docker
|
||||||
|
event-type: relay-updated
|
||||||
|
client-payload: >-
|
||||||
|
{
|
||||||
|
"relay_ref": "${{ github.ref_name }}",
|
||||||
|
"relay_sha": "${{ github.sha }}",
|
||||||
|
"relay_sha_short": "${{ steps.sha.outputs.short }}"
|
||||||
|
}
|
||||||
14
.github/workflows/docs-preview.yaml
vendored
14
.github/workflows/docs-preview.yaml
vendored
@@ -7,6 +7,8 @@ on:
|
|||||||
- 'scripts/build-docs.sh'
|
- 'scripts/build-docs.sh'
|
||||||
- '.github/workflows/docs-preview.yaml'
|
- '.github/workflows/docs-preview.yaml'
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
scripts:
|
scripts:
|
||||||
name: build
|
name: build
|
||||||
@@ -16,6 +18,8 @@ jobs:
|
|||||||
url: https://staging.chatmail.at/doc/relay/${{ steps.prepare.outputs.prid }}
|
url: https://staging.chatmail.at/doc/relay/${{ steps.prepare.outputs.prid }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- name: initenv
|
- name: initenv
|
||||||
run: scripts/initenv.sh
|
run: scripts/initenv.sh
|
||||||
@@ -34,18 +38,22 @@ jobs:
|
|||||||
- name: Get Pullrequest ID
|
- name: Get Pullrequest ID
|
||||||
id: prepare
|
id: prepare
|
||||||
run: |
|
run: |
|
||||||
export PULLREQUEST_ID=$(echo "${{ github.ref }}" | cut -d "/" -f3)
|
export PULLREQUEST_ID=$(echo "${GITHUB_REF}" | cut -d "/" -f3)
|
||||||
echo "prid=$PULLREQUEST_ID" >> $GITHUB_OUTPUT
|
echo "prid=$PULLREQUEST_ID" >> $GITHUB_OUTPUT
|
||||||
if [ $(expr length "${{ secrets.USERNAME }}") -gt "1" ]; then echo "uploadtoserver=true" >> $GITHUB_OUTPUT; fi
|
if [ $(expr length "${{ secrets.USERNAME }}") -gt "1" ]; then echo "uploadtoserver=true" >> $GITHUB_OUTPUT; fi
|
||||||
- run: |
|
- run: |
|
||||||
echo "baseurl: /${{ steps.prepare.outputs.prid }}" >> _config.yml
|
echo "baseurl: /${STEPS_PREPARE_OUTPUTS_PRID}" >> _config.yml
|
||||||
|
env:
|
||||||
|
STEPS_PREPARE_OUTPUTS_PRID: ${{ steps.prepare.outputs.prid }}
|
||||||
|
|
||||||
- name: Upload preview
|
- name: Upload preview
|
||||||
run: |
|
run: |
|
||||||
mkdir -p "$HOME/.ssh"
|
mkdir -p "$HOME/.ssh"
|
||||||
echo "${{ secrets.CHATMAIL_STAGING_SSHKEY }}" > "$HOME/.ssh/key"
|
echo "${{ secrets.CHATMAIL_STAGING_SSHKEY }}" > "$HOME/.ssh/key"
|
||||||
chmod 600 "$HOME/.ssh/key"
|
chmod 600 "$HOME/.ssh/key"
|
||||||
rsync -rILvh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/doc/build/ "${{ secrets.USERNAME }}@chatmail.at:/var/www/html/staging.chatmail.at/doc/relay/${{ steps.prepare.outputs.prid }}/"
|
rsync -rILvh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/doc/build/ "${{ secrets.USERNAME }}@chatmail.at:/var/www/html/staging.chatmail.at/doc/relay/${STEPS_PREPARE_OUTPUTS_PRID}/"
|
||||||
|
env:
|
||||||
|
STEPS_PREPARE_OUTPUTS_PRID: ${{ steps.prepare.outputs.prid }}
|
||||||
|
|
||||||
- name: check links
|
- name: check links
|
||||||
working-directory: doc
|
working-directory: doc
|
||||||
|
|||||||
4
.github/workflows/docs.yaml
vendored
4
.github/workflows/docs.yaml
vendored
@@ -10,6 +10,8 @@ on:
|
|||||||
- 'scripts/build-docs.sh'
|
- 'scripts/build-docs.sh'
|
||||||
- '.github/workflows/docs.yaml'
|
- '.github/workflows/docs.yaml'
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
scripts:
|
scripts:
|
||||||
name: build
|
name: build
|
||||||
@@ -19,6 +21,8 @@ jobs:
|
|||||||
url: https://chatmail.at/doc/relay/
|
url: https://chatmail.at/doc/relay/
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- name: initenv
|
- name: initenv
|
||||||
run: scripts/initenv.sh
|
run: scripts/initenv.sh
|
||||||
|
|||||||
26
.github/workflows/zizmor-scan.yml
vendored
Normal file
26
.github/workflows/zizmor-scan.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
name: GitHub Actions Security Analysis with zizmor
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["main"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["**"]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
zizmor:
|
||||||
|
name: Run zizmor
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
security-events: write # Required for upload-sarif (used by zizmor-action) to upload SARIF files.
|
||||||
|
contents: read
|
||||||
|
actions: read
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Run zizmor
|
||||||
|
uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3
|
||||||
7
.github/zizmor.yml
vendored
Normal file
7
.github/zizmor.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
rules:
|
||||||
|
unpinned-uses:
|
||||||
|
config:
|
||||||
|
policies:
|
||||||
|
actions/*: ref-pin
|
||||||
|
dependabot/*: ref-pin
|
||||||
|
chatmail/*: ref-pin
|
||||||
84
CHANGELOG.md
84
CHANGELOG.md
@@ -1,5 +1,89 @@
|
|||||||
# Changelog for chatmail deployment
|
# Changelog for chatmail deployment
|
||||||
|
|
||||||
|
## 1.10.0 2026-04-30
|
||||||
|
|
||||||
|
* start mtail after networking is fully up <https://github.com/chatmail/relay/pull/942>
|
||||||
|
* support specifying custom filtermail binary through environment variable <https://github.com/chatmail/relay/pull/941>
|
||||||
|
* add automated zizmor scanning of github workflows <https://github.com/chatmail/relay/pull/938>
|
||||||
|
* added dispatch for *automated builds of chatmail relay docker images* <https://github.com/chatmail/relay/pull/934>
|
||||||
|
* do not bind SMTP client sockets to public addresses <https://github.com/chatmail/relay/pull/932>
|
||||||
|
* underline in docs that scripts/initenv.sh should be used for building the docs <https://github.com/chatmail/relay/pull/933>
|
||||||
|
* automatic oldest-first message removal from mailboxes to always stay under max_mailbox_size <https://github.com/chatmail/relay/pull/929>
|
||||||
|
* remove --slow from cmdeploy test <https://github.com/chatmail/relay/pull/931>
|
||||||
|
* handle missing inotify sysctl keys in containers <https://github.com/chatmail/relay/pull/930>
|
||||||
|
* replace resolvconf with static resolv.conf <https://github.com/chatmail/relay/pull/928>
|
||||||
|
* disable fsync for LMTP and IMAP services <https://github.com/chatmail/relay/pull/925>
|
||||||
|
* re-use cmlxc workflow, replacing CI with hetzner staging servers with local lxc containers <https://github.com/chatmail/relay/pull/917>
|
||||||
|
* explicitly install resolvconf <https://github.com/chatmail/relay/pull/924>
|
||||||
|
* detect stale dovecot binary and force restart in activate() <https://github.com/chatmail/relay/pull/922>
|
||||||
|
* Rename filtermail_http_port to filtermail_http_port_incoming <https://github.com/chatmail/relay/pull/921>
|
||||||
|
* consolidated is_in_container() check https://github.com/chatmail/relay/pull/920>
|
||||||
|
* restart dovecot after package replacement (rebase, test condense) <https://github.com/chatmail/relay/pull/913>
|
||||||
|
* Set permissions on dovecot pin prefs <https://github.com/chatmail/relay/pull/915>
|
||||||
|
* Route `/mxdeliv/` to configurable port <https://github.com/chatmail/relay/pull/901>
|
||||||
|
* fix VM detection, automated testing fixes, use newer chatmail-turn and move to standard BIND DNS zone format <https://github.com/chatmail/relay/pull/912>
|
||||||
|
* Upgrade to filtermail 0.6.1 <https://github.com/chatmail/relay/pull/910>
|
||||||
|
* pin dovecot packages to prevent apt upgrades <https://github.com/chatmail/relay/pull/908>
|
||||||
|
* add rpc server to cmdeploy along with client <https://github.com/chatmail/relay/pull/906>
|
||||||
|
* remove unused deps from chatmaild <https://github.com/chatmail/relay/pull/905>
|
||||||
|
* set default smtp_tls_security_level to "verify" unconditionally <https://github.com/chatmail/relay/pull/902>
|
||||||
|
* featprefer IPv4 in SMTP client <https://github.com/chatmail/relay/pull/900>
|
||||||
|
* Install dovecot .deb packages atomically <https://github.com/chatmail/relay/pull/899>
|
||||||
|
* stop installing cron package <https://github.com/chatmail/relay/pull/898>
|
||||||
|
* Rewrite dovecot install logic, update <https://github.com/chatmail/relay/pull/862>
|
||||||
|
* fix a test and some linting fixes <https://github.com/chatmail/relay/pull/897>
|
||||||
|
* Disable IP verification on domain-literal addresses <https://github.com/chatmail/relay/pull/895>
|
||||||
|
* disable installing recommended packages globally on the relay <https://github.com/chatmail/relay/pull/887>
|
||||||
|
* multiple bug fixes across chatmaild and cmdeploy <https://github.com/chatmail/relay/pull/883>
|
||||||
|
* remove /metrics from the website <https://github.com/chatmail/relay/pull/703>
|
||||||
|
* add Prometheus textfile output to fsreport <https://github.com/chatmail/relay/pull/881>
|
||||||
|
* chown opendkim: private key <https://github.com/chatmail/relay/pull/879>
|
||||||
|
* make sure chatmail-metadata was started <https://github.com/chatmail/relay/pull/882>
|
||||||
|
* dovecot update url <https://github.com/chatmail/relay/pull/880>
|
||||||
|
* upgrade to filtermail v0.5.2 <https://github.com/chatmail/relay/pull/876>
|
||||||
|
* download dovecot packages from github release <https://github.com/chatmail/relay/pull/875>
|
||||||
|
* replace DKIM verification with filtermail v0.5 <https://github.com/chatmail/relay/pull/831>
|
||||||
|
* remove CFFI deltachat bindings usage, and consolidate test support with rpc-bindings <https://github.com/chatmail/relay/pull/872>
|
||||||
|
* prepare chatmaild/cmdeploy changes for Docker support <https://github.com/chatmail/relay/pull/857>
|
||||||
|
* stabilize online benchmark timing adding rate-limit-aware cooldown between iterations <https://github.com/chatmail/relay/pull/867>
|
||||||
|
* move rate-limit cooldown to benchmark fixture <https://github.com/chatmail/relay/pull/868>
|
||||||
|
* reconfigure acmetool from redirector to proxy mode <https://github.com/chatmail/relay/pull/861>
|
||||||
|
* make tests work with `--ssh-host localhost` <https://github.com/chatmail/relay/pull/856>
|
||||||
|
* mark f-string with f prefix in test_expunged <https://github.com/chatmail/relay/pull/863>
|
||||||
|
* install also if dovecot.service=False in SystemdEnabled Fact <https://github.com/chatmail/relay/pull/841>
|
||||||
|
* Introduce support for self-signed chatmail relays <https://github.com/chatmail/relay/pull/855>
|
||||||
|
* Strip Received headers before delivery <https://github.com/chatmail/relay/pull/849>
|
||||||
|
* upgrade to filtermail v0.3 <https://github.com/chatmail/relay/pull/850>
|
||||||
|
* fix link to Maddy and update madmail URL <https://github.com/chatmail/relay/pull/847>
|
||||||
|
* accept self-signed certificates for IP-only relays <https://github.com/chatmail/relay/pull/846>
|
||||||
|
* enforce sending from public IP addresses <https://github.com/chatmail/relay/pull/845>
|
||||||
|
* port check: check addresses, fix single services <https://github.com/chatmail/relay/pull/844>
|
||||||
|
* remediates issue with improper concat on resolver injection <https://github.com/chatmail/relay/pull/834>
|
||||||
|
* ipv6 boolean not being respected during operations <https://github.com/chatmail/relay/pull/832>
|
||||||
|
* upgrade to filtermail v0.2 by <https://github.com/chatmail/relay/pull/825>
|
||||||
|
* fix link to filtermail <https://github.com/chatmail/relay/pull/824>
|
||||||
|
* print timestamps when sending messages <https://github.com/chatmail/relay/pull/823>
|
||||||
|
* fix flaky test_exceed_rate_limit <https://github.com/chatmail/relay/pull/822>
|
||||||
|
* Replace filtermail with rust reimplementation <https://github.com/chatmail/relay/pull/808>
|
||||||
|
* Set default internal SMTP ports in Config <https://github.com/chatmail/relay/pull/819>
|
||||||
|
* separate metrics for incoming and outgoing messages <https://github.com/chatmail/relay/pull/820>
|
||||||
|
* disable appending the Received header <https://github.com/chatmail/relay/pull/815>
|
||||||
|
* fail on errors in postfix/dovecot config <https://github.com/chatmail/relay/pull/813>
|
||||||
|
* tweak idle/hibernate metrics some more <https://github.com/chatmail/relay/pull/811>
|
||||||
|
* add config flag to export statistics <https://github.com/chatmail/relay/pull/806>
|
||||||
|
* add --website-only option to run subcommand <https://github.com/chatmail/relay/pull/768>
|
||||||
|
* Strip DKIM-Signature header before LMTP <https://github.com/chatmail/relay/pull/803>
|
||||||
|
* properly make sure that postfix gets restarted on failure <https://github.com/chatmail/relay/pull/802>
|
||||||
|
* expire.py: use absolute path to maildirsize <https://github.com/chatmail/relay/pull/807>
|
||||||
|
* pin Dovecot documentation URLs to version 2.3 <https://github.com/chatmail/relay/pull/800>
|
||||||
|
* try to use "build machine" and "deployment server" consistently <https://github.com/chatmail/relay/pull/797>
|
||||||
|
* adds instructions for migrating control machines <https://github.com/chatmail/relay/pull/795>
|
||||||
|
* use consistent naming schema in getting started <https://github.com/chatmail/relay/pull/793>
|
||||||
|
* remove jsok/serialize-workflow-action dependency <https://github.com/chatmail/relay/pull/790>
|
||||||
|
* streamline migration guide wording, provide titled steps <https://github.com/chatmail/relay/pull/789>
|
||||||
|
* increases default max mailbox size <https://github.com/chatmail/relay/pull/792>
|
||||||
|
* use daemon_name for OpenDKIM sign-verify decision instead of IP <https://github.com/chatmail/relay/pull/784>
|
||||||
|
|
||||||
## 1.9.0 2025-12-18
|
## 1.9.0 2025-12-18
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ where = ['src']
|
|||||||
[project.scripts]
|
[project.scripts]
|
||||||
doveauth = "chatmaild.doveauth:main"
|
doveauth = "chatmaild.doveauth:main"
|
||||||
chatmail-metadata = "chatmaild.metadata:main"
|
chatmail-metadata = "chatmaild.metadata:main"
|
||||||
chatmail-expire = "chatmaild.expire:main"
|
chatmail-expire = "chatmaild.expire:daily_expire_main"
|
||||||
|
chatmail-quota-expire = "chatmaild.expire:quota_expire_main"
|
||||||
chatmail-fsreport = "chatmaild.fsreport:main"
|
chatmail-fsreport = "chatmaild.fsreport:main"
|
||||||
|
chatmail-deferred = "chatmaild.deferred:main"
|
||||||
lastlogin = "chatmaild.lastlogin:main"
|
lastlogin = "chatmaild.lastlogin:main"
|
||||||
turnserver = "chatmaild.turnserver:main"
|
turnserver = "chatmaild.turnserver:main"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import iniconfig
|
import iniconfig
|
||||||
@@ -41,14 +40,15 @@ class Config:
|
|||||||
self.filtermail_http_port_incoming = int(
|
self.filtermail_http_port_incoming = int(
|
||||||
params.get("filtermail_http_port_incoming", "10082")
|
params.get("filtermail_http_port_incoming", "10082")
|
||||||
)
|
)
|
||||||
|
self.filtermail_lmtp_port_transport = int(
|
||||||
|
params.get("filtermail_lmtp_port_transport", "10083")
|
||||||
|
)
|
||||||
self.postfix_reinject_port = int(params.get("postfix_reinject_port", "10025"))
|
self.postfix_reinject_port = int(params.get("postfix_reinject_port", "10025"))
|
||||||
self.postfix_reinject_port_incoming = int(
|
self.postfix_reinject_port_incoming = int(
|
||||||
params.get("postfix_reinject_port_incoming", "10026")
|
params.get("postfix_reinject_port_incoming", "10026")
|
||||||
)
|
)
|
||||||
self.mtail_address = params.get("mtail_address")
|
self.mtail_address = params.get("mtail_address")
|
||||||
self.disable_ipv6 = params.get("disable_ipv6", "false").lower() == "true"
|
self.disable_ipv6 = params.get("disable_ipv6", "false").lower() == "true"
|
||||||
self.addr_v4 = os.environ.get("CHATMAIL_ADDR_V4", "")
|
|
||||||
self.addr_v6 = os.environ.get("CHATMAIL_ADDR_V6", "")
|
|
||||||
self.acme_email = params.get("acme_email", "")
|
self.acme_email = params.get("acme_email", "")
|
||||||
self.imap_rawlog = params.get("imap_rawlog", "false").lower() == "true"
|
self.imap_rawlog = params.get("imap_rawlog", "false").lower() == "true"
|
||||||
self.imap_compress = params.get("imap_compress", "false").lower() == "true"
|
self.imap_compress = params.get("imap_compress", "false").lower() == "true"
|
||||||
@@ -95,6 +95,11 @@ class Config:
|
|||||||
# old unused option (except for first migration from sqlite to maildir store)
|
# old unused option (except for first migration from sqlite to maildir store)
|
||||||
self.passdb_path = Path(params.get("passdb_path", "/home/vmail/passdb.sqlite"))
|
self.passdb_path = Path(params.get("passdb_path", "/home/vmail/passdb.sqlite"))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_mailbox_size_mb(self):
|
||||||
|
"""Return max_mailbox_size as an integer in megabytes."""
|
||||||
|
return parse_size_mb(self.max_mailbox_size)
|
||||||
|
|
||||||
def _getbytefile(self):
|
def _getbytefile(self):
|
||||||
return open(self._inipath, "rb")
|
return open(self._inipath, "rb")
|
||||||
|
|
||||||
@@ -108,6 +113,16 @@ class Config:
|
|||||||
return User(maildir, addr, password_path, uid="vmail", gid="vmail")
|
return User(maildir, addr, password_path, uid="vmail", gid="vmail")
|
||||||
|
|
||||||
|
|
||||||
|
def parse_size_mb(limit):
|
||||||
|
"""Parse a size string like ``500M`` or ``2G`` and return megabytes."""
|
||||||
|
value = limit.strip().upper().removesuffix("B")
|
||||||
|
if value.endswith("G"):
|
||||||
|
return int(value[:-1]) * 1024
|
||||||
|
if value.endswith("M"):
|
||||||
|
return int(value[:-1])
|
||||||
|
return int(value)
|
||||||
|
|
||||||
|
|
||||||
def write_initial_config(inipath, mail_domain, overrides):
|
def write_initial_config(inipath, mail_domain, overrides):
|
||||||
"""Write out default config file, using the specified config value overrides."""
|
"""Write out default config file, using the specified config value overrides."""
|
||||||
content = get_default_config_content(mail_domain, **overrides)
|
content = get_default_config_content(mail_domain, **overrides)
|
||||||
|
|||||||
37
chatmaild/src/chatmaild/deferred.py
Normal file
37
chatmaild/src/chatmaild/deferred.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
"""
|
||||||
|
Analyze deferred mails and print most common failing destinations.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
python -m chatmaild.deferred
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
from collections import Counter, defaultdict
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
p = subprocess.Popen(["postqueue", "-j"], text=True, stdout=subprocess.PIPE)
|
||||||
|
domain_reasons = defaultdict(Counter)
|
||||||
|
domain_total = Counter()
|
||||||
|
|
||||||
|
for line in p.stdout:
|
||||||
|
item = json.loads(line)
|
||||||
|
if item["queue_name"] != "deferred":
|
||||||
|
continue
|
||||||
|
|
||||||
|
for recipient in item["recipients"]:
|
||||||
|
_, domain = recipient["address"].rsplit("@", 1)
|
||||||
|
reason = recipient["delay_reason"]
|
||||||
|
domain_total[domain] += 1
|
||||||
|
domain_reasons[domain][reason] += 1
|
||||||
|
|
||||||
|
for domain, total in reversed(domain_total.most_common()):
|
||||||
|
print(f"{domain} ({total} recipients)")
|
||||||
|
for reason, count in domain_reasons[domain].most_common():
|
||||||
|
print(f" {count}: {reason}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -4,17 +4,26 @@ Expire old messages and addresses.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
from stat import S_ISREG
|
from stat import S_ISREG
|
||||||
|
|
||||||
from chatmaild.config import read_config
|
from chatmaild.config import read_config
|
||||||
|
|
||||||
FileEntry = namedtuple("FileEntry", ("path", "mtime", "size"))
|
FileEntry = namedtuple("FileEntry", ("path", "mtime", "size"))
|
||||||
|
QuotaFileEntry = namedtuple("QuotaFileEntry", ("mtime", "quota_size", "path"))
|
||||||
|
|
||||||
|
# Quota cleanup factor of max_mailbox_size. The mailbox is reset to this size.
|
||||||
|
QUOTA_CLEANUP_FACTOR = 0.7
|
||||||
|
|
||||||
|
# e.g. "cur/1775324677.M448978P3029757.exam,S=3235,W=3305:2,S"
|
||||||
|
_dovecot_fn_rex = re.compile(r".+/(\d+)\..+,S=(\d+)")
|
||||||
|
|
||||||
|
|
||||||
def iter_mailboxes(basedir, maxnum):
|
def iter_mailboxes(basedir, maxnum):
|
||||||
@@ -74,6 +83,42 @@ class MailboxStat:
|
|||||||
self.extrafiles.sort(key=lambda x: -x.size)
|
self.extrafiles.sort(key=lambda x: -x.size)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_dovecot_filename(relpath):
|
||||||
|
m = _dovecot_fn_rex.match(relpath)
|
||||||
|
if not m:
|
||||||
|
return None
|
||||||
|
return QuotaFileEntry(int(m.group(1)), int(m.group(2)), relpath)
|
||||||
|
|
||||||
|
|
||||||
|
def scan_mailbox_messages(mbox):
|
||||||
|
messages = []
|
||||||
|
for sub in ("cur", "new"):
|
||||||
|
for name in os_listdir_if_exists(mbox / sub):
|
||||||
|
if entry := parse_dovecot_filename(f"{sub}/{name}"):
|
||||||
|
messages.append(entry)
|
||||||
|
return messages
|
||||||
|
|
||||||
|
|
||||||
|
def expire_to_target(mbox, target_bytes):
|
||||||
|
messages = scan_mailbox_messages(mbox)
|
||||||
|
total_size = sum(m.quota_size for m in messages)
|
||||||
|
# Keep recent 24 hours of messages protected from expiry because
|
||||||
|
# likely something is wrong with interactions on that address
|
||||||
|
# and quota-full signal can help the address owner's device to notice it
|
||||||
|
undeletable_messages_cutoff = time.time() - (3600 * 24)
|
||||||
|
removed = 0
|
||||||
|
for entry in sorted(messages):
|
||||||
|
if total_size <= target_bytes:
|
||||||
|
break
|
||||||
|
if entry.mtime > undeletable_messages_cutoff:
|
||||||
|
break
|
||||||
|
(mbox / entry.path).unlink(missing_ok=True)
|
||||||
|
total_size -= entry.quota_size
|
||||||
|
removed += 1
|
||||||
|
|
||||||
|
return removed
|
||||||
|
|
||||||
|
|
||||||
def print_info(msg):
|
def print_info(msg):
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
|
|
||||||
@@ -143,6 +188,19 @@ class Expiry:
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
target_bytes = (
|
||||||
|
self.config.max_mailbox_size_mb * 1024 * 1024 * QUOTA_CLEANUP_FACTOR
|
||||||
|
)
|
||||||
|
removed = expire_to_target(Path(mbox.basedir), target_bytes)
|
||||||
|
if removed:
|
||||||
|
changed = True
|
||||||
|
self.del_files += removed
|
||||||
|
if self.verbose:
|
||||||
|
print_info(
|
||||||
|
f"quota-expire: removed {removed} message(s) from {mboxname}"
|
||||||
|
)
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
self.remove_file(f"{mbox.basedir}/maildirsize")
|
self.remove_file(f"{mbox.basedir}/maildirsize")
|
||||||
|
|
||||||
@@ -154,9 +212,9 @@ class Expiry:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def daily_expire_main(args=None):
|
||||||
"""Expire mailboxes and messages according to chatmail config"""
|
"""Expire mailboxes and messages according to chatmail config"""
|
||||||
parser = ArgumentParser(description=main.__doc__)
|
parser = ArgumentParser(description=daily_expire_main.__doc__)
|
||||||
ini = "/usr/local/lib/chatmaild/chatmail.ini"
|
ini = "/usr/local/lib/chatmaild/chatmail.ini"
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"chatmail_ini",
|
"chatmail_ini",
|
||||||
@@ -202,5 +260,33 @@ def main(args=None):
|
|||||||
print(exp.get_summary())
|
print(exp.get_summary())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def quota_expire_main(args=None):
|
||||||
main(sys.argv[1:])
|
"""Remove mailbox messages to stay within a megabyte target.
|
||||||
|
|
||||||
|
This entry point is called by dovecot when a quota threshold is passed.
|
||||||
|
"""
|
||||||
|
|
||||||
|
parser = ArgumentParser(description=quota_expire_main.__doc__)
|
||||||
|
parser.add_argument(
|
||||||
|
"target_mb",
|
||||||
|
type=int,
|
||||||
|
help="target mailbox size in megabytes",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"mailbox_path",
|
||||||
|
type=Path,
|
||||||
|
help="path to a user mailbox",
|
||||||
|
)
|
||||||
|
args = parser.parse_args(args)
|
||||||
|
|
||||||
|
target_bytes = args.target_mb * 1024 * 1024
|
||||||
|
|
||||||
|
removed_count = expire_to_target(args.mailbox_path, target_bytes)
|
||||||
|
if removed_count:
|
||||||
|
(args.mailbox_path / "maildirsize").unlink(missing_ok=True)
|
||||||
|
print(
|
||||||
|
f"quota-expire: removed {removed_count} message(s)"
|
||||||
|
f" from {args.mailbox_path.name}",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
return 0
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ max_user_send_per_minute = 60
|
|||||||
max_user_send_burst_size = 10
|
max_user_send_burst_size = 10
|
||||||
|
|
||||||
# maximum mailbox size of a chatmail address
|
# maximum mailbox size of a chatmail address
|
||||||
|
# Oldest messages will be removed automatically, so mailboxes never run full.
|
||||||
max_mailbox_size = 500M
|
max_mailbox_size = 500M
|
||||||
|
|
||||||
# maximum message size for an e-mail in bytes
|
# maximum message size for an e-mail in bytes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from chatmaild.config import read_config
|
from chatmaild.config import parse_size_mb, read_config
|
||||||
|
|
||||||
|
|
||||||
def test_read_config_basic(example_config):
|
def test_read_config_basic(example_config):
|
||||||
@@ -121,3 +121,17 @@ def test_config_tls_external_bad_format(make_config):
|
|||||||
"tls_external_cert_and_key": "/only/one/path.pem",
|
"tls_external_cert_and_key": "/only/one/path.pem",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_size_mb():
|
||||||
|
assert parse_size_mb("500M") == 500
|
||||||
|
assert parse_size_mb("2G") == 2048
|
||||||
|
assert parse_size_mb(" 1g ") == 1024
|
||||||
|
assert parse_size_mb("100MB") == 100
|
||||||
|
assert parse_size_mb("256") == 256
|
||||||
|
|
||||||
|
|
||||||
|
def test_max_mailbox_size_mb(make_config):
|
||||||
|
config = make_config("chat.example.org")
|
||||||
|
assert config.max_mailbox_size == "500M"
|
||||||
|
assert config.max_mailbox_size_mb == 500
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from chatmaild.doveauth import AuthDictProxy
|
from chatmaild.doveauth import AuthDictProxy
|
||||||
from chatmaild.expire import main as main_expire
|
from chatmaild.expire import daily_expire_main as main_expire
|
||||||
|
|
||||||
|
|
||||||
def test_login_timestamps(example_config):
|
def test_login_timestamps(example_config):
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import itertools
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -9,13 +11,19 @@ import pytest
|
|||||||
from chatmaild.expire import (
|
from chatmaild.expire import (
|
||||||
FileEntry,
|
FileEntry,
|
||||||
MailboxStat,
|
MailboxStat,
|
||||||
|
expire_to_target,
|
||||||
get_file_entry,
|
get_file_entry,
|
||||||
iter_mailboxes,
|
iter_mailboxes,
|
||||||
os_listdir_if_exists,
|
os_listdir_if_exists,
|
||||||
|
parse_dovecot_filename,
|
||||||
|
quota_expire_main,
|
||||||
|
scan_mailbox_messages,
|
||||||
)
|
)
|
||||||
from chatmaild.expire import main as expiry_main
|
from chatmaild.expire import daily_expire_main as expiry_main
|
||||||
from chatmaild.fsreport import main as report_main
|
from chatmaild.fsreport import main as report_main
|
||||||
|
|
||||||
|
MB = 1024 * 1024
|
||||||
|
|
||||||
|
|
||||||
def fill_mbox(folderdir):
|
def fill_mbox(folderdir):
|
||||||
password = folderdir.joinpath("password")
|
password = folderdir.joinpath("password")
|
||||||
@@ -196,3 +204,51 @@ def test_os_listdir_if_exists(tmp_path):
|
|||||||
tmp_path.joinpath("x").write_text("hello")
|
tmp_path.joinpath("x").write_text("hello")
|
||||||
assert len(os_listdir_if_exists(str(tmp_path))) == 1
|
assert len(os_listdir_if_exists(str(tmp_path))) == 1
|
||||||
assert len(os_listdir_if_exists(str(tmp_path.joinpath("123123")))) == 0
|
assert len(os_listdir_if_exists(str(tmp_path.joinpath("123123")))) == 0
|
||||||
|
|
||||||
|
|
||||||
|
# --- quota expire tests ---
|
||||||
|
|
||||||
|
_msg_counter = itertools.count(1)
|
||||||
|
|
||||||
|
|
||||||
|
def _create_message(basedir, sub, size, days_old=0, disk_size=None):
|
||||||
|
seq = next(_msg_counter)
|
||||||
|
mtime = int(time.time() - days_old * 86400)
|
||||||
|
name = f"{mtime}.M1P1Q{seq}.hostname,S={size},W={size}:2,S"
|
||||||
|
path = basedir / sub / name
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
path.write_bytes(b"x" * (disk_size if disk_size is not None else size))
|
||||||
|
os.utime(path, (mtime, mtime))
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_dovecot_filename():
|
||||||
|
e = parse_dovecot_filename("cur/1775324677.M448978P3029757.exam,S=3235,W=3305:2,S")
|
||||||
|
assert e.path == "cur/1775324677.M448978P3029757.exam,S=3235,W=3305:2,S"
|
||||||
|
assert e.mtime == 1775324677
|
||||||
|
assert e.quota_size == 3235
|
||||||
|
assert parse_dovecot_filename("cur/msg_without_structure") is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_expire_to_target(tmp_path):
|
||||||
|
_create_message(tmp_path, "cur", MB, days_old=10, disk_size=100)
|
||||||
|
_create_message(tmp_path, "new", MB, days_old=5)
|
||||||
|
_create_message(tmp_path, "cur", MB, days_old=0) # undeletable (<1 hour)
|
||||||
|
assert len(scan_mailbox_messages(tmp_path)) == 3
|
||||||
|
# removes oldest first, uses S= size not disk size
|
||||||
|
removed = expire_to_target(tmp_path, MB)
|
||||||
|
assert removed == 2
|
||||||
|
msgs = scan_mailbox_messages(tmp_path)
|
||||||
|
assert len(msgs) == 1
|
||||||
|
# the surviving message is the fresh undeletable one
|
||||||
|
assert msgs[0].mtime > time.time() - 3600
|
||||||
|
|
||||||
|
|
||||||
|
def test_quota_expire_main(tmp_path, capsys):
|
||||||
|
mbox = tmp_path / "user@example.org"
|
||||||
|
_create_message(mbox, "cur", 2 * MB, days_old=5)
|
||||||
|
(mbox / "maildirsize").write_text("x")
|
||||||
|
quota_expire_main([str(1), str(mbox)])
|
||||||
|
_, err = capsys.readouterr()
|
||||||
|
assert "quota-expire: removed 1 message(s) from user@example.org" in err
|
||||||
|
assert not (mbox / "maildirsize").exists()
|
||||||
|
|||||||
@@ -101,9 +101,6 @@ def run_cmd(args, out):
|
|||||||
env["CHATMAIL_WEBSITE_ONLY"] = "True" if args.website_only else ""
|
env["CHATMAIL_WEBSITE_ONLY"] = "True" if args.website_only else ""
|
||||||
env["CHATMAIL_DISABLE_MAIL"] = "True" if args.disable_mail else ""
|
env["CHATMAIL_DISABLE_MAIL"] = "True" if args.disable_mail else ""
|
||||||
env["CHATMAIL_REQUIRE_IROH"] = "True" if require_iroh else ""
|
env["CHATMAIL_REQUIRE_IROH"] = "True" if require_iroh else ""
|
||||||
if not args.dns_check_disabled:
|
|
||||||
env["CHATMAIL_ADDR_V4"] = remote_data.get("A") or ""
|
|
||||||
env["CHATMAIL_ADDR_V6"] = remote_data.get("AAAA") or ""
|
|
||||||
deploy_path = importlib.resources.files(__package__).joinpath("run.py").resolve()
|
deploy_path = importlib.resources.files(__package__).joinpath("run.py").resolve()
|
||||||
pyinf = "pyinfra --dry" if args.dry_run else "pyinfra"
|
pyinf = "pyinfra --dry" if args.dry_run else "pyinfra"
|
||||||
|
|
||||||
@@ -194,12 +191,6 @@ def status_cmd(args, out):
|
|||||||
|
|
||||||
|
|
||||||
def test_cmd_options(parser):
|
def test_cmd_options(parser):
|
||||||
parser.add_argument(
|
|
||||||
"--slow",
|
|
||||||
dest="slow",
|
|
||||||
action="store_true",
|
|
||||||
help="also run slow tests",
|
|
||||||
)
|
|
||||||
add_ssh_host_option(parser)
|
add_ssh_host_option(parser)
|
||||||
|
|
||||||
|
|
||||||
@@ -221,8 +212,6 @@ def test_cmd(args, out):
|
|||||||
"-v",
|
"-v",
|
||||||
"--durations=5",
|
"--durations=5",
|
||||||
]
|
]
|
||||||
if args.slow:
|
|
||||||
pytest_args.append("--slow")
|
|
||||||
ret = out.run_ret(pytest_args, env=env)
|
ret = out.run_ret(pytest_args, env=env)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
@@ -149,12 +149,26 @@ plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin {
|
plugin {
|
||||||
# for now we define static quota-rules for all users
|
|
||||||
quota = maildir:User quota
|
quota = maildir:User quota
|
||||||
quota_rule = *:storage={{ config.max_mailbox_size }}
|
|
||||||
quota_max_mail_size={{ config.max_message_size }}
|
quota_max_mail_size={{ config.max_message_size }}
|
||||||
quota_grace = 0
|
quota_grace = 0
|
||||||
# quota_over_flag_value = TRUE
|
|
||||||
|
quota_rule = *:storage={{ config.max_mailbox_size_mb }}M
|
||||||
|
|
||||||
|
# Trigger at 75%% of quota, expire oldest messages down to 70%%.
|
||||||
|
# The percentages are chosen to prevent current Delta Chat users
|
||||||
|
# from seeing "quota warnings" which trigger at 80% and 95%.
|
||||||
|
|
||||||
|
quota_warning = storage=75%% quota-warning {{ config.max_mailbox_size_mb * 70 // 100 }} {{ config.mailboxes_dir }}/%u
|
||||||
|
}
|
||||||
|
|
||||||
|
service quota-warning {
|
||||||
|
executable = script /usr/local/lib/chatmaild/venv/bin/chatmail-quota-expire
|
||||||
|
user = vmail
|
||||||
|
unix_listener quota-warning {
|
||||||
|
user = vmail
|
||||||
|
mode = 0600
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# push_notification configuration
|
# push_notification configuration
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
from pyinfra import facts, host
|
from pyinfra import facts, host
|
||||||
from pyinfra.operations import files, systemd
|
from pyinfra.operations import files, systemd
|
||||||
|
|
||||||
@@ -5,7 +7,7 @@ from cmdeploy.basedeploy import Deployer, get_resource
|
|||||||
|
|
||||||
|
|
||||||
class FiltermailDeployer(Deployer):
|
class FiltermailDeployer(Deployer):
|
||||||
services = ["filtermail", "filtermail-incoming"]
|
services = ["filtermail", "filtermail-incoming", "filtermail-transport"]
|
||||||
bin_path = "/usr/local/bin/filtermail"
|
bin_path = "/usr/local/bin/filtermail"
|
||||||
config_path = "/usr/local/lib/chatmaild/chatmail.ini"
|
config_path = "/usr/local/lib/chatmaild/chatmail.ini"
|
||||||
|
|
||||||
@@ -13,11 +15,21 @@ class FiltermailDeployer(Deployer):
|
|||||||
self.need_restart = False
|
self.need_restart = False
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
|
local_bin = os.environ.get("CHATMAIL_FILTERMAIL_BINARY")
|
||||||
|
if local_bin:
|
||||||
|
self.need_restart |= files.put(
|
||||||
|
name="Upload locally built filtermail",
|
||||||
|
src=local_bin,
|
||||||
|
dest=self.bin_path,
|
||||||
|
mode="755",
|
||||||
|
).changed
|
||||||
|
return
|
||||||
|
|
||||||
arch = host.get_fact(facts.server.Arch)
|
arch = host.get_fact(facts.server.Arch)
|
||||||
url = f"https://github.com/chatmail/filtermail/releases/download/v0.6.1/filtermail-{arch}"
|
url = f"https://github.com/chatmail/filtermail/releases/download/v0.6.4/filtermail-{arch}"
|
||||||
sha256sum = {
|
sha256sum = {
|
||||||
"x86_64": "48b3fb80c092d00b9b0a0ef77a8673496da3b9aed5ec1851e1df936d5589d62f",
|
"x86_64": "5295115952c72e4c4ec3c85546e094b4155a4c702c82bd71fcdcb744dc73adf6",
|
||||||
"aarch64": "c65bd5f45df187d3d65d6965a285583a3be0f44a6916ff12909ff9a8d702c22e",
|
"aarch64": "6892244f17b8f26ccb465766e96028e7222b3c8adefca9fc6bfe9ff332ca8dff",
|
||||||
}[arch]
|
}[arch]
|
||||||
self.need_restart |= files.download(
|
self.need_restart |= files.download(
|
||||||
name="Download filtermail",
|
name="Download filtermail",
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Chatmail transport service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart={{ bin_path }} {{ config_path }} transport
|
||||||
|
Restart=always
|
||||||
|
RestartSec=30
|
||||||
|
User=vmail
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -78,3 +78,11 @@ counter rejected_unencrypted_mail_count
|
|||||||
/Rejected unencrypted mail/ {
|
/Rejected unencrypted mail/ {
|
||||||
rejected_unencrypted_mail_count++
|
rejected_unencrypted_mail_count++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
counter quota_expire_runs
|
||||||
|
counter quota_expire_removed_files
|
||||||
|
|
||||||
|
/quota-expire: removed (?P<count>\d+) message\(s\)/ {
|
||||||
|
quota_expire_runs++
|
||||||
|
quota_expire_removed_files += $count
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=mtail
|
Description=mtail
|
||||||
|
After=multi-user.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ http {
|
|||||||
|
|
||||||
access_log syslog:server=unix:/dev/log,facility=local7;
|
access_log syslog:server=unix:/dev/log,facility=local7;
|
||||||
|
|
||||||
location /mxdeliv/ {
|
location /mxdeliv {
|
||||||
proxy_pass http://127.0.0.1:{{ config.filtermail_http_port_incoming }};
|
proxy_pass http://127.0.0.1:{{ config.filtermail_http_port_incoming }};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,15 +69,6 @@ mynetworks = 127.0.0.0/8
|
|||||||
{% else %}
|
{% else %}
|
||||||
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
|
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if config.addr_v4 %}
|
|
||||||
smtp_bind_address = {{ config.addr_v4 }}
|
|
||||||
{% endif %}
|
|
||||||
{% if config.addr_v6 %}
|
|
||||||
smtp_bind_address6 = {{ config.addr_v6 }}
|
|
||||||
{% endif %}
|
|
||||||
{% if config.addr_v4 or config.addr_v6 %}
|
|
||||||
smtp_bind_address_enforce = yes
|
|
||||||
{% endif %}
|
|
||||||
mailbox_size_limit = 0
|
mailbox_size_limit = 0
|
||||||
message_size_limit = {{config.max_message_size}}
|
message_size_limit = {{config.max_message_size}}
|
||||||
recipient_delimiter = +
|
recipient_delimiter = +
|
||||||
@@ -88,22 +79,6 @@ inet_protocols = ipv4
|
|||||||
inet_protocols = all
|
inet_protocols = all
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
# Postfix does not try IPv4 and IPv6 connections
|
|
||||||
# concurrently as of version 3.7.11.
|
|
||||||
#
|
|
||||||
# When relay has both A (IPv4) and AAAA (IPv6) records,
|
|
||||||
# but broken IPv6 connectivity,
|
|
||||||
# every second message is delayed by the connection timeout
|
|
||||||
# <https://www.postfix.org/postconf.5.html#smtp_connect_timeout>
|
|
||||||
# which defaults to 30 seconds. Reducing timeouts is not a solution
|
|
||||||
# as this will result in a failure to connect to slow servers.
|
|
||||||
#
|
|
||||||
# As a workaround we always prefer IPv4 when it is available.
|
|
||||||
#
|
|
||||||
# The setting is documented at
|
|
||||||
# <https://www.postfix.org/postconf.5.html#smtp_address_preference>
|
|
||||||
smtp_address_preference=ipv4
|
|
||||||
|
|
||||||
virtual_transport = lmtp:unix:private/dovecot-lmtp
|
virtual_transport = lmtp:unix:private/dovecot-lmtp
|
||||||
virtual_mailbox_domains = {{ config.mail_domain }}
|
virtual_mailbox_domains = {{ config.mail_domain }}
|
||||||
lmtp_header_checks = regexp:/etc/postfix/lmtp_header_cleanup
|
lmtp_header_checks = regexp:/etc/postfix/lmtp_header_cleanup
|
||||||
@@ -118,3 +93,10 @@ smtpd_sender_login_maps = regexp:/etc/postfix/login_map
|
|||||||
# Do not lookup SMTP client hostnames to reduce delays
|
# Do not lookup SMTP client hostnames to reduce delays
|
||||||
# and avoid unnecessary DNS requests.
|
# and avoid unnecessary DNS requests.
|
||||||
smtpd_peername_lookup = no
|
smtpd_peername_lookup = no
|
||||||
|
|
||||||
|
# Use filtermail-transport to relay messages.
|
||||||
|
# We can't force postfix to split messages per destination,
|
||||||
|
# when specifying a custom next-hop,
|
||||||
|
# so instead this is handled in filtermail.
|
||||||
|
# We use LMTP instead SMTP so we can communicate per-recipient errors back to postfix.
|
||||||
|
default_transport = lmtp-filtermail:inet:[127.0.0.1]:{{ config.filtermail_lmtp_port_transport }}
|
||||||
|
|||||||
@@ -100,3 +100,8 @@ filter unix - n n - - lmtp
|
|||||||
# cannot send unprotected Subject.
|
# cannot send unprotected Subject.
|
||||||
authclean unix n - - - 0 cleanup
|
authclean unix n - - - 0 cleanup
|
||||||
-o header_checks=regexp:/etc/postfix/submission_header_cleanup
|
-o header_checks=regexp:/etc/postfix/submission_header_cleanup
|
||||||
|
|
||||||
|
lmtp-filtermail unix - - y - - lmtp
|
||||||
|
-o syslog_name=postfix/lmtp-filtermail
|
||||||
|
-o lmtp_header_checks=
|
||||||
|
-o lmtp_tls_security_level=none
|
||||||
|
|||||||
@@ -221,7 +221,6 @@ def test_rewrite_subject(cmsetup, maildata):
|
|||||||
assert "Subject: Unencrypted subject" not in rcvd_msg
|
assert "Subject: Unencrypted subject" not in rcvd_msg
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.slow
|
|
||||||
def test_exceed_rate_limit(cmsetup, gencreds, maildata, chatmail_config):
|
def test_exceed_rate_limit(cmsetup, gencreds, maildata, chatmail_config):
|
||||||
"""Test that the per-account send-mail limit is exceeded."""
|
"""Test that the per-account send-mail limit is exceeded."""
|
||||||
user1, user2 = cmsetup.gen_users(2)
|
user1, user2 = cmsetup.gen_users(2)
|
||||||
@@ -244,7 +243,6 @@ def test_exceed_rate_limit(cmsetup, gencreds, maildata, chatmail_config):
|
|||||||
pytest.fail("Rate limit was not exceeded")
|
pytest.fail("Rate limit was not exceeded")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.slow
|
|
||||||
def test_expunged(remote, chatmail_config):
|
def test_expunged(remote, chatmail_config):
|
||||||
outdated_days = int(chatmail_config.delete_mails_after) + 1
|
outdated_days = int(chatmail_config.delete_mails_after) + 1
|
||||||
find_cmds = [
|
find_cmds = [
|
||||||
|
|||||||
@@ -23,12 +23,6 @@ def _is_ip(domain):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
|
||||||
parser.addoption(
|
|
||||||
"--slow", action="store_true", default=False, help="also run slow tests"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
config._benchresults = {}
|
config._benchresults = {}
|
||||||
config.addinivalue_line(
|
config.addinivalue_line(
|
||||||
@@ -36,13 +30,6 @@ def pytest_configure(config):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def pytest_runtest_setup(item):
|
|
||||||
markers = list(item.iter_markers(name="slow"))
|
|
||||||
if markers:
|
|
||||||
if not item.config.getoption("--slow"):
|
|
||||||
pytest.skip("skipping slow test, use --slow to run")
|
|
||||||
|
|
||||||
|
|
||||||
def _get_chatmail_config():
|
def _get_chatmail_config():
|
||||||
inipath = os.environ.get("CHATMAIL_INI")
|
inipath = os.environ.get("CHATMAIL_INI")
|
||||||
if inipath:
|
if inipath:
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import importlib.resources
|
from pathlib import Path
|
||||||
|
|
||||||
from cmdeploy.www import build_webpages
|
from cmdeploy.www import build_webpages
|
||||||
|
|
||||||
|
|
||||||
def test_build_webpages(tmp_path, make_config):
|
def test_build_webpages(tmp_path, make_config):
|
||||||
pkgroot = importlib.resources.files("cmdeploy")
|
src_dir = (Path(__file__).resolve() / "../../../../../www/src").resolve()
|
||||||
src_dir = pkgroot.joinpath("../../../www/src").resolve()
|
|
||||||
assert src_dir.exists(), src_dir
|
assert src_dir.exists(), src_dir
|
||||||
config = make_config("chat.example.org")
|
config = make_config("chat.example.org")
|
||||||
build_dir = tmp_path.joinpath("build")
|
build_dir = tmp_path.joinpath("build")
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import importlib.resources
|
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
@@ -37,7 +36,7 @@ def prepare_template(source):
|
|||||||
|
|
||||||
|
|
||||||
def get_paths(config) -> (Path, Path, Path):
|
def get_paths(config) -> (Path, Path, Path):
|
||||||
reporoot = importlib.resources.files(__package__).joinpath("../../../").resolve()
|
reporoot = (Path(__file__).resolve() / "../../../../").resolve()
|
||||||
www_path = Path(config.www_folder)
|
www_path = Path(config.www_folder)
|
||||||
# if www_folder was not set, use default directory
|
# if www_folder was not set, use default directory
|
||||||
if config.www_folder == "":
|
if config.www_folder == "":
|
||||||
@@ -133,8 +132,7 @@ def find_merge_conflict(src_dir) -> Path:
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
path = importlib.resources.files(__package__)
|
reporoot = (Path(__file__).resolve() / "../../../../").resolve()
|
||||||
reporoot = path.joinpath("../../../").resolve()
|
|
||||||
inipath = reporoot.joinpath("chatmail.ini")
|
inipath = reporoot.joinpath("chatmail.ini")
|
||||||
config = read_config(inipath)
|
config = read_config(inipath)
|
||||||
config.webdev = True
|
config.webdev = True
|
||||||
|
|||||||
@@ -4,12 +4,14 @@
|
|||||||
|
|
||||||
You can use the `make` command and `make html` to build web pages.
|
You can use the `make` command and `make html` to build web pages.
|
||||||
|
|
||||||
You need a Python environment where the following install was excuted:
|
You need a Python environment with `sphinx` and other
|
||||||
|
dependencies, you can create it by running `scripts/initenv.sh`
|
||||||
pip install furo sphinx-autobuild
|
from the repository root.
|
||||||
|
|
||||||
To develop/change documentation, you can then do:
|
To develop/change documentation, you can then do:
|
||||||
|
|
||||||
|
. venv/bin/activate
|
||||||
|
cd doc
|
||||||
make auto
|
make auto
|
||||||
|
|
||||||
A page will open at https://127.0.0.1:8000/ serving the docs and it will
|
A page will open at https://127.0.0.1:8000/ serving the docs and it will
|
||||||
|
|||||||
@@ -16,5 +16,6 @@ Contributions and feedback welcome through the https://github.com/chatmail/relay
|
|||||||
proxy
|
proxy
|
||||||
migrate
|
migrate
|
||||||
overview
|
overview
|
||||||
|
reverse_dns
|
||||||
related
|
related
|
||||||
faq
|
faq
|
||||||
|
|||||||
@@ -102,8 +102,12 @@ short overview of ``chatmaild`` services:
|
|||||||
Apple/Google/Huawei.
|
Apple/Google/Huawei.
|
||||||
|
|
||||||
- `chatmail-expire <https://github.com/chatmail/relay/blob/main/chatmaild/src/chatmaild/expire.py>`_
|
- `chatmail-expire <https://github.com/chatmail/relay/blob/main/chatmaild/src/chatmaild/expire.py>`_
|
||||||
deletes users if they have not logged in for a longer while.
|
deletes old messages, large messages, and entire mailboxes
|
||||||
The timeframe can be configured in ``chatmail.ini``.
|
of users who have not logged in for longer than
|
||||||
|
``delete_inactive_users_after`` days.
|
||||||
|
|
||||||
|
- ``chatmail-quota-expire`` is called by Dovecot's ``quota_warning`` mechanism
|
||||||
|
and will automatically remove oldest messages to keep mailboxes well under ``max_mailbox_size``.
|
||||||
|
|
||||||
- `lastlogin <https://github.com/chatmail/relay/blob/main/chatmaild/src/chatmaild/lastlogin.py>`_
|
- `lastlogin <https://github.com/chatmail/relay/blob/main/chatmaild/src/chatmaild/lastlogin.py>`_
|
||||||
is contacted by Dovecot when a user logs in and stores the date of
|
is contacted by Dovecot when a user logs in and stores the date of
|
||||||
@@ -149,6 +153,7 @@ Chatmail relay dependency diagram
|
|||||||
autoconfig.xml --- dovecot;
|
autoconfig.xml --- dovecot;
|
||||||
postfix --- |10080|filtermail-outgoing;
|
postfix --- |10080|filtermail-outgoing;
|
||||||
postfix --- |10081|filtermail-incoming;
|
postfix --- |10081|filtermail-incoming;
|
||||||
|
postfix --- |10083|filtermail-transport;
|
||||||
filtermail-outgoing --- |10025 reinject|postfix;
|
filtermail-outgoing --- |10025 reinject|postfix;
|
||||||
filtermail-incoming --- |10026 reinject|postfix;
|
filtermail-incoming --- |10026 reinject|postfix;
|
||||||
dovecot --- |doveauth.socket|doveauth;
|
dovecot --- |doveauth.socket|doveauth;
|
||||||
@@ -156,6 +161,8 @@ Chatmail relay dependency diagram
|
|||||||
/home/vmail/.../user"];
|
/home/vmail/.../user"];
|
||||||
dovecot --- |lastlogin.socket|lastlogin;
|
dovecot --- |lastlogin.socket|lastlogin;
|
||||||
dovecot --- chatmail-metadata;
|
dovecot --- chatmail-metadata;
|
||||||
|
dovecot --- |quota-warning|chatmail-quota-expire;
|
||||||
|
chatmail-quota-expire --- maildir;
|
||||||
lastlogin --- maildir;
|
lastlogin --- maildir;
|
||||||
doveauth --- maildir;
|
doveauth --- maildir;
|
||||||
chatmail-expire-daily --- maildir;
|
chatmail-expire-daily --- maildir;
|
||||||
@@ -289,9 +296,7 @@ ensured by ``filtermail`` proxy.
|
|||||||
TLS requirements
|
TLS requirements
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Postfix is configured to require valid TLS by setting
|
Filtermail (used for delivery) requires a valid TLS.
|
||||||
`smtp_tls_security_level <https://www.postfix.org/postconf.5.html#smtp_tls_security_level>`_
|
|
||||||
to ``verify``.
|
|
||||||
|
|
||||||
You can test it by resolving ``MX`` records of your relay domain and
|
You can test it by resolving ``MX`` records of your relay domain and
|
||||||
then connecting to MX relays (e.g ``mx.example.org``) with
|
then connecting to MX relays (e.g ``mx.example.org``) with
|
||||||
|
|||||||
64
doc/source/reverse_dns.rst
Normal file
64
doc/source/reverse_dns.rst
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
Configuring reverse DNS
|
||||||
|
=======================
|
||||||
|
|
||||||
|
Some email servers reject the emails
|
||||||
|
if they don't pass `FCrDNS`_ check, also known as `iprev`_ check.
|
||||||
|
|
||||||
|
.. _FCrDNS: https://en.wikipedia.org/wiki/Forward-confirmed_reverse_DNS
|
||||||
|
.. _iprev: https://datatracker.ietf.org/doc/html/rfc8601#section-3
|
||||||
|
|
||||||
|
Passing the check requires that the IP address that email is sent from
|
||||||
|
should have a ``PTR`` record pointing to the domain name of the server,
|
||||||
|
and domain name record should have an ``A/AAAA`` record
|
||||||
|
pointing to the IP address.
|
||||||
|
|
||||||
|
Modern email relies on DKIM and SPF for authentication,
|
||||||
|
while iprev check exists for
|
||||||
|
`historical reasons <https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-reverse-mapping-considerations-06#section-2.1>`_.
|
||||||
|
Chatmail relays don't resolve ``PTR`` records,
|
||||||
|
so you can ignore this section if configuring ``PTR`` records
|
||||||
|
is difficult and federation with legacy email servers that don't accept
|
||||||
|
valid DKIM signature for authentication is not important.
|
||||||
|
|
||||||
|
Multi-homed setups
|
||||||
|
------------------
|
||||||
|
|
||||||
|
If you have a server with multiple IP addresses,
|
||||||
|
also known as multi-homed setup,
|
||||||
|
and don't publish all IP addresses in DNS,
|
||||||
|
you need to make sure you are using
|
||||||
|
the published address when making outgoing connections.
|
||||||
|
|
||||||
|
For example, your server may have a static IP
|
||||||
|
address, and a so-called Floating IP or Virtual IP
|
||||||
|
that can be moved between servers in case of
|
||||||
|
migration or for failover.
|
||||||
|
By using Floating IP you can avoid downtime
|
||||||
|
and keep the IP address reputation
|
||||||
|
for destinatinons that rely on IP reputation and IP blocklists.
|
||||||
|
In this case you will only publish
|
||||||
|
the Floating IP to DNS and only use the static IP
|
||||||
|
to SSH into the server.
|
||||||
|
|
||||||
|
If you have such setup, make sure that
|
||||||
|
you not only set ``PTR`` records for the Floating IP,
|
||||||
|
but make outgoing connections using the Floating IP.
|
||||||
|
Otherwise reverse DNS check succeed,
|
||||||
|
but forward check making sure your domain name points
|
||||||
|
to the IP address will fail.
|
||||||
|
Such setup is indistinguishable from someone
|
||||||
|
setting IP address ``PTR`` with the domain they don't own
|
||||||
|
and as a result don't succeed.
|
||||||
|
|
||||||
|
On Linux you can configure source IP address with ``ip route`` command,
|
||||||
|
for example:
|
||||||
|
::
|
||||||
|
|
||||||
|
ip route change default via <default-gateway> dev eth0 src <source-address>
|
||||||
|
|
||||||
|
Make sure to persist the change after verifying it is working.
|
||||||
|
You can check what your outgoing IP address is
|
||||||
|
with ``curl icanhazip.com``.
|
||||||
|
Check both the IPv4 and IPv6 addresses.
|
||||||
|
For IPv4 address use ``curl ipv4.icanhazip.com`` or ``curl -4 icanhazip.com``
|
||||||
|
and similarly for IPv6 if you have it.
|
||||||
Reference in New Issue
Block a user