add support for specifying whole domains for passthrough

This commit is contained in:
holger krekel
2024-09-06 18:36:33 +02:00
parent 8ea96e505e
commit 72df078d02
4 changed files with 38 additions and 2 deletions

View File

@@ -35,6 +35,9 @@
- fix checking for required DNS records - fix checking for required DNS records
([#412](https://github.com/deltachat/chatmail/pull/412)) ([#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 - add a paragraph about "account deletion" to info page
([#405](https://github.com/deltachat/chatmail/pull/405)) ([#405](https://github.com/deltachat/chatmail/pull/405))

View File

@@ -142,6 +142,15 @@ async def asyncmain_beforequeue(config):
Controller(BeforeQueueHandler(config), hostname="127.0.0.1", port=port).start() 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: class BeforeQueueHandler:
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
@@ -205,7 +214,7 @@ class BeforeQueueHandler:
if envelope.mail_from == recipient: if envelope.mail_from == recipient:
# Always allow sending emails to self. # Always allow sending emails to self.
continue continue
if recipient in passthrough_recipients: if recipient_matches_passthrough(recipient, passthrough_recipients):
continue continue
res = recipient.split("@") res = recipient.split("@")
if len(res) != 2: if len(res) != 2:

View File

@@ -39,7 +39,7 @@ password_min_length = 9
passthrough_senders = passthrough_senders =
# list of e-mail recipients for which to accept outbound un-encrypted mails # 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 passthrough_recipients = xstore@testrun.org
# #

View File

@@ -121,6 +121,30 @@ def test_excempt_privacy(maildata, gencreds, handler):
assert "500" in handler.check_DATA(envelope=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): def test_passthrough_senders(gencreds, handler, maildata):
acc1 = gencreds()[0] acc1 = gencreds()[0]
to_addr = "recipient@something.org" to_addr = "recipient@something.org"