1.8 KiB
1.8 KiB
Threading: Add References Header Fallback
Problem
Ingress threading only resolves parent via In-Reply-To. When a client sets References without In-Reply-To, the bridge creates a new thread_id instead of attaching to the existing conversation, breaking thread continuity and downstream dispatch.
Requirements
From requirements.md:74:
- If
In-Reply-ToorReferencesis present, find parent task in DB and inheritthread_id. - Otherwise use
message_idas newthread_id.
Design
Current behavior (imap.go:333-369)
- Parse MIME body headers, extract
In-Reply-To - If found, lookup parent by message ID → inherit
thread_id
New behavior
- Parse MIME body headers, extract both
In-Reply-ToandReferences - Try
In-Reply-Tofirst (unchanged) - If no parent found via
In-Reply-To, parseReferencesheader (space-separated<msg-id>list) - Iterate
Referencesfrom last to first (most recent ancestor first) - First match in DB wins → inherit
thread_id
Why last-to-first
References lists message IDs chronologically: <oldest> ... <newest>. The last entry is the most recent message in the chain, most likely already processed by the bridge.
Scope
- Single file change:
internal/mail/imap.go(threading block inprocessMessage, ~10 lines) - New tests:
internal/mail/imap_test.go(References parsing, fallback, multi-ID) - No changes to DB, config, API, or other packages
Test cases
In-Reply-Tomatches → existing behavior unchangedIn-Reply-Toabsent,Referenceshas match → inherits thread_id from most recent matchReferenceshas multiple IDs, only older one in DB → still matches- Both headers absent → thread_id = message_id (unchanged)
Referencespresent but no match in DB → thread_id = message_id (new thread)