blob: 6f5b52b7c352a250f9154e3774214a297fc072e2 [file] [log] [blame]
Dusan Kasan17e497e2017-04-10 22:44:22 +02001package parsemail_test
2
3import (
Dusan Kasan17e497e2017-04-10 22:44:22 +02004 "encoding/base64"
Dusan Kasan4595dfe2017-04-13 00:38:24 +02005 "github.com/DusanKasan/parsemail"
Dusan Kasan17e497e2017-04-10 22:44:22 +02006 "io/ioutil"
Dusan Kasan4595dfe2017-04-13 00:38:24 +02007 "net/mail"
8 "strings"
9 "testing"
10 "time"
Dusan Kasan17e497e2017-04-10 22:44:22 +020011)
12
13func TestParseEmail(t *testing.T) {
Dusan Kasan4595dfe2017-04-13 00:38:24 +020014 var testData = map[int]struct {
Dusan Kasan17e497e2017-04-10 22:44:22 +020015 mailData string
16
Dusan Kasan4595dfe2017-04-13 00:38:24 +020017 subject string
18 date time.Time
19 from []mail.Address
20 sender mail.Address
21 to []mail.Address
22 replyTo []mail.Address
23 cc []mail.Address
24 bcc []mail.Address
25 messageID string
26 resentDate time.Time
27 resentFrom []mail.Address
28 resentSender mail.Address
29 resentTo []mail.Address
30 resentReplyTo []mail.Address
31 resentCc []mail.Address
32 resentBcc []mail.Address
Dusan Kasanb49ceb62017-04-13 00:00:36 +020033 resentMessageID string
Dusan Kasan4595dfe2017-04-13 00:38:24 +020034 inReplyTo []string
35 references []string
36 htmlBody string
37 textBody string
38 attachments []attachmentData
39 embeddedFiles []embeddedFileData
40 headerCheck func(mail.Header, *testing.T)
Dusan Kasan17e497e2017-04-10 22:44:22 +020041 }{
Dusan Kasanb49ceb62017-04-13 00:00:36 +020042 1: {
43 mailData: RFC5322_Example_A11,
Dusan Kasan4595dfe2017-04-13 00:38:24 +020044 subject: "Saying Hello",
Dusan Kasanb49ceb62017-04-13 00:00:36 +020045 from: []mail.Address{
46 {"John Doe", "jdoe@machine.example"},
47 },
48 to: []mail.Address{
49 {"Mary Smith", "mary@example.net"},
50 },
Dusan Kasan4595dfe2017-04-13 00:38:24 +020051 sender: mail.Address{"Michael Jones", "mjones@machine.example"},
Dusan Kasanb49ceb62017-04-13 00:00:36 +020052 messageID: "1234@local.machine.example",
Dusan Kasan4595dfe2017-04-13 00:38:24 +020053 date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"),
Dusan Kasanb49ceb62017-04-13 00:00:36 +020054 textBody: `This is a message just to say hello.
55So, "Hello".`,
56 },
57 2: {
58 mailData: RFC5322_Example_A12,
59 from: []mail.Address{
60 {"Joe Q. Public", "john.q.public@example.com"},
61 },
62 to: []mail.Address{
63 {"Mary Smith", "mary@x.test"},
64 {"", "jdoe@example.org"},
65 {"Who?", "one@y.test"},
66 },
67 cc: []mail.Address{
68 {"", "boss@nil.test"},
69 {"Giant; \"Big\" Box", "sysservices@example.net"},
70 },
71 messageID: "5678.21-Nov-1997@example.com",
Dusan Kasan4595dfe2017-04-13 00:38:24 +020072 date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"),
73 textBody: `Hi everyone.`,
Dusan Kasanb49ceb62017-04-13 00:00:36 +020074 },
75 3: {
76 mailData: RFC5322_Example_A2a,
Dusan Kasan4595dfe2017-04-13 00:38:24 +020077 subject: "Re: Saying Hello",
Dusan Kasanb49ceb62017-04-13 00:00:36 +020078 from: []mail.Address{
79 {"Mary Smith", "mary@example.net"},
80 },
81 replyTo: []mail.Address{
82 {"Mary Smith: Personal Account", "smith@home.example"},
83 },
84 to: []mail.Address{
85 {"John Doe", "jdoe@machine.example"},
86 },
Dusan Kasan4595dfe2017-04-13 00:38:24 +020087 messageID: "3456@example.net",
88 inReplyTo: []string{"1234@local.machine.example"},
Dusan Kasanb49ceb62017-04-13 00:00:36 +020089 references: []string{"1234@local.machine.example"},
Dusan Kasan4595dfe2017-04-13 00:38:24 +020090 date: parseDate("Fri, 21 Nov 1997 10:01:10 -0600"),
91 textBody: `This is a reply to your hello.`,
Dusan Kasanb49ceb62017-04-13 00:00:36 +020092 },
93 4: {
94 mailData: RFC5322_Example_A2b,
Dusan Kasan4595dfe2017-04-13 00:38:24 +020095 subject: "Re: Saying Hello",
Dusan Kasanb49ceb62017-04-13 00:00:36 +020096 from: []mail.Address{
97 {"John Doe", "jdoe@machine.example"},
98 },
99 to: []mail.Address{
100 {"Mary Smith: Personal Account", "smith@home.example"},
101 },
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200102 messageID: "abcd.1234@local.machine.test",
103 inReplyTo: []string{"3456@example.net"},
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200104 references: []string{"1234@local.machine.example", "3456@example.net"},
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200105 date: parseDate("Fri, 21 Nov 1997 11:00:00 -0600"),
106 textBody: `This is a reply to your reply.`,
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200107 },
108 5: {
109 mailData: RFC5322_Example_A3,
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200110 subject: "Saying Hello",
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200111 from: []mail.Address{
112 {"John Doe", "jdoe@machine.example"},
113 },
114 to: []mail.Address{
115 {"Mary Smith", "mary@example.net"},
116 },
117 messageID: "1234@local.machine.example",
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200118 date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"),
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200119 resentFrom: []mail.Address{
120 {"Mary Smith", "mary@example.net"},
121 },
122 resentTo: []mail.Address{
123 {"Jane Brown", "j-brown@other.example"},
124 },
125 resentMessageID: "78910@example.net",
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200126 resentDate: parseDate("Mon, 24 Nov 1997 14:22:01 -0800"),
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200127 textBody: `This is a message just to say hello.
128So, "Hello".`,
129 },
130 6: {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200131 mailData: Data1,
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200132 subject: "Test Subject 1",
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200133 from: []mail.Address{
134 {"Peter Paholík", "peter.paholik@gmail.com"},
135 },
136 to: []mail.Address{
137 {"", "dusan@kasan.sk"},
138 },
Dusan Kasan17e497e2017-04-10 22:44:22 +0200139 messageID: "CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com",
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200140 date: parseDate("Fri, 07 Apr 2017 09:17:26 +0200"),
141 htmlBody: "<div dir=\"ltr\"><br></div>",
Dusan Kasan17e497e2017-04-10 22:44:22 +0200142 attachments: []attachmentData{
143 {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200144 filename: "Peter Paholík 1 4 2017 2017-04-07.pdf",
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200145 contentType: "application/pdf",
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200146 base64data: "JVBERi0xLjQNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIvTGFuZyhlbi1VUykgL1N0cnVjdFRyZWVSb290IDY3IDAgUi9NYXJrSW5mbzw8L01hcmtlZCB0cnVlPj4vT3V0cHV0SW50ZW50c1s8PC9UeXBlL091dHB1dEludGVudC9TL0dUU19QREZBMS9PdXRwdXRDb25kZXYgMzk1MzYyDQo+Pg0Kc3RhcnR4cmVmDQo0MTk4ODUNCiUlRU9GDQo=",
Dusan Kasan17e497e2017-04-10 22:44:22 +0200147 },
148 },
149 },
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200150 7: {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200151 mailData: Data2,
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200152 subject: "Re: Test Subject 2",
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200153 from: []mail.Address{
154 {"Sender Man", "sender@domain.com"},
155 },
156 to: []mail.Address{
157 {"", "info@receiver.com"},
158 },
159 cc: []mail.Address{
160 {"Cc Man", "ccman@gmail.com"},
161 },
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200162 messageID: "0e9a21b4-01dc-e5c1-dcd6-58ce5aa61f4f@receiver.com",
163 inReplyTo: []string{"9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@receiver.eu"},
Dusan Kasan17e497e2017-04-10 22:44:22 +0200164 references: []string{"2f6b7595-c01e-46e5-42bc-f263e1c4282d@receiver.com", "9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@domain.com"},
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200165 date: parseDate("Fri, 07 Apr 2017 12:59:55 +0200"),
166 htmlBody: `<html>data<img src="part2.9599C449.04E5EC81@develhell.com"/></html>`,
Dusan Kasan17e497e2017-04-10 22:44:22 +0200167 textBody: `First level
168> Second level
169>> Third level
170>
171`,
172 embeddedFiles: []embeddedFileData{
173 {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200174 cid: "part2.9599C449.04E5EC81@develhell.com",
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200175 contentType: "image/png",
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200176 base64data: "iVBORw0KGgoAAAANSUhEUgAAAQEAAAAYCAIAAAB1IN9NAAAACXBIWXMAAAsTAAALEwEAmpwYYKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg==",
Dusan Kasan17e497e2017-04-10 22:44:22 +0200177 },
178 },
179 },
180 }
181
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200182 for index, td := range testData {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200183 e, err := parsemail.Parse(strings.NewReader(td.mailData))
184 if err != nil {
185 t.Error(err)
186 }
187
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200188 if td.subject != e.Subject {
189 t.Errorf("[Test Case %v] Wrong subject. Expected: %s, Got: %s", index, td.subject, e.Subject)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200190 }
191
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200192 if td.messageID != e.MessageID {
193 t.Errorf("[Test Case %v] Wrong messageID. Expected: '%s', Got: '%s'", index, td.messageID, e.MessageID)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200194 }
195
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200196 if !td.date.Equal(e.Date) {
197 t.Errorf("[Test Case %v] Wrong date. Expected: %v, Got: %v", index, td.date, e.Date)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200198 }
199
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200200 d := dereferenceAddressList(e.From)
201 if !assertAddressListEq(td.from, d) {
202 t.Errorf("[Test Case %v] Wrong from. Expected: %s, Got: %s", index, td.from, d)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200203 }
204
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200205 var sender mail.Address
206 if e.Sender != nil {
207 sender = *e.Sender
208 }
209 if td.sender != sender {
210 t.Errorf("[Test Case %v] Wrong sender. Expected: %s, Got: %s", index, td.sender, sender)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200211 }
212
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200213 d = dereferenceAddressList(e.To)
214 if !assertAddressListEq(td.to, d) {
215 t.Errorf("[Test Case %v] Wrong to. Expected: %s, Got: %s", index, td.to, d)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200216 }
217
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200218 d = dereferenceAddressList(e.Cc)
219 if !assertAddressListEq(td.cc, d) {
220 t.Errorf("[Test Case %v] Wrong cc. Expected: %s, Got: %s", index, td.cc, d)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200221 }
222
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200223 d = dereferenceAddressList(e.Bcc)
224 if !assertAddressListEq(td.bcc, d) {
225 t.Errorf("[Test Case %v] Wrong bcc. Expected: %s, Got: %s", index, td.bcc, d)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200226 }
227
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200228 if td.resentMessageID != e.ResentMessageID {
229 t.Errorf("[Test Case %v] Wrong resent messageID. Expected: '%s', Got: '%s'", index, td.resentMessageID, e.ResentMessageID)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200230 }
231
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200232 if !td.resentDate.Equal(e.ResentDate) && !td.resentDate.IsZero() && !e.ResentDate.IsZero() {
233 t.Errorf("[Test Case %v] Wrong resent date. Expected: %v, Got: %v", index, td.resentDate, e.ResentDate)
234 }
235
236 d = dereferenceAddressList(e.ResentFrom)
237 if !assertAddressListEq(td.resentFrom, d) {
238 t.Errorf("[Test Case %v] Wrong resent from. Expected: %s, Got: %s", index, td.resentFrom, d)
239 }
240
241 var resentSender mail.Address
242 if e.ResentSender != nil {
243 resentSender = *e.ResentSender
244 }
245 if td.resentSender != resentSender {
246 t.Errorf("[Test Case %v] Wrong resent sender. Expected: %s, Got: %s", index, td.resentSender, resentSender)
247 }
248
249 d = dereferenceAddressList(e.ResentTo)
250 if !assertAddressListEq(td.resentTo, d) {
251 t.Errorf("[Test Case %v] Wrong resent to. Expected: %s, Got: %s", index, td.resentTo, d)
252 }
253
254 d = dereferenceAddressList(e.ResentCc)
255 if !assertAddressListEq(td.resentCc, d) {
256 t.Errorf("[Test Case %v] Wrong resent cc. Expected: %s, Got: %s", index, td.resentCc, d)
257 }
258
259 d = dereferenceAddressList(e.ResentBcc)
260 if !assertAddressListEq(td.resentBcc, d) {
261 t.Errorf("[Test Case %v] Wrong resent bcc. Expected: %s, Got: %s", index, td.resentBcc, d)
262 }
263
264 if !assertSliceEq(td.inReplyTo, e.InReplyTo) {
265 t.Errorf("[Test Case %v] Wrong in reply to. Expected: %s, Got: %s", index, td.inReplyTo, e.InReplyTo)
266 }
267
268 if !assertSliceEq(td.references, e.References) {
269 t.Errorf("[Test Case %v] Wrong references. Expected: %s, Got: %s", index, td.references, e.References)
270 }
271
272 d = dereferenceAddressList(e.ReplyTo)
273 if !assertAddressListEq(td.replyTo, d) {
274 t.Errorf("[Test Case %v] Wrong reply to. Expected: %s, Got: %s", index, td.replyTo, d)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200275 }
276
277 if td.htmlBody != e.HTMLBody {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200278 t.Errorf("[Test Case %v] Wrong html body. Expected: '%s', Got: '%s'", index, td.htmlBody, e.HTMLBody)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200279 }
280
281 if td.textBody != e.TextBody {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200282 t.Errorf("[Test Case %v] Wrong text body. Expected: '%s', Got: '%s'", index, td.textBody, e.TextBody)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200283 }
284
Dusan Kasan17e497e2017-04-10 22:44:22 +0200285 if len(td.attachments) != len(e.Attachments) {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200286 t.Errorf("[Test Case %v] Incorrect number of attachments! Expected: %v, Got: %v.", index, len(td.attachments), len(e.Attachments))
Dusan Kasan17e497e2017-04-10 22:44:22 +0200287 } else {
288 attachs := e.Attachments[:]
289
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200290 for _, ad := range td.attachments {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200291 found := false
292
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200293 for i, ra := range attachs {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200294 b, err := ioutil.ReadAll(ra.Data)
295 if err != nil {
296 t.Error(err)
297 }
298
299 encoded := base64.StdEncoding.EncodeToString(b)
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200300 if ra.Filename == ad.filename && encoded == ad.base64data && ra.ContentType == ad.contentType {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200301 found = true
302 attachs = append(attachs[:i], attachs[i+1:]...)
303 }
304 }
305
306 if !found {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200307 t.Errorf("[Test Case %v] Attachment not found: %s", index, ad.filename)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200308 }
309 }
310
311 if len(attachs) != 0 {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200312 t.Errorf("[Test Case %v] Email contains %v unexpected attachments: %v", index, len(attachs), attachs)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200313 }
314 }
315
316 if len(td.embeddedFiles) != len(e.EmbeddedFiles) {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200317 t.Errorf("[Test Case %v] Incorrect number of embedded files! Expected: %s, Got: %s.", index, len(td.embeddedFiles), len(e.EmbeddedFiles))
Dusan Kasan17e497e2017-04-10 22:44:22 +0200318 } else {
319 embeds := e.EmbeddedFiles[:]
320
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200321 for _, ad := range td.embeddedFiles {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200322 found := false
323
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200324 for i, ra := range embeds {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200325 b, err := ioutil.ReadAll(ra.Data)
326 if err != nil {
327 t.Error(err)
328 }
329
330 encoded := base64.StdEncoding.EncodeToString(b)
331
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200332 if ra.CID == ad.cid && encoded == ad.base64data && ra.ContentType == ad.contentType {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200333 found = true
334 embeds = append(embeds[:i], embeds[i+1:]...)
335 }
336 }
337
338 if !found {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200339 t.Errorf("[Test Case %v] Embedded file not found: %s", index, ad.cid)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200340 }
341 }
342
343 if len(embeds) != 0 {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200344 t.Errorf("[Test Case %v] Email contains %v unexpected embedded files: %v", index, len(embeds), embeds)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200345 }
346 }
347 }
348}
349
350func parseDate(in string) time.Time {
351 out, err := time.Parse(time.RFC1123Z, in)
352 if err != nil {
353 panic(err)
354 }
355
356 return out
357}
358
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200359type attachmentData struct {
360 filename string
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200361 contentType string
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200362 base64data string
Dusan Kasan17e497e2017-04-10 22:44:22 +0200363}
364
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200365type embeddedFileData struct {
366 cid string
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200367 contentType string
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200368 base64data string
Dusan Kasan17e497e2017-04-10 22:44:22 +0200369}
370
371func assertSliceEq(a, b []string) bool {
372 if len(a) == len(b) && len(a) == 0 {
373 return true
374 }
375
376 if a == nil && b == nil {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200377 return true
Dusan Kasan17e497e2017-04-10 22:44:22 +0200378 }
379
380 if a == nil || b == nil {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200381 return false
Dusan Kasan17e497e2017-04-10 22:44:22 +0200382 }
383
384 if len(a) != len(b) {
385 return false
386 }
387
388 for i := range a {
389 if a[i] != b[i] {
390 return false
391 }
392 }
393
394 return true
395}
396
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200397func assertAddressListEq(a, b []mail.Address) bool {
398 if len(a) == len(b) && len(a) == 0 {
399 return true
400 }
401
402 if a == nil && b == nil {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200403 return true
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200404 }
405
406 if a == nil || b == nil {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200407 return false
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200408 }
409
410 if len(a) != len(b) {
411 return false
412 }
413
414 for i := range a {
415 if a[i] != b[i] {
416 return false
417 }
418 }
419
420 return true
421}
422
423func dereferenceAddressList(al []*mail.Address) (result []mail.Address) {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200424 for _, a := range al {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200425 result = append(result, *a)
426 }
427
428 return
429}
430
Dusan Kasan17e497e2017-04-10 22:44:22 +0200431var Data1 = `From: =?UTF-8?Q?Peter_Pahol=C3=ADk?= <peter.paholik@gmail.com>
432Date: Fri, 7 Apr 2017 09:17:26 +0200
433Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com>
434Subject: Test Subject 1
435To: dusan@kasan.sk
436Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf
437
438--f403045f1dcc043a44054c8e6bbf
439Content-Type: multipart/alternative; boundary=f403045f1dcc043a3f054c8e6bbd
440
441--f403045f1dcc043a3f054c8e6bbd
442Content-Type: text/plain; charset=UTF-8
443
444
445
446--f403045f1dcc043a3f054c8e6bbd
447Content-Type: text/html; charset=UTF-8
448
449<div dir="ltr"><br></div>
450
451--f403045f1dcc043a3f054c8e6bbd--
452--f403045f1dcc043a44054c8e6bbf
453Content-Type: application/pdf;
454 name="=?UTF-8?Q?Peter_Paholi=CC=81k_1?=
455 =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Epdf?="
456Content-Disposition: attachment;
457 filename="=?UTF-8?Q?Peter_Paholi=CC=81k_1?=
458 =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Epdf?="
459Content-Transfer-Encoding: base64
460X-Attachment-Id: f_j17i0f0d0
461
462JVBERi0xLjQNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIvTGFu
463Zyhlbi1VUykgL1N0cnVjdFRyZWVSb290IDY3IDAgUi9NYXJrSW5mbzw8L01hcmtlZCB0cnVlPj4v
464T3V0cHV0SW50ZW50c1s8PC9UeXBlL091dHB1dEludGVudC9TL0dUU19QREZBMS9PdXRwdXRDb25k
465ZXYgMzk1MzYyDQo+Pg0Kc3RhcnR4cmVmDQo0MTk4ODUNCiUlRU9GDQo=
466--f403045f1dcc043a44054c8e6bbf--
467`
468
469var Data2 = `Subject: Re: Test Subject 2
470To: info@receiver.com
471References: <2f6b7595-c01e-46e5-42bc-f263e1c4282d@receiver.com>
472 <9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@domain.com>
473Cc: Cc Man <ccman@gmail.com>
474From: Sender Man <sender@domain.com>
475Message-ID: <0e9a21b4-01dc-e5c1-dcd6-58ce5aa61f4f@receiver.com>
476Date: Fri, 7 Apr 2017 12:59:55 +0200
477User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0)
478 Gecko/20100101 Thunderbird/45.8.0
479MIME-Version: 1.0
480In-Reply-To: <9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@receiver.eu>
481Content-Type: multipart/alternative;
482 boundary="------------C70C0458A558E585ACB75FB4"
483
484This is a multi-part message in MIME format.
485--------------C70C0458A558E585ACB75FB4
486Content-Type: text/plain; charset=utf-8; format=flowed
487Content-Transfer-Encoding: 8bit
488
489First level
490> Second level
491>> Third level
492>
493
494
495--------------C70C0458A558E585ACB75FB4
496Content-Type: multipart/related;
497 boundary="------------5DB4A1356834BB602A5F88B2"
498
499
500--------------5DB4A1356834BB602A5F88B2
501Content-Type: text/html; charset=utf-8
502Content-Transfer-Encoding: 8bit
503
504<html>data<img src="part2.9599C449.04E5EC81@develhell.com"/></html>
505
506--------------5DB4A1356834BB602A5F88B2
507Content-Type: image/png
508Content-Transfer-Encoding: base64
509Content-ID: <part2.9599C449.04E5EC81@develhell.com>
510
511iVBORw0KGgoAAAANSUhEUgAAAQEAAAAYCAIAAAB1IN9NAAAACXBIWXMAAAsTAAALEwEAmpwY
512YKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg==
513--------------5DB4A1356834BB602A5F88B2
514
515--------------C70C0458A558E585ACB75FB4--
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200516`
517
518var RFC5322_Example_A11 = `From: John Doe <jdoe@machine.example>
519Sender: Michael Jones <mjones@machine.example>
520To: Mary Smith <mary@example.net>
521Subject: Saying Hello
522Date: Fri, 21 Nov 1997 09:55:06 -0600
523Message-ID: <1234@local.machine.example>
524
525This is a message just to say hello.
526So, "Hello".
527`
528
529var RFC5322_Example_A12 = `From: "Joe Q. Public" <john.q.public@example.com>
530To: Mary Smith <mary@x.test>, jdoe@example.org, Who? <one@y.test>
531Cc: <boss@nil.test>, "Giant; \"Big\" Box" <sysservices@example.net>
532Date: Tue, 1 Jul 2003 10:52:37 +0200
533Message-ID: <5678.21-Nov-1997@example.com>
534
535Hi everyone.
536`
537
538//todo: not yet implemented in net/mail
539//once there is support for this, add it
540var RFC5322_Example_A13 = `From: Pete <pete@silly.example>
541To: A Group:Ed Jones <c@a.test>,joe@where.test,John <jdoe@one.test>;
542Cc: Undisclosed recipients:;
543Date: Thu, 13 Feb 1969 23:32:54 -0330
544Message-ID: <testabcd.1234@silly.example>
545
546Testing.
547`
548
549//we skipped the first message bcause it's the same as A 1.1
550var RFC5322_Example_A2a = `From: Mary Smith <mary@example.net>
551To: John Doe <jdoe@machine.example>
552Reply-To: "Mary Smith: Personal Account" <smith@home.example>
553Subject: Re: Saying Hello
554Date: Fri, 21 Nov 1997 10:01:10 -0600
555Message-ID: <3456@example.net>
556In-Reply-To: <1234@local.machine.example>
557References: <1234@local.machine.example>
558
559This is a reply to your hello.
560`
561
562var RFC5322_Example_A2b = `To: "Mary Smith: Personal Account" <smith@home.example>
563From: John Doe <jdoe@machine.example>
564Subject: Re: Saying Hello
565Date: Fri, 21 Nov 1997 11:00:00 -0600
566Message-ID: <abcd.1234@local.machine.test>
567In-Reply-To: <3456@example.net>
568References: <1234@local.machine.example> <3456@example.net>
569
570This is a reply to your reply.
571`
572
573var RFC5322_Example_A3 = `Resent-From: Mary Smith <mary@example.net>
574Resent-To: Jane Brown <j-brown@other.example>
575Resent-Date: Mon, 24 Nov 1997 14:22:01 -0800
576Resent-Message-ID: <78910@example.net>
577From: John Doe <jdoe@machine.example>
578To: Mary Smith <mary@example.net>
579Subject: Saying Hello
580Date: Fri, 21 Nov 1997 09:55:06 -0600
581Message-ID: <1234@local.machine.example>
582
583This is a message just to say hello.
584So, "Hello".`
585
586var RFC5322_Example_A4 = `Received: from x.y.test
587 by example.net
588 via TCP
589 with ESMTP
590 id ABC12345
591 for <mary@example.net>; 21 Nov 1997 10:05:43 -0600
592Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 -0600
593From: John Doe <jdoe@node.example>
594To: Mary Smith <mary@example.net>
595Subject: Saying Hello
596Date: Fri, 21 Nov 1997 09:55:06 -0600
597Message-ID: <1234@local.node.example>
598
599This is a message just to say hello.
600So, "Hello".`