aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/email/lore
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-04-11 16:53:24 +0200
committerAleksandr Nogikh <wp32pw@gmail.com>2023-04-12 13:55:59 +0200
commited75c0a7f1b7d6758be3942746675ff94071d154 (patch)
tree74a7117e09d4a5aeb11589f05e87106ec8d483ba /pkg/email/lore
parentec77d7cc1b8bc1c3058c2bfdcfcccb781f338f20 (diff)
pkg/email/lore: skip syzbot-started subthreads
Adjust tests.
Diffstat (limited to 'pkg/email/lore')
-rw-r--r--pkg/email/lore/parse.go25
-rw-r--r--pkg/email/lore/parse_test.go63
2 files changed, 78 insertions, 10 deletions
diff --git a/pkg/email/lore/parse.go b/pkg/email/lore/parse.go
index 6d90f9ee5..84bb56352 100644
--- a/pkg/email/lore/parse.go
+++ b/pkg/email/lore/parse.go
@@ -36,22 +36,33 @@ func (c *parseCtx) record(msg *email.Email) {
func (c *parseCtx) threads() []*Thread {
threads := map[string]*Thread{}
threadsList := []*Thread{}
+
+ newThread := func(msg *email.Email) {
+ thread := &Thread{
+ MessageID: msg.MessageID,
+ Subject: msg.Subject,
+ }
+ threads[msg.MessageID] = thread
+ threadsList = append(threadsList, thread)
+ }
+
// Detect threads, i.e. messages without In-Reply-To.
for _, msg := range c.messages {
if msg.InReplyTo == "" {
- thread := &Thread{
- MessageID: msg.MessageID,
- Subject: msg.Subject,
- }
- threads[msg.MessageID] = thread
- threadsList = append(threadsList, thread)
+ newThread(msg)
}
}
// Assign messages to threads.
for _, msg := range c.messages {
base := c.first(msg)
if base == nil {
- continue
+ if msg.OwnEmail {
+ // Likely bot's reply to a non-public command. Ignore.
+ continue
+ }
+ // Pretend it's a separate discussion.
+ newThread(msg)
+ base = msg
}
thread := threads[base.MessageID]
thread.BugIDs = append(thread.BugIDs, msg.BugIDs...)
diff --git a/pkg/email/lore/parse_test.go b/pkg/email/lore/parse_test.go
index 90be05200..86e2b51b7 100644
--- a/pkg/email/lore/parse_test.go
+++ b/pkg/email/lore/parse_test.go
@@ -83,6 +83,28 @@ Content-Type: text/plain
Patch`,
+ // An orphaned reply from a human.
+ `Date: Sun, 7 May 2017 19:57:00 -0700
+Subject: [syzbot] Some bug 2
+In-Reply-To: <Unknown>
+Message-ID: <Sub-Discussion>
+From: person@email.com
+Cc: syzbot <syzbot+4564456@bar.com>
+Content-Type: text/plain
+
+
+Bug report`,
+ // An orphaned reply from a bot.
+ `Date: Sun, 7 May 2017 19:57:00 -0700
+Subject: Re: [syzbot] Some bug 3
+In-Reply-To: <Unknown>
+Message-ID: <Sub-Discussion-Bot>
+From: syzbot+4564456@bar.com
+To: all@email.com
+Content-Type: text/plain
+
+
+Bug report`,
}
zone := time.FixedZone("", -7*60*60)
@@ -130,6 +152,7 @@ Patch`,
Subject: "[syzbot] Some bug",
Date: time.Date(2017, time.May, 7, 19, 57, 0, 0, zone),
Author: "syzbot@bar.com",
+ OwnEmail: true,
Command: email.CmdNone,
},
{
@@ -142,6 +165,16 @@ Patch`,
InReplyTo: "<Bug>",
Command: email.CmdNone,
},
+ {
+ MessageID: "<Bug-Reply2>",
+ BugIDs: []string{"4564456"},
+ Subject: "Re: [syzbot] Some bug",
+ Date: time.Date(2017, time.May, 7, 19, 58, 1, 0, zone),
+ Author: "d@user.com",
+ Cc: []string{"d@user.com"},
+ InReplyTo: "<Bug>",
+ Command: email.CmdNone,
+ },
},
},
"<Patch>": {
@@ -160,6 +193,24 @@ Patch`,
},
},
},
+ "<Sub-Discussion>": {
+ Subject: "[syzbot] Some bug 2",
+ MessageID: "<Sub-Discussion>",
+ BugIDs: []string{"4564456"},
+ Messages: []*email.Email{
+ {
+ MessageID: "<Sub-Discussion>",
+ InReplyTo: "<Unknown>",
+ Date: time.Date(2017, time.May, 7, 19, 57, 0, 0, zone),
+ BugIDs: []string{"4564456"},
+ Cc: []string{"person@email.com"},
+ Subject: "[syzbot] Some bug 2",
+ Author: "person@email.com",
+ Command: email.CmdNone,
+ },
+ },
+ },
+ "<Sub-Discussion-Bot>": nil,
}
emails := []*email.Email{}
@@ -174,16 +225,22 @@ Patch`,
}
threads := Threads(emails)
+ got := map[string]*Thread{}
+
for _, d := range threads {
sort.Slice(d.Messages, func(i, j int) bool {
return d.Messages[i].Date.Before(d.Messages[j].Date)
})
- if diff := cmp.Diff(expected[d.MessageID], d); diff != "" {
- t.Fatalf("%s: %s", d.MessageID, diff)
+ got[d.MessageID] = d
+ }
+
+ for key, val := range expected {
+ if diff := cmp.Diff(val, got[key]); diff != "" {
+ t.Fatalf("%s: %s", key, diff)
}
}
- if len(threads) != len(expected) {
+ if len(threads) > len(expected) {
t.Fatalf("Expected %d threads, got %d", len(expected), len(threads))
}
}