Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for specifying whole domains for passthrough recipients #408

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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)
hpk42 marked this conversation as resolved.
Show resolved Hide resolved
passthrough_recipients = [email protected]

#
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 = "[email protected]"
handler.config.passthrough_recipients = ["@x.y.z"]
false_to = "[email protected]"

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 = "[email protected]"
Expand Down