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 @@ def check_DATA(self, envelope): 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 @@ 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 @@ class env2: 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"