From 7d014f2c405f05d9ca3471b794e90940d7b852c6 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 11 Apr 2023 14:08:06 +0200 Subject: pkg/email: parse multiple In-Reply-To message IDs Even though the standard seems to prohibit it, there are real world cases of messages with multiple IDs in an "In-Reply-To" header. --- pkg/email/parser.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'pkg/email/parser.go') diff --git a/pkg/email/parser.go b/pkg/email/parser.go index 795cc6fed..77b063055 100644 --- a/pkg/email/parser.go +++ b/pkg/email/parser.go @@ -169,7 +169,7 @@ func Parse(r io.Reader, ownEmails, goodLists, domains []string) (*Email, error) email := &Email{ BugIDs: dedupBugIDs(bugIDs), MessageID: msg.Header.Get("Message-ID"), - InReplyTo: msg.Header.Get("In-Reply-To"), + InReplyTo: extractInReplyTo(msg.Header), Date: date, Link: link, Author: author, @@ -417,6 +417,20 @@ func parseBody(r io.Reader, headers mail.Header) ([]byte, [][]byte, error) { } } +var extractMessageIDs = regexp.MustCompile(`<.+?>`) + +func extractInReplyTo(header mail.Header) string { + value := header.Get("In-Reply-To") + // Normally there should be just one message, to which we reply. + // However, there have been some cases when multiple addresses were mentioned. + // For now let's just take the first one. + ret := extractMessageIDs.FindStringSubmatch(value) + if ret != nil { + return ret[0] + } + return "" +} + func extractBodyBugIDs(body string, ownEmailMap map[string]bool, domains []string) []string { // Let's build a regular expression. var rb strings.Builder -- cgit mrf-deployment