From 72df078d0253ee2ef07bd200f9426f5cc3a90d97 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 6 Sep 2024 18:36:33 +0200 Subject: [PATCH] add support for specifying whole domains for passthrough --- CHANGELOG.md | 3 +++ chatmaild/src/chatmaild/filtermail.py | 11 ++++++++- chatmaild/src/chatmaild/ini/chatmail.ini.f | 2 +- .../src/chatmaild/tests/test_filtermail.py | 24 +++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa10953c..98e1b8a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,9 @@ - fix checking for required DNS records ([#412](https://github.com/deltachat/chatmail/pull/412)) +- add support for specifying whole domains for recipient passthrough list + ([#408](https://github.com/deltachat/chatmail/pull/408)) + - add a paragraph about "account deletion" to info page ([#405](https://github.com/deltachat/chatmail/pull/405)) diff --git a/chatmaild/src/chatmaild/filtermail.py b/chatmaild/src/chatmaild/filtermail.py index 6e0dbf53..47ab791a 100644 --- a/chatmaild/src/chatmaild/filtermail.py +++ b/chatmaild/src/chatmaild/filtermail.py @@ -142,6 +142,15 @@ async def asyncmain_beforequeue(config): Controller(BeforeQueueHandler(config), hostname="127.0.0.1", port=port).start() +def recipient_matches_passthrough(recipient, passthrough_recipients): + for addr in passthrough_recipients: + if recipient == addr: + return True + if addr[0] == "@" and recipient.endswith(addr): + return True + return False + + class BeforeQueueHandler: def __init__(self, config): self.config = config @@ -205,7 +214,7 @@ class BeforeQueueHandler: if envelope.mail_from == recipient: # Always allow sending emails to self. continue - if recipient in passthrough_recipients: + if recipient_matches_passthrough(recipient, passthrough_recipients): continue res = recipient.split("@") if len(res) != 2: diff --git a/chatmaild/src/chatmaild/ini/chatmail.ini.f b/chatmaild/src/chatmaild/ini/chatmail.ini.f index bde5bf5b..60fe1dcd 100644 --- a/chatmaild/src/chatmaild/ini/chatmail.ini.f +++ b/chatmaild/src/chatmaild/ini/chatmail.ini.f @@ -39,7 +39,7 @@ password_min_length = 9 passthrough_senders = # list of e-mail recipients for which to accept outbound un-encrypted mails -# (space-separated) +# (space-separated, item may start with "@" to whitelist whole recipient domains) passthrough_recipients = xstore@testrun.org # diff --git a/chatmaild/src/chatmaild/tests/test_filtermail.py b/chatmaild/src/chatmaild/tests/test_filtermail.py index 6072d656..2bd5b2b1 100644 --- a/chatmaild/src/chatmaild/tests/test_filtermail.py +++ b/chatmaild/src/chatmaild/tests/test_filtermail.py @@ -121,6 +121,30 @@ def test_excempt_privacy(maildata, gencreds, handler): assert "500" in handler.check_DATA(envelope=env2) +def test_passthrough_domains(maildata, gencreds, handler): + from_addr = gencreds()[0] + to_addr = "privacy@x.y.z" + handler.config.passthrough_recipients = ["@x.y.z"] + false_to = "something@x.y" + + msg = maildata("plain.eml", from_addr=from_addr, to_addr=to_addr) + + class env: + mail_from = from_addr + rcpt_tos = [to_addr] + content = msg.as_bytes() + + # assert that None/no error is returned + assert not handler.check_DATA(envelope=env) + + class env2: + mail_from = from_addr + rcpt_tos = [to_addr, false_to] + content = msg.as_bytes() + + assert "500" in handler.check_DATA(envelope=env2) + + def test_passthrough_senders(gencreds, handler, maildata): acc1 = gencreds()[0] to_addr = "recipient@something.org"