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>
This commit is contained in:
parent
374d3a0d01
commit
1b6ce56164
1 changed files with 17 additions and 5 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue