Fallschlüssel auch bei Message-ID mit Sonderzeichen bilden
This commit is contained in:
3 files changed
+23
-7
No files matched your search
@@ -11,7 +11,7 @@ STATES = ("new", "running", "unsubscribed", "not_possible", "unclear")
|
|||||||
|
|
||||||
def case_key(message) -> str:
|
def case_key(message) -> str:
|
||||||
"""Message-ID of the mail in the collection mailbox; the UID changes when the mail is moved."""
|
"""Message-ID of the mail in the collection mailbox; the UID changes when the mail is moved."""
|
||||||
mid = (message.get("Message-ID") or "").strip()
|
mid = str(message.get("Message-ID") or "").strip()
|
||||||
if mid:
|
if mid:
|
||||||
return mid
|
return mid
|
||||||
raw = "|".join(str(message.get(h, "")) for h in ("Date", "Subject", "From"))
|
raw = "|".join(str(message.get(h, "")) for h in ("Date", "Subject", "From"))
|
||||||
|
|||||||
@@ -111,3 +111,12 @@ def test_meta_roundtrip(store):
|
|||||||
assert store.meta("paused", "0") == "0"
|
assert store.meta("paused", "0") == "0"
|
||||||
store.set_meta("paused", "1")
|
store.set_meta("paused", "1")
|
||||||
assert store.meta("paused") == "1"
|
assert store.meta("paused") == "1"
|
||||||
|
|
||||||
|
|
||||||
|
def test_key_copes_with_a_non_ascii_message_id():
|
||||||
|
import email
|
||||||
|
raw = "Message-ID: <näh@x>\r\nSubject: s\r\n\r\nbody".encode("utf-8")
|
||||||
|
message = email.message_from_bytes(raw)
|
||||||
|
key = case_key(message)
|
||||||
|
assert isinstance(key, str) and key
|
||||||
|
assert case_key(message) == key
|
||||||
+13
-6
@@ -307,14 +307,21 @@ def test_malformed_agent_result_ends_the_case_unclear(store, result):
|
|||||||
assert summary["handled"] == 1 and summary["error"] == ""
|
assert summary["handled"] == 1 and summary["error"] == ""
|
||||||
|
|
||||||
|
|
||||||
def test_mail_with_non_ascii_message_id_does_not_stop_the_run(store):
|
def test_exception_while_handling_one_mail_does_not_stop_the_run(store):
|
||||||
raw = ("Message-ID: <näh@x>\nSubject: Fwd: x\nFrom: jens@wagnersnetz.de\n\n"
|
raw = ("Message-ID: <broken@x>\nSubject: broken\nFrom: jens@wagnersnetz.de\n\n"
|
||||||
"Von: news@shop.example\nAn: philipp@wagnersnetz.de\n\nhttps://shop.example/unsubscribe/9\n").encode("utf-8")
|
"Von: news@shop.example\nAn: philipp@wagnersnetz.de\n\nhttps://shop.example/unsubscribe/9\n").encode("utf-8")
|
||||||
import email
|
|
||||||
with pytest.raises(Exception):
|
def parse_failing_on_one(message):
|
||||||
case_key(email.message_from_bytes(raw)) # proves the mail really is a poison pill
|
result = parse(message)
|
||||||
|
if result[0] == "broken":
|
||||||
|
raise ValueError("cannot handle this mail")
|
||||||
|
return result
|
||||||
|
|
||||||
imap = FakeIMAP({b"1": raw, b"2": mail_bytes("<b@x>")})
|
imap = FakeIMAP({b"1": raw, b"2": mail_bytes("<b@x>")})
|
||||||
summary = worker(store, imap, Agent(OK, OK)).run_once()
|
w = Worker(store, lambda: imap, parse_failing_on_one, Agent(OK), allowed_domains=("wagnersnetz.de",),
|
||||||
|
allowed_senders=("jens@wagnersnetz.de",))
|
||||||
|
summary = w.run_once()
|
||||||
|
assert store.get("<broken@x>") is None
|
||||||
assert store.get("<b@x>")["state"] == "unsubscribed" and summary["error"] == ""
|
assert store.get("<b@x>")["state"] == "unsubscribed" and summary["error"] == ""
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user