Antispam: mirror the engine in dev, and never file a contact as spam
Dev compose gains rspamd + redis-rspamd, matching production. The dev API and worker run on the host rather than in the compose network, so the ports are published on loopback and RSPAMD_URL points at 127.0.0.1 — documented in .env.example. Contacts now cap a verdict at "banner": mail from someone in the user's address book is never moved to Junk. Capped rather than exempted, because the way this fails in practice is a contact's account being compromised and spamming its own address book — the warning still has value even when the move would be wrong. An explicit deny rule still wins; that is the user overruling us deliberately. The lookup reads the contacts plugin's table directly and forgives its absence: no contacts plugin means no contacts to check, not an error. Addresses are stored as the user typed them, so both sides are lower-cased rather than relying on the jsonb containment index, and secondary addresses in the emails array count as well as the primary. It runs only when the verdict would otherwise be a move, so the common path pays nothing. Also fixes a test that asserted stats degrade "without an engine" by relying on no engine being present — true until this commit. It now simulates the absence. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018SqJYt7jD7oUEkoY68sBZo
This commit is contained in:
@@ -92,3 +92,44 @@ def test_per_account_enablement() -> None:
|
||||
)
|
||||
assert scoped.covers("acc-1")
|
||||
assert not scoped.covers("acc-2")
|
||||
|
||||
|
||||
# --- contacts are never filed as spam ----------------------------------------
|
||||
|
||||
|
||||
def test_a_contact_is_warned_about_but_never_moved() -> None:
|
||||
"""Mail from someone in the address book must not vanish into Junk."""
|
||||
assert _decide(score=99.0) == "moved" # same score, not a contact
|
||||
assert (
|
||||
decide(
|
||||
sender="friend@example.com",
|
||||
rules=NO_RULES,
|
||||
score=99.0,
|
||||
settings=SETTINGS,
|
||||
contact=True,
|
||||
)
|
||||
== "banner"
|
||||
)
|
||||
|
||||
|
||||
def test_a_contact_below_the_move_threshold_is_unaffected() -> None:
|
||||
for score, expected in ((0.0, "none"), (6.0, "banner"), (11.9, "banner")):
|
||||
assert (
|
||||
decide(
|
||||
sender="friend@example.com",
|
||||
rules=NO_RULES,
|
||||
score=score,
|
||||
settings=SETTINGS,
|
||||
contact=True,
|
||||
)
|
||||
== expected
|
||||
)
|
||||
|
||||
|
||||
def test_an_explicit_deny_still_beats_being_a_contact() -> None:
|
||||
"""Deny-listing someone you also have saved is a deliberate act — honour it."""
|
||||
rules = {"allow": set(), "deny": {"ex@example.com"}}
|
||||
assert (
|
||||
decide(sender="ex@example.com", rules=rules, score=0.0, settings=SETTINGS, contact=True)
|
||||
== "deny_listed"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user