filtermail: always allow privacy@testrun.org

This commit is contained in:
missytake 2023-12-07 15:16:40 +01:00 committed by holger krekel
parent 8cb77d3b98
commit 2055e9f5b8
2 changed files with 37 additions and 1 deletions

View File

@ -34,6 +34,14 @@ def check_encrypted(message):
return True
def check_passthrough(recipient):
"""Check whether a recipient is configured as passthrough."""
passthroughlist = ["privacy@testrun.org"]
if recipient in passthroughlist:
return True
return False
def check_mdn(message, envelope):
if len(envelope.rcpt_tos) != 1:
return False
@ -118,6 +126,9 @@ def check_DATA(envelope):
if envelope.mail_from == recipient:
# Always allow sending emails to self.
continue
if check_passthrough(recipient):
# Always allow recipients marked as passthrough in chatmail.ini
continue
res = recipient.split("@")
if len(res) != 2:
return f"500 Invalid address <{recipient}>"

View File

@ -1,4 +1,4 @@
from chatmaild.filtermail import check_encrypted, check_DATA, SendRateLimiter, check_mdn
from chatmaild.filtermail import check_encrypted, check_DATA, SendRateLimiter, check_mdn, check_passthrough
import pytest
@ -80,3 +80,28 @@ def test_send_rate_limiter():
else:
assert i == SendRateLimiter.MAX_USER_SEND_PER_MINUTE + 1
break
def test_excempt_privacy(maildata, gencreds):
from_addr = gencreds()[0]
to_addr = "privacy@testrun.org"
false_to = "privacy@tstrn.org"
false_to2 = "prvcy@testrun.org"
assert check_passthrough(to_addr)
msg = maildata("plain.eml", from_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 check_DATA(envelope=env)
class env2:
mail_from = from_addr
rcpt_tos = [to_addr, false_to, false_to2]
content = msg.as_bytes()
assert "500" in check_DATA(envelope=env2)