Skip to content

Commit

Permalink
add support for specifying whole domains for passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
hpk42 committed Oct 30, 2024
1 parent 8ea96e5 commit 72df078
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
11 changes: 10 additions & 1 deletion chatmaild/src/chatmaild/filtermail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion chatmaild/src/chatmaild/ini/chatmail.ini.f
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down
24 changes: 24 additions & 0 deletions chatmaild/src/chatmaild/tests/test_filtermail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 72df078

Please sign in to comment.