From 67ef0ea2b648fd72cc7f0e3ec50c5b2fa144b80c Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 10 Oct 2025 17:45:29 +0200 Subject: pkg/email/lore: wrap the Email object Wrapping the email.Email object will let us add lore-specific fields to it at a later point. --- pkg/email/lore/parse_test.go | 143 +++++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 65 deletions(-) (limited to 'pkg/email/lore/parse_test.go') diff --git a/pkg/email/lore/parse_test.go b/pkg/email/lore/parse_test.go index 0480729ff..743ffc976 100644 --- a/pkg/email/lore/parse_test.go +++ b/pkg/email/lore/parse_test.go @@ -6,7 +6,6 @@ package lore import ( "fmt" "sort" - "strings" "testing" "time" @@ -116,29 +115,35 @@ Bug report`, Subject: "Thread A", MessageID: "", Type: dashapi.DiscussionMention, - Messages: []*email.Email{ + Messages: []*Email{ { - MessageID: "", - Subject: "Thread A", - Date: time.Date(2017, time.May, 7, 19, 54, 0, 0, zone), - Author: "a@user.com", - Cc: []string{"a@user.com"}, + Email: &email.Email{ + MessageID: "", + Subject: "Thread A", + Date: time.Date(2017, time.May, 7, 19, 54, 0, 0, zone), + Author: "a@user.com", + Cc: []string{"a@user.com"}, + }, }, { - MessageID: "", - Subject: "Re: Thread A", - Date: time.Date(2017, time.May, 7, 19, 55, 0, 0, zone), - Author: "b@user.com", - Cc: []string{"a@user.com", "b@user.com"}, - InReplyTo: "", + Email: &email.Email{ + MessageID: "", + Subject: "Re: Thread A", + Date: time.Date(2017, time.May, 7, 19, 55, 0, 0, zone), + Author: "b@user.com", + Cc: []string{"a@user.com", "b@user.com"}, + InReplyTo: "", + }, }, { - MessageID: "", - Subject: "Re: Re: Thread A", - Date: time.Date(2017, time.May, 7, 19, 56, 0, 0, zone), - Author: "c@user.com", - Cc: []string{"a@user.com", "b@user.com", "c@user.com"}, - InReplyTo: "", + Email: &email.Email{ + MessageID: "", + Subject: "Re: Re: Thread A", + Date: time.Date(2017, time.May, 7, 19, 56, 0, 0, zone), + Author: "c@user.com", + Cc: []string{"a@user.com", "b@user.com", "c@user.com"}, + InReplyTo: "", + }, }, }, }, @@ -147,32 +152,38 @@ Bug report`, MessageID: "", Type: dashapi.DiscussionReport, BugIDs: []string{"4564456"}, - Messages: []*email.Email{ + Messages: []*Email{ { - MessageID: "", - BugIDs: []string{"4564456"}, - Subject: "[syzbot] Some bug", - Date: time.Date(2017, time.May, 7, 19, 57, 0, 0, zone), - Author: "syzbot@bar.com", - OwnEmail: true, + Email: &email.Email{ + MessageID: "", + BugIDs: []string{"4564456"}, + Subject: "[syzbot] Some bug", + Date: time.Date(2017, time.May, 7, 19, 57, 0, 0, zone), + Author: "syzbot@bar.com", + OwnEmail: true, + }, }, { - MessageID: "", - BugIDs: []string{"4564456"}, - Subject: "Re: [syzbot] Some bug", - Date: time.Date(2017, time.May, 7, 19, 58, 0, 0, zone), - Author: "c@user.com", - Cc: []string{"c@user.com"}, - InReplyTo: "", + Email: &email.Email{ + MessageID: "", + BugIDs: []string{"4564456"}, + Subject: "Re: [syzbot] Some bug", + Date: time.Date(2017, time.May, 7, 19, 58, 0, 0, zone), + Author: "c@user.com", + Cc: []string{"c@user.com"}, + InReplyTo: "", + }, }, { - MessageID: "", - 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: "", + Email: &email.Email{ + MessageID: "", + 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: "", + }, }, }, }, @@ -181,14 +192,16 @@ Bug report`, MessageID: "", Type: dashapi.DiscussionPatch, BugIDs: []string{"12345"}, - Messages: []*email.Email{ + Messages: []*Email{ { - MessageID: "", - BugIDs: []string{"12345"}, - Subject: "[PATCH] Some bug fixed", - Date: time.Date(2017, time.May, 7, 19, 58, 1, 0, zone), - Author: "e@user.com", - Cc: []string{"e@user.com"}, + Email: &email.Email{ + MessageID: "", + BugIDs: []string{"12345"}, + Subject: "[PATCH] Some bug fixed", + Date: time.Date(2017, time.May, 7, 19, 58, 1, 0, zone), + Author: "e@user.com", + Cc: []string{"e@user.com"}, + }, }, }, }, @@ -197,29 +210,29 @@ Bug report`, MessageID: "", Type: dashapi.DiscussionMention, BugIDs: []string{"4564456"}, - Messages: []*email.Email{ + Messages: []*Email{ { - MessageID: "", - InReplyTo: "", - Date: time.Date(2017, time.May, 7, 19, 57, 0, 0, zone), - BugIDs: []string{"4564456"}, - Cc: []string{"person@email.com"}, - Subject: "Another bug discussion", - Author: "person@email.com", + Email: &email.Email{ + MessageID: "", + InReplyTo: "", + Date: time.Date(2017, time.May, 7, 19, 57, 0, 0, zone), + BugIDs: []string{"4564456"}, + Cc: []string{"person@email.com"}, + Subject: "Another bug discussion", + Author: "person@email.com", + }, }, }, }, "": nil, } - emails := []*email.Email{} + var emails []*Email for _, m := range messages { - msg, err := email.Parse(strings.NewReader(m), []string{"syzbot@bar.com"}, - []string{}, []string{"bar.com"}) + msg, err := emailFromRaw([]byte(m), []string{"syzbot@bar.com"}, []string{"bar.com"}) if err != nil { t.Fatal(err) } - msg.Body = "" msg.RawCc = nil emails = append(emails, msg) } @@ -418,9 +431,9 @@ Content-Type: text/plain Bug report`, } - emails := []*email.Email{} + var emails []*Email for _, m := range messages { - msg, err := email.Parse(strings.NewReader(m), nil, nil, nil) + msg, err := emailFromRaw([]byte(m), nil, nil) if err != nil { t.Fatal(err) } @@ -437,7 +450,7 @@ Bug report`, Patches: []Patch{ { Seq: 1, - Email: &email.Email{Subject: "[PATCH] Small patch"}, + Email: &Email{Email: &email.Email{Subject: "[PATCH] Small patch"}}, }, }, }, @@ -448,11 +461,11 @@ Bug report`, Patches: []Patch{ { Seq: 1, - Email: &email.Email{Subject: "[PATCH v2 01/02] First patch"}, + Email: &Email{Email: &email.Email{Subject: "[PATCH v2 01/02] First patch"}}, }, { Seq: 2, - Email: &email.Email{Subject: "[PATCH v2 02/02] Second patch"}, + Email: &Email{Email: &email.Email{Subject: "[PATCH v2 02/02] Second patch"}}, }, }, }, @@ -463,7 +476,7 @@ Bug report`, Patches: []Patch{ { Seq: 1, - Email: &email.Email{Subject: "[PATCH 01/03] Series"}, + Email: &Email{Email: &email.Email{Subject: "[PATCH 01/03] Series"}}, }, }, }, -- cgit mrf-deployment