diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-04-11 14:08:06 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2023-04-12 13:55:59 +0200 |
| commit | 7d014f2c405f05d9ca3471b794e90940d7b852c6 (patch) | |
| tree | ef07f7a821d3bd3f80a01799cf8ca8f2075f5024 /pkg/email/parser.go | |
| parent | 7e83566529c0c9fd1882625e157ad53383fe3168 (diff) | |
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.
Diffstat (limited to 'pkg/email/parser.go')
| -rw-r--r-- | pkg/email/parser.go | 16 |
1 files changed, 15 insertions, 1 deletions
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 |
