From e2c7870cb29ae33156ef5f5e058d350e0d485f04 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 10 Jul 2025 10:37:19 +0200 Subject: pkg/email: share raw email addresses These will be necessary to properly route emails in dashboard. --- pkg/email/lore/parse_test.go | 1 + pkg/email/parser.go | 24 +++++++++++++++++++----- pkg/email/parser_test.go | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) (limited to 'pkg') diff --git a/pkg/email/lore/parse_test.go b/pkg/email/lore/parse_test.go index 3ee9ec392..81d1eaebc 100644 --- a/pkg/email/lore/parse_test.go +++ b/pkg/email/lore/parse_test.go @@ -220,6 +220,7 @@ Bug report`, t.Fatal(err) } msg.Body = "" + msg.RawCc = nil emails = append(emails, msg) } diff --git a/pkg/email/parser.go b/pkg/email/parser.go index 63f758bd2..3ebd7ac08 100644 --- a/pkg/email/parser.go +++ b/pkg/email/parser.go @@ -30,8 +30,9 @@ type Email struct { Author string OwnEmail bool Cc []string - Body string // text/plain part - Patch string // attached patch, if any + RawCc []string // unstripped emails + Body string // text/plain part + Patch string // attached patch, if any Commands []*SingleCommand } @@ -178,7 +179,7 @@ func Parse(r io.Reader, ownEmails, goodLists, domains []string) (*Email, error) } date, _ := mail.ParseDate(msg.Header.Get("Date")) email := &Email{ - BugIDs: dedupBugIDs(bugIDs), + BugIDs: unique(bugIDs), MessageID: msg.Header.Get("Message-ID"), InReplyTo: extractInReplyTo(msg.Header), Date: date, @@ -188,6 +189,7 @@ func Parse(r io.Reader, ownEmails, goodLists, domains []string) (*Email, error) MailingList: mailingList, Subject: subject, Cc: ccList, + RawCc: mergeRawAddresses(from, originalFroms, to, cc), Body: bodyStr, Patch: patch, Commands: cmds, @@ -500,8 +502,8 @@ func extractBodyBugIDs(body string, ownEmailMap map[string]bool, domains []strin return ids } -func dedupBugIDs(list []string) []string { - // We should preserve the original order of IDs. +func unique(list []string) []string { + // We preserve the original order since it's necessary for bug IDs. var ret []string dup := map[string]struct{}{} for _, v := range list { @@ -541,6 +543,18 @@ func MergeEmailLists(lists ...[]string) []string { return result } +func mergeRawAddresses(lists ...[]*mail.Address) []string { + var emails []string + for _, list := range lists { + for _, item := range list { + emails = append(emails, item.Address) + } + } + emails = unique(emails) + sort.Strings(emails) + return emails +} + func RemoveFromEmailList(list []string, toRemove string) []string { var result []string toRemove = CanonicalEmail(toRemove) diff --git a/pkg/email/parser_test.go b/pkg/email/parser_test.go index 4c042bcfc..87f6ec38e 100644 --- a/pkg/email/parser_test.go +++ b/pkg/email/parser_test.go @@ -442,6 +442,7 @@ For more options, visit https://groups.google.com/d/optout.`, Subject: "test subject", Author: "bob@example.com", Cc: []string{"bob@example.com"}, + RawCc: []string{"bob@example.com", "foo+4564456@bar.com"}, Body: `text body second line #syz fix: arg1 arg2 arg3 @@ -482,6 +483,7 @@ To view this discussion visit https://groups.google.com/d/msgid/syzkaller-bugs/6 Subject: "new footer", Author: "bob@example.com", Cc: []string{"bob@example.com"}, + RawCc: []string{"bob@example.com", "foo+4564456@bar.com"}, Body: `some title -- @@ -508,6 +510,7 @@ last line`, Author: "foo@bar.com", OwnEmail: true, Cc: []string{"bob@example.com"}, + RawCc: []string{"bob@example.com", "foo+4564456@bar.com"}, Body: `text body last line`, Patch: "", @@ -529,6 +532,7 @@ last line`, Subject: "test subject", Author: "bob@example.com", Cc: []string{"alice@example.com", "bob@example.com", "bot@example.com"}, + RawCc: []string{"alice@example.com", "bob@example.com", "bot@example.com"}, Body: `#syz invalid text body second line @@ -560,6 +564,7 @@ last line Subject: "test subject", Author: "bob@example.com", Cc: []string{"alice@example.com", "bob@example.com", "bot@example.com"}, + RawCc: []string{"alice@example.com", "bob@example.com", "bot@example.com"}, Body: `text body second line last line @@ -605,6 +610,7 @@ IHQpKSB7CiAJCXNwaW5fdW5sb2NrKCZrY292LT5sb2NrKTsKIAkJcmV0dXJuOwo= Subject: "test subject", Author: "bob@example.com", Cc: []string{"bob@example.com", "bot@example.com"}, + RawCc: []string{"bob@example.com", "bot@example.com"}, Body: `body text >#syz test `, @@ -692,6 +698,7 @@ or) Subject: "test subject", Author: "bob@example.com", Cc: []string{"bob@example.com", "bot@example.com"}, + RawCc: []string{"bob@example.com", "bot@example.com"}, Body: `On Mon, May 8, 2017 at 6:47 PM, Bob wrote: > body text @@ -774,6 +781,7 @@ d Subject: "Re: BUG: unable to handle kernel NULL pointer dereference in sock_poll", Author: "bar@foo.com", Cc: []string{"bar@foo.com", "syzbot@syzkaller.appspotmail.com"}, + RawCc: []string{"bar@foo.com", "syzbot+344bb0f46d7719cd9483@syzkaller.appspotmail.com"}, Body: `On 2018/06/10 4:57, syzbot wrote: > Hello, > @@ -804,6 +812,7 @@ BUG: unable to handle kernel NULL pointer dereference in corrupted `, Email{ Author: "bar@foo.com", Cc: []string{"bar@foo.com", "syzbot@syzkaller.appspotmail.com"}, + RawCc: []string{"bar@foo.com", "syzbot+6dd701dc797b23b8c761@syzkaller.appspotmail.com"}, Body: `#syz dup: BUG: unable to handle kernel NULL pointer dereference in corrupted `, @@ -825,6 +834,7 @@ When freeing a lockf struct that already is part of a linked list, make sure to `, Email{ Author: "bar@foo.com", Cc: []string{"bar@foo.com", "syzbot@syzkaller.appspotmail.com"}, + RawCc: []string{"bar@foo.com", "syzbot+6dd701dc797b23b8c761@syzkaller.appspotmail.com"}, Body: `#syz fix: When freeing a lockf struct that already is part of a linked list, make sure to `, @@ -850,6 +860,7 @@ nothing to see here`, Subject: "#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git master", Author: "bob@example.com", Cc: []string{"bob@example.com"}, + RawCc: []string{"bob@example.com", "foo+4564456@bar.com"}, Body: `nothing to see here`, Commands: []*SingleCommand{ { @@ -874,6 +885,7 @@ nothing to see here`, Author: "user@mail.com", MailingList: "list@googlegroups.com", Cc: []string{"list@googlegroups.com", "user@mail.com"}, + RawCc: []string{"list@googlegroups.com", "user@mail.com"}, Body: `nothing to see here`, }}, {`Date: Sun, 7 May 2017 19:54:00 -0700 @@ -891,6 +903,7 @@ nothing to see here`, Author: "user@mail.com", MailingList: "list@googlegroups.com", Cc: []string{"list@googlegroups.com", "user2@mail.com", "user@mail.com"}, + RawCc: []string{"list@googlegroups.com", "user2@mail.com", "user@mail.com"}, Body: `nothing to see here`, }}, // A faulty case, just check we handle it normally. @@ -908,6 +921,7 @@ nothing to see here`, Author: "list@googlegroups.com", MailingList: "list@googlegroups.com", Cc: []string{"list@googlegroups.com", "user2@mail.com"}, + RawCc: []string{"list@googlegroups.com", "user2@mail.com"}, Body: `nothing to see here`, }}, {`Sender: syzkaller-bugs@googlegroups.com @@ -931,6 +945,7 @@ f950fddb9ea6bdb5e39 Subject: "Re: BUG: unable to handle kernel NULL pointer dereference in sock_poll", Author: "bar@foo.com", Cc: []string{"bar@foo.com", "syzbot@syzkaller.appspotmail.com"}, + RawCc: []string{"bar@foo.com", "syzbot+344bb0f46d7719cd9483@syzkaller.appspotmail.com"}, Body: `#syz test: https://github.com/torvalds/linux.git 7b5bb460defa107dd2e82f950fddb9ea6bdb5e39 `, @@ -961,6 +976,7 @@ Reported-by: syzbot Subject: "[PATCH] Some patch", Author: "bar@foo.com", Cc: []string{"bar@foo.com", "someone@foo.com"}, + RawCc: []string{"bar@foo.com", "someone@foo.com"}, Body: `Reported-by: syzbot `, }}, @@ -982,6 +998,7 @@ Link: https://bar.com/bug?extid=223c7461c58c58a4cb10@bar.com Subject: "[PATCH] Some patch", Author: "bar@foo.com", Cc: []string{"bar@foo.com", "someone@foo.com"}, + RawCc: []string{"bar@foo.com", "someone@foo.com"}, Body: `Link: https://bar.com/bug?extid=223c7461c58c58a4cb10@bar.com `, }}, @@ -1006,6 +1023,7 @@ Reported-by: syzbot Subject: "[PATCH] Some patch", Author: "bar@foo.com", Cc: []string{"bar@foo.com", "someone@foo.com"}, + RawCc: []string{"bar@foo.com", "someone@foo.com"}, Body: `Reported-by: syzbot Reported-by: syzbot `, @@ -1030,6 +1048,7 @@ Reported-by: syzbot Subject: "[PATCH] Some patch", Author: "bar@foo.com", Cc: []string{"bar@foo.com", "someone@foo.com"}, + RawCc: []string{"bar@foo.com", "foo+9909090909090909@bar.com", "someone@foo.com"}, Body: `Reported-by: syzbot `, }}, @@ -1058,6 +1077,7 @@ Some text Subject: "Some discussion", Author: "bar@foo.com", Cc: []string{"bar@foo.com", "someone@foo.com"}, + RawCc: []string{"bar@foo.com", "someone@foo.com"}, Body: "Some text\n", }}, {`Sender: syzkaller-bugs@googlegroups.com @@ -1080,6 +1100,7 @@ Content-Transfer-Encoding: quoted-printable Subject: "Re: BUG: unable to handle kernel NULL pointer dereference in sock_poll", Author: "bar@foo.com", Cc: []string{"bar@foo.com", "syzbot@syzkaller.appspotmail.com"}, + RawCc: []string{"bar@foo.com", "syzbot+344bb0f46d7719cd9483@syzkaller.appspotmail.com"}, Body: `#syz test: aaa bbb #syz test: ccc ddd `, -- cgit mrf-deployment