Phase 6: rules editor + unsubscribe detection (AUD-72)
- FR-11 rules editor: plain-text area at /rules, saved and versioned (SaveRules appends a version; restore re-saves an old version), parse errors surfaced, one-click re-classify. The reply model now reads the rules document too (FR-11). - FR-7 unsubscribe: parse and store List-Unsubscribe / List-Unsubscribe-Post (migration v6), detect email and web links (internal/unsubscribe), a domain-level ignore list, and an explicit record of what was marked. No code path contacts an unsubscribe link; acting on one needs Sam's approval. - Migration v6 is additive; unsubscribe gains url/updated_at. - Tests: detector, parser, store migration/records/candidates, rules editor, unsubscribe handlers, message-detail rendering. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -172,3 +172,34 @@ func TestHeaderAddressParsing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMessageCapturesUnsubscribeHeaders(t *testing.T) {
|
||||
raw := "From: Heritage Fruit Trees <support@heritagefruittrees.com.au>\r\n" +
|
||||
"To: samuelrolfe@gmail.com\r\n" +
|
||||
"X-Pm-Original-To: hello@where-woof.com\r\n" +
|
||||
"Subject: New workshops\r\n" +
|
||||
"List-Unsubscribe: <mailto:unsub@heritagefruittrees.com.au?subject=unsubscribe>, <https://heritagefruittrees.com.au/u?id=1>\r\n" +
|
||||
"List-Unsubscribe-Post: List-Unsubscribe=One-Click\r\n" +
|
||||
"Message-Id: <abc@mail.example>\r\n" +
|
||||
"Date: Mon, 01 Jan 2026 10:00:00 +0000\r\n" +
|
||||
"Content-Type: text/plain; charset=utf-8\r\n" +
|
||||
"\r\n" +
|
||||
"Hello, you can unsubscribe at https://heritagefruittrees.com.au/u?id=1.\r\n"
|
||||
|
||||
pm, err := ParseMessage([]byte(raw))
|
||||
if err != nil {
|
||||
t.Fatalf("ParseMessage() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(pm.ListUnsubscribe, "mailto:unsub@heritagefruittrees.com.au") {
|
||||
t.Errorf("ListUnsubscribe = %q", pm.ListUnsubscribe)
|
||||
}
|
||||
if !strings.Contains(pm.ListUnsubscribe, "https://heritagefruittrees.com.au/u?id=1") {
|
||||
t.Errorf("ListUnsubscribe = %q", pm.ListUnsubscribe)
|
||||
}
|
||||
if pm.ListUnsubscribePost != "List-Unsubscribe=One-Click" {
|
||||
t.Errorf("ListUnsubscribePost = %q", pm.ListUnsubscribePost)
|
||||
}
|
||||
if pm.SourceAddress != "hello@where-woof.com" {
|
||||
t.Errorf("SourceAddress = %q", pm.SourceAddress)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user