threading: fix stack overflow from faulty headers

Fix stack overflow from faulty headers that cause a circularity in the
threading algorithm. Remove duplicated message-ids in the references
headers. Check that the message-id itself is not part of the references.

Fixes: https://todo.sr.ht/~rjarry/aerc/32
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Robin Jarry <robin@jarry.cc>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-03-22 00:50:02 +01:00 committed by Robin Jarry
parent 4c699d35f8
commit 93c160ab66
1 changed files with 13 additions and 1 deletions

View File

@ -200,7 +200,19 @@ func (t *threadable) MessageThreadReferences() []string {
}
refs = []string{inreplyto}
}
return refs
return cleanRefs(t.MessageThreadID(), refs)
}
func cleanRefs(m string, refs []string) []string {
considered := make(map[string]interface{})
cleanRefs := make([]string, 0, len(refs))
for _, r := range refs {
if _, seen := considered[r]; r != m && !seen {
considered[r] = nil
cleanRefs = append(cleanRefs, r)
}
}
return cleanRefs
}
func (t *threadable) Subject() string {