Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions pkg/email/lore/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Thread struct {
MessageID string
Type dashapi.DiscussionType
BugIDs []string
Messages []*email.Email
Messages []*Email
}

// Series represents a single patch series sent over email.
Expand All @@ -35,19 +35,19 @@ type Series struct {

type Patch struct {
Seq int
*email.Email
*Email
}

// Threads extracts individual threads from a list of emails.
func Threads(emails []*email.Email) []*Thread {
func Threads(emails []*Email) []*Thread {
return listThreads(emails, 0)
}

func listThreads(emails []*email.Email, maxDepth int) []*Thread {
func listThreads(emails []*Email, maxDepth int) []*Thread {
ctx := &parseCtx{
maxDepth: maxDepth,
messages: map[string]*email.Email{},
next: map[*email.Email][]*email.Email{},
messages: map[string]*Email{},
next: map[*Email][]*Email{},
}
for _, email := range emails {
ctx.record(email)
Expand All @@ -57,7 +57,7 @@ func listThreads(emails []*email.Email, maxDepth int) []*Thread {
}

// PatchSeries is similar to Threads, but returns only the patch series submitted to the mailing lists.
func PatchSeries(emails []*email.Email) []*Series {
func PatchSeries(emails []*Email) []*Series {
var ret []*Series
// Normally, all following series patches are sent in response to the first email sent.
// So there's no sense to look at deeper replies.
Expand Down Expand Up @@ -93,6 +93,11 @@ func PatchSeries(emails []*email.Email) []*Series {
// The cover email is not of interest.
continue
}
if !email.HasPatch {
// Sometimes users reply to the series keeping the original subject.
// Ignore such messages.
continue
}
if hasSeq[seq] {
// It's weird if that really happens, but let's skip for now.
continue
Expand Down Expand Up @@ -180,17 +185,17 @@ func parsePatchSubject(subject string) (PatchSubject, bool) {
type parseCtx struct {
maxDepth int
threads []*Thread
messages map[string]*email.Email
next map[*email.Email][]*email.Email
messages map[string]*Email
next map[*Email][]*Email
}

func (c *parseCtx) record(msg *email.Email) {
func (c *parseCtx) record(msg *Email) {
c.messages[msg.MessageID] = msg
}

func (c *parseCtx) process() {
// List messages for which we dont't have ancestors.
nodes := []*email.Email{}
nodes := []*Email{}
for _, msg := range c.messages {
if msg.InReplyTo == "" || c.messages[msg.InReplyTo] == nil {
nodes = append(nodes, msg)
Expand Down Expand Up @@ -220,15 +225,15 @@ func (c *parseCtx) process() {
}
}

func (c *parseCtx) visit(msg *email.Email, thread *Thread, depth int) {
func (c *parseCtx) visit(msg *Email, thread *Thread, depth int) {
var oldInfo *email.OldThreadInfo
if thread != nil {
oldInfo = &email.OldThreadInfo{
ThreadType: thread.Type,
}
}
msgType := DiscussionType(msg)
switch email.NewMessageAction(msg, msgType, oldInfo) {
msgType := DiscussionType(msg.Email)
switch email.NewMessageAction(msg.Email, msgType, oldInfo) {
case email.ActionIgnore:
thread = nil
case email.ActionAppend:
Expand All @@ -238,7 +243,7 @@ func (c *parseCtx) visit(msg *email.Email, thread *Thread, depth int) {
MessageID: msg.MessageID,
Subject: msg.Subject,
Type: msgType,
Messages: []*email.Email{msg},
Messages: []*Email{msg},
}
c.threads = append(c.threads, thread)
}
Expand Down
Loading
Loading