Skip to content

Commit e993187

Browse files
committed
fix: avoid sourceId collision for messages without Message-ID (CM-1318)
Signed-off-by: Uroš Marolt <uros@marolt.me>
1 parent 435772b commit e993187

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

services/apps/mailing_list_integration/src/crowdmail/services/parse/noteren.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ def parse_email(
268268
git_id[:12],
269269
)
270270

271-
# Grab the message id for this message
272-
msgid = message_id_cleanup(e.get("Message-ID", None))
271+
# Grab the message id for this message. Fall back to a synthetic id built
272+
# from the (unique) git commit sha when Message-ID is absent, so the
273+
# sourceId-based dedup key can't collide across such messages.
274+
msgid = message_id_cleanup(e.get("Message-ID", None)) or f"{channel}:{git_id}"
273275

274276
# Grab only the "last" reference in the list of references for this email.
275277
# "References:" is a long list, trying to show everything else in the

services/apps/mailing_list_integration/src/test/test_noteren.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,11 @@ def test_run_command_returns_nonzero_exit_code():
736736
assert rc == 42
737737

738738

739-
def test_parse_email_no_message_id_gives_empty_source_id():
740-
"""A message without a Message-ID header must yield sourceId == ''."""
739+
def test_parse_email_no_message_id_gives_synthetic_source_id():
740+
"""A message without a Message-ID header must fall back to a channel:git_id sourceId."""
741741
raw = b"From: A <a@example.com>\nSubject: s\nDate: Mon, 1 Jan 2024 12:00:00 +0000\n\nbody\n"
742742
parsed = _parse_email(raw, "src", "chan", "c1", "b1")
743-
assert parsed["activityData"]["sourceId"] == ""
743+
assert parsed["activityData"]["sourceId"] == "chan:c1"
744744

745745

746746
def test_parse_email_no_subject_gives_none_title():
@@ -856,10 +856,10 @@ def test_parse_email_url_contains_message_id():
856856

857857

858858
def test_parse_email_url_with_no_message_id():
859-
"""When Message-ID is absent the url must end with a slash under the source's /r/ path."""
859+
"""When Message-ID is absent the url must embed the synthetic channel:git_id id."""
860860
raw = b"From: A <a@example.com>\nSubject: s\nDate: Mon, 1 Jan 2024 12:00:00 +0000\n\nbody\n"
861861
parsed = _parse_email(raw, "src", "chan", "c1", "b1")
862-
assert parsed["activityData"]["url"] == "src/r/"
862+
assert parsed["activityData"]["url"] == "src/r/chan:c1"
863863

864864

865865
def test_parse_email_result_structure():

0 commit comments

Comments
 (0)