diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-03-23 20:25:37 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-03-23 20:56:47 +0100 |
commit | 1b6ce56164179f5449c5dab1876fd03a235e616d (patch) | |
tree | 30f1b2f862f32f0370535db128b4267aaa7775d8 | |
parent | 374d3a0d01a3dbaa246acd9bbd23df743addf477 (diff) | |
download | aerc-1b6ce56164179f5449c5dab1876fd03a235e616d.tar.gz |
threading: fix msg-id order in references header
Fix order in the references header when an in-reply-to msg-id is
erroneously added at the beginning instead of at the end. Add
description to the function that cleans up the reference headers for
threading.
Reported-by: Evan Gates <evan.gates@gmail.com>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r-- | lib/threadbuilder.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/threadbuilder.go b/lib/threadbuilder.go index 9137fc17..334a8468 100644 --- a/lib/threadbuilder.go +++ b/lib/threadbuilder.go @@ -192,18 +192,25 @@ func (t *threadable) MessageThreadReferences() []string { if t.IsDummy() || t.MsgInfo == nil { return nil } + irp, err := t.MsgInfo.InReplyTo() + if err != nil { + irp = "" + } refs, err := t.MsgInfo.References() if err != nil || len(refs) == 0 { - inreplyto, err := t.MsgInfo.InReplyTo() - if err != nil { + if irp == "" { return nil } - refs = []string{inreplyto} + refs = []string{irp} } - return cleanRefs(t.MessageThreadID(), refs) + return cleanRefs(t.MessageThreadID(), irp, refs) } -func cleanRefs(m string, refs []string) []string { +// cleanRefs cleans up the references headers for threading +// 1) message-id should not be part of the references +// 2) no message-id should occur twice (avoid circularities) +// 3) in-reply-to header should not be at the beginning +func cleanRefs(m, irp string, refs []string) []string { considered := make(map[string]interface{}) cleanRefs := make([]string, 0, len(refs)) for _, r := range refs { @@ -212,6 +219,11 @@ func cleanRefs(m string, refs []string) []string { cleanRefs = append(cleanRefs, r) } } + if irp != "" && len(cleanRefs) > 0 { + if cleanRefs[0] == irp { + cleanRefs = append(cleanRefs[1:], irp) + } + } return cleanRefs } |