diff --git a/chatmaild/src/chatmaild/filtermail.py b/chatmaild/src/chatmaild/filtermail.py index b493bab8..bd5984cd 100644 --- a/chatmaild/src/chatmaild/filtermail.py +++ b/chatmaild/src/chatmaild/filtermail.py @@ -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}>" diff --git a/tests/chatmaild/test_filtermail.py b/tests/chatmaild/test_filtermail.py index df71fd8a..1ffbc965 100644 --- a/tests/chatmaild/test_filtermail.py +++ b/tests/chatmaild/test_filtermail.py @@ -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)