blob: fb9a231a7f3339251c46b03297f2a148d3335d47 [file] [log] [blame]
Dusan Kasanc2129de2017-04-13 10:42:21 +02001package parsemail
Dusan Kasan17e497e2017-04-10 22:44:22 +02002
3import (
Dusan Kasan17e497e2017-04-10 22:44:22 +02004 "encoding/base64"
5 "io/ioutil"
Dusan Kasan4595dfe2017-04-13 00:38:24 +02006 "net/mail"
7 "strings"
8 "testing"
9 "time"
Dusan Kasan17e497e2017-04-10 22:44:22 +020010)
11
12func TestParseEmail(t *testing.T) {
Dusan Kasan4595dfe2017-04-13 00:38:24 +020013 var testData = map[int]struct {
Dusan Kasan17e497e2017-04-10 22:44:22 +020014 mailData string
15
Dusan Kasan4595dfe2017-04-13 00:38:24 +020016 subject string
17 date time.Time
18 from []mail.Address
19 sender mail.Address
20 to []mail.Address
21 replyTo []mail.Address
22 cc []mail.Address
23 bcc []mail.Address
24 messageID string
25 resentDate time.Time
26 resentFrom []mail.Address
27 resentSender mail.Address
28 resentTo []mail.Address
29 resentReplyTo []mail.Address
30 resentCc []mail.Address
31 resentBcc []mail.Address
Dusan Kasanb49ceb62017-04-13 00:00:36 +020032 resentMessageID string
Dusan Kasan4595dfe2017-04-13 00:38:24 +020033 inReplyTo []string
34 references []string
35 htmlBody string
36 textBody string
37 attachments []attachmentData
38 embeddedFiles []embeddedFileData
39 headerCheck func(mail.Header, *testing.T)
Dusan Kasan17e497e2017-04-10 22:44:22 +020040 }{
Dusan Kasanb49ceb62017-04-13 00:00:36 +020041 1: {
42 mailData: RFC5322_Example_A11,
Dusan Kasan4595dfe2017-04-13 00:38:24 +020043 subject: "Saying Hello",
Dusan Kasanb49ceb62017-04-13 00:00:36 +020044 from: []mail.Address{
45 {"John Doe", "jdoe@machine.example"},
46 },
47 to: []mail.Address{
48 {"Mary Smith", "mary@example.net"},
49 },
Dusan Kasan4595dfe2017-04-13 00:38:24 +020050 sender: mail.Address{"Michael Jones", "mjones@machine.example"},
Dusan Kasanb49ceb62017-04-13 00:00:36 +020051 messageID: "1234@local.machine.example",
Dusan Kasan4595dfe2017-04-13 00:38:24 +020052 date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"),
Dusan Kasanb49ceb62017-04-13 00:00:36 +020053 textBody: `This is a message just to say hello.
54So, "Hello".`,
55 },
56 2: {
57 mailData: RFC5322_Example_A12,
58 from: []mail.Address{
59 {"Joe Q. Public", "john.q.public@example.com"},
60 },
61 to: []mail.Address{
62 {"Mary Smith", "mary@x.test"},
63 {"", "jdoe@example.org"},
64 {"Who?", "one@y.test"},
65 },
66 cc: []mail.Address{
67 {"", "boss@nil.test"},
68 {"Giant; \"Big\" Box", "sysservices@example.net"},
69 },
70 messageID: "5678.21-Nov-1997@example.com",
Dusan Kasan4595dfe2017-04-13 00:38:24 +020071 date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"),
72 textBody: `Hi everyone.`,
Dusan Kasanb49ceb62017-04-13 00:00:36 +020073 },
74 3: {
75 mailData: RFC5322_Example_A2a,
Dusan Kasan4595dfe2017-04-13 00:38:24 +020076 subject: "Re: Saying Hello",
Dusan Kasanb49ceb62017-04-13 00:00:36 +020077 from: []mail.Address{
78 {"Mary Smith", "mary@example.net"},
79 },
80 replyTo: []mail.Address{
81 {"Mary Smith: Personal Account", "smith@home.example"},
82 },
83 to: []mail.Address{
84 {"John Doe", "jdoe@machine.example"},
85 },
Dusan Kasan4595dfe2017-04-13 00:38:24 +020086 messageID: "3456@example.net",
87 inReplyTo: []string{"1234@local.machine.example"},
Dusan Kasanb49ceb62017-04-13 00:00:36 +020088 references: []string{"1234@local.machine.example"},
Dusan Kasan4595dfe2017-04-13 00:38:24 +020089 date: parseDate("Fri, 21 Nov 1997 10:01:10 -0600"),
90 textBody: `This is a reply to your hello.`,
Dusan Kasanb49ceb62017-04-13 00:00:36 +020091 },
92 4: {
93 mailData: RFC5322_Example_A2b,
Dusan Kasan4595dfe2017-04-13 00:38:24 +020094 subject: "Re: Saying Hello",
Dusan Kasanb49ceb62017-04-13 00:00:36 +020095 from: []mail.Address{
96 {"John Doe", "jdoe@machine.example"},
97 },
98 to: []mail.Address{
99 {"Mary Smith: Personal Account", "smith@home.example"},
100 },
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200101 messageID: "abcd.1234@local.machine.test",
102 inReplyTo: []string{"3456@example.net"},
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200103 references: []string{"1234@local.machine.example", "3456@example.net"},
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200104 date: parseDate("Fri, 21 Nov 1997 11:00:00 -0600"),
105 textBody: `This is a reply to your reply.`,
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200106 },
107 5: {
108 mailData: RFC5322_Example_A3,
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200109 subject: "Saying Hello",
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200110 from: []mail.Address{
111 {"John Doe", "jdoe@machine.example"},
112 },
113 to: []mail.Address{
114 {"Mary Smith", "mary@example.net"},
115 },
116 messageID: "1234@local.machine.example",
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200117 date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"),
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200118 resentFrom: []mail.Address{
119 {"Mary Smith", "mary@example.net"},
120 },
121 resentTo: []mail.Address{
122 {"Jane Brown", "j-brown@other.example"},
123 },
124 resentMessageID: "78910@example.net",
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200125 resentDate: parseDate("Mon, 24 Nov 1997 14:22:01 -0800"),
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200126 textBody: `This is a message just to say hello.
127So, "Hello".`,
128 },
129 6: {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200130 mailData: Data1,
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200131 subject: "Test Subject 1",
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200132 from: []mail.Address{
133 {"Peter Paholík", "peter.paholik@gmail.com"},
134 },
135 to: []mail.Address{
136 {"", "dusan@kasan.sk"},
137 },
Dusan Kasan17e497e2017-04-10 22:44:22 +0200138 messageID: "CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com",
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200139 date: parseDate("Fri, 07 Apr 2017 09:17:26 +0200"),
140 htmlBody: "<div dir=\"ltr\"><br></div>",
Dusan Kasan17e497e2017-04-10 22:44:22 +0200141 attachments: []attachmentData{
142 {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200143 filename: "Peter Paholík 1 4 2017 2017-04-07.pdf",
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200144 contentType: "application/pdf",
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200145 base64data: "JVBERi0xLjQNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIvTGFuZyhlbi1VUykgL1N0cnVjdFRyZWVSb290IDY3IDAgUi9NYXJrSW5mbzw8L01hcmtlZCB0cnVlPj4vT3V0cHV0SW50ZW50c1s8PC9UeXBlL091dHB1dEludGVudC9TL0dUU19QREZBMS9PdXRwdXRDb25kZXYgMzk1MzYyDQo+Pg0Kc3RhcnR4cmVmDQo0MTk4ODUNCiUlRU9GDQo=",
Dusan Kasan17e497e2017-04-10 22:44:22 +0200146 },
147 },
148 },
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200149 7: {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200150 mailData: Data2,
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200151 subject: "Re: Test Subject 2",
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200152 from: []mail.Address{
153 {"Sender Man", "sender@domain.com"},
154 },
155 to: []mail.Address{
156 {"", "info@receiver.com"},
157 },
158 cc: []mail.Address{
159 {"Cc Man", "ccman@gmail.com"},
160 },
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200161 messageID: "0e9a21b4-01dc-e5c1-dcd6-58ce5aa61f4f@receiver.com",
162 inReplyTo: []string{"9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@receiver.eu"},
Dusan Kasan17e497e2017-04-10 22:44:22 +0200163 references: []string{"2f6b7595-c01e-46e5-42bc-f263e1c4282d@receiver.com", "9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@domain.com"},
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200164 date: parseDate("Fri, 07 Apr 2017 12:59:55 +0200"),
165 htmlBody: `<html>data<img src="part2.9599C449.04E5EC81@develhell.com"/></html>`,
Dusan Kasan17e497e2017-04-10 22:44:22 +0200166 textBody: `First level
167> Second level
168>> Third level
169>
170`,
171 embeddedFiles: []embeddedFileData{
172 {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200173 cid: "part2.9599C449.04E5EC81@develhell.com",
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200174 contentType: "image/png",
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200175 base64data: "iVBORw0KGgoAAAANSUhEUgAAAQEAAAAYCAIAAAB1IN9NAAAACXBIWXMAAAsTAAALEwEAmpwYYKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg==",
Dusan Kasan17e497e2017-04-10 22:44:22 +0200176 },
177 },
178 },
179 }
180
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200181 for index, td := range testData {
Dusan Kasanc2129de2017-04-13 10:42:21 +0200182 e, err := Parse(strings.NewReader(td.mailData))
Dusan Kasan17e497e2017-04-10 22:44:22 +0200183 if err != nil {
184 t.Error(err)
185 }
186
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200187 if td.subject != e.Subject {
188 t.Errorf("[Test Case %v] Wrong subject. Expected: %s, Got: %s", index, td.subject, e.Subject)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200189 }
190
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200191 if td.messageID != e.MessageID {
192 t.Errorf("[Test Case %v] Wrong messageID. Expected: '%s', Got: '%s'", index, td.messageID, e.MessageID)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200193 }
194
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200195 if !td.date.Equal(e.Date) {
196 t.Errorf("[Test Case %v] Wrong date. Expected: %v, Got: %v", index, td.date, e.Date)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200197 }
198
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200199 d := dereferenceAddressList(e.From)
200 if !assertAddressListEq(td.from, d) {
201 t.Errorf("[Test Case %v] Wrong from. Expected: %s, Got: %s", index, td.from, d)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200202 }
203
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200204 var sender mail.Address
205 if e.Sender != nil {
206 sender = *e.Sender
207 }
208 if td.sender != sender {
209 t.Errorf("[Test Case %v] Wrong sender. Expected: %s, Got: %s", index, td.sender, sender)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200210 }
211
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200212 d = dereferenceAddressList(e.To)
213 if !assertAddressListEq(td.to, d) {
214 t.Errorf("[Test Case %v] Wrong to. Expected: %s, Got: %s", index, td.to, d)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200215 }
216
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200217 d = dereferenceAddressList(e.Cc)
218 if !assertAddressListEq(td.cc, d) {
219 t.Errorf("[Test Case %v] Wrong cc. Expected: %s, Got: %s", index, td.cc, d)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200220 }
221
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200222 d = dereferenceAddressList(e.Bcc)
223 if !assertAddressListEq(td.bcc, d) {
224 t.Errorf("[Test Case %v] Wrong bcc. Expected: %s, Got: %s", index, td.bcc, d)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200225 }
226
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200227 if td.resentMessageID != e.ResentMessageID {
228 t.Errorf("[Test Case %v] Wrong resent messageID. Expected: '%s', Got: '%s'", index, td.resentMessageID, e.ResentMessageID)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200229 }
230
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200231 if !td.resentDate.Equal(e.ResentDate) && !td.resentDate.IsZero() && !e.ResentDate.IsZero() {
232 t.Errorf("[Test Case %v] Wrong resent date. Expected: %v, Got: %v", index, td.resentDate, e.ResentDate)
233 }
234
235 d = dereferenceAddressList(e.ResentFrom)
236 if !assertAddressListEq(td.resentFrom, d) {
237 t.Errorf("[Test Case %v] Wrong resent from. Expected: %s, Got: %s", index, td.resentFrom, d)
238 }
239
240 var resentSender mail.Address
241 if e.ResentSender != nil {
242 resentSender = *e.ResentSender
243 }
244 if td.resentSender != resentSender {
245 t.Errorf("[Test Case %v] Wrong resent sender. Expected: %s, Got: %s", index, td.resentSender, resentSender)
246 }
247
248 d = dereferenceAddressList(e.ResentTo)
249 if !assertAddressListEq(td.resentTo, d) {
250 t.Errorf("[Test Case %v] Wrong resent to. Expected: %s, Got: %s", index, td.resentTo, d)
251 }
252
253 d = dereferenceAddressList(e.ResentCc)
254 if !assertAddressListEq(td.resentCc, d) {
255 t.Errorf("[Test Case %v] Wrong resent cc. Expected: %s, Got: %s", index, td.resentCc, d)
256 }
257
258 d = dereferenceAddressList(e.ResentBcc)
259 if !assertAddressListEq(td.resentBcc, d) {
260 t.Errorf("[Test Case %v] Wrong resent bcc. Expected: %s, Got: %s", index, td.resentBcc, d)
261 }
262
263 if !assertSliceEq(td.inReplyTo, e.InReplyTo) {
264 t.Errorf("[Test Case %v] Wrong in reply to. Expected: %s, Got: %s", index, td.inReplyTo, e.InReplyTo)
265 }
266
267 if !assertSliceEq(td.references, e.References) {
268 t.Errorf("[Test Case %v] Wrong references. Expected: %s, Got: %s", index, td.references, e.References)
269 }
270
271 d = dereferenceAddressList(e.ReplyTo)
272 if !assertAddressListEq(td.replyTo, d) {
273 t.Errorf("[Test Case %v] Wrong reply to. Expected: %s, Got: %s", index, td.replyTo, d)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200274 }
275
276 if td.htmlBody != e.HTMLBody {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200277 t.Errorf("[Test Case %v] Wrong html body. Expected: '%s', Got: '%s'", index, td.htmlBody, e.HTMLBody)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200278 }
279
280 if td.textBody != e.TextBody {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200281 t.Errorf("[Test Case %v] Wrong text body. Expected: '%s', Got: '%s'", index, td.textBody, e.TextBody)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200282 }
283
Dusan Kasan17e497e2017-04-10 22:44:22 +0200284 if len(td.attachments) != len(e.Attachments) {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200285 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 +0200286 } else {
287 attachs := e.Attachments[:]
288
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200289 for _, ad := range td.attachments {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200290 found := false
291
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200292 for i, ra := range attachs {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200293 b, err := ioutil.ReadAll(ra.Data)
294 if err != nil {
295 t.Error(err)
296 }
297
298 encoded := base64.StdEncoding.EncodeToString(b)
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200299 if ra.Filename == ad.filename && encoded == ad.base64data && ra.ContentType == ad.contentType {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200300 found = true
301 attachs = append(attachs[:i], attachs[i+1:]...)
302 }
303 }
304
305 if !found {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200306 t.Errorf("[Test Case %v] Attachment not found: %s", index, ad.filename)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200307 }
308 }
309
310 if len(attachs) != 0 {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200311 t.Errorf("[Test Case %v] Email contains %v unexpected attachments: %v", index, len(attachs), attachs)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200312 }
313 }
314
315 if len(td.embeddedFiles) != len(e.EmbeddedFiles) {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200316 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 +0200317 } else {
318 embeds := e.EmbeddedFiles[:]
319
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200320 for _, ad := range td.embeddedFiles {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200321 found := false
322
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200323 for i, ra := range embeds {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200324 b, err := ioutil.ReadAll(ra.Data)
325 if err != nil {
326 t.Error(err)
327 }
328
329 encoded := base64.StdEncoding.EncodeToString(b)
330
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200331 if ra.CID == ad.cid && encoded == ad.base64data && ra.ContentType == ad.contentType {
Dusan Kasan17e497e2017-04-10 22:44:22 +0200332 found = true
333 embeds = append(embeds[:i], embeds[i+1:]...)
334 }
335 }
336
337 if !found {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200338 t.Errorf("[Test Case %v] Embedded file not found: %s", index, ad.cid)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200339 }
340 }
341
342 if len(embeds) != 0 {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200343 t.Errorf("[Test Case %v] Email contains %v unexpected embedded files: %v", index, len(embeds), embeds)
Dusan Kasan17e497e2017-04-10 22:44:22 +0200344 }
345 }
346 }
347}
348
349func parseDate(in string) time.Time {
350 out, err := time.Parse(time.RFC1123Z, in)
351 if err != nil {
352 panic(err)
353 }
354
355 return out
356}
357
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200358type attachmentData struct {
359 filename string
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200360 contentType string
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200361 base64data string
Dusan Kasan17e497e2017-04-10 22:44:22 +0200362}
363
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200364type embeddedFileData struct {
365 cid string
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200366 contentType string
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200367 base64data string
Dusan Kasan17e497e2017-04-10 22:44:22 +0200368}
369
370func assertSliceEq(a, b []string) bool {
371 if len(a) == len(b) && len(a) == 0 {
372 return true
373 }
374
375 if a == nil && b == nil {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200376 return true
Dusan Kasan17e497e2017-04-10 22:44:22 +0200377 }
378
379 if a == nil || b == nil {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200380 return false
Dusan Kasan17e497e2017-04-10 22:44:22 +0200381 }
382
383 if len(a) != len(b) {
384 return false
385 }
386
387 for i := range a {
388 if a[i] != b[i] {
389 return false
390 }
391 }
392
393 return true
394}
395
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200396func assertAddressListEq(a, b []mail.Address) bool {
397 if len(a) == len(b) && len(a) == 0 {
398 return true
399 }
400
401 if a == nil && b == nil {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200402 return true
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200403 }
404
405 if a == nil || b == nil {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200406 return false
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200407 }
408
409 if len(a) != len(b) {
410 return false
411 }
412
413 for i := range a {
414 if a[i] != b[i] {
415 return false
416 }
417 }
418
419 return true
420}
421
422func dereferenceAddressList(al []*mail.Address) (result []mail.Address) {
Dusan Kasan4595dfe2017-04-13 00:38:24 +0200423 for _, a := range al {
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200424 result = append(result, *a)
425 }
426
427 return
428}
429
Dusan Kasan17e497e2017-04-10 22:44:22 +0200430var Data1 = `From: =?UTF-8?Q?Peter_Pahol=C3=ADk?= <peter.paholik@gmail.com>
431Date: Fri, 7 Apr 2017 09:17:26 +0200
432Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com>
433Subject: Test Subject 1
434To: dusan@kasan.sk
435Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf
436
437--f403045f1dcc043a44054c8e6bbf
438Content-Type: multipart/alternative; boundary=f403045f1dcc043a3f054c8e6bbd
439
440--f403045f1dcc043a3f054c8e6bbd
441Content-Type: text/plain; charset=UTF-8
442
443
444
445--f403045f1dcc043a3f054c8e6bbd
446Content-Type: text/html; charset=UTF-8
447
448<div dir="ltr"><br></div>
449
450--f403045f1dcc043a3f054c8e6bbd--
451--f403045f1dcc043a44054c8e6bbf
452Content-Type: application/pdf;
453 name="=?UTF-8?Q?Peter_Paholi=CC=81k_1?=
454 =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Epdf?="
455Content-Disposition: attachment;
456 filename="=?UTF-8?Q?Peter_Paholi=CC=81k_1?=
457 =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Epdf?="
458Content-Transfer-Encoding: base64
459X-Attachment-Id: f_j17i0f0d0
460
461JVBERi0xLjQNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIvTGFu
462Zyhlbi1VUykgL1N0cnVjdFRyZWVSb290IDY3IDAgUi9NYXJrSW5mbzw8L01hcmtlZCB0cnVlPj4v
463T3V0cHV0SW50ZW50c1s8PC9UeXBlL091dHB1dEludGVudC9TL0dUU19QREZBMS9PdXRwdXRDb25k
464ZXYgMzk1MzYyDQo+Pg0Kc3RhcnR4cmVmDQo0MTk4ODUNCiUlRU9GDQo=
465--f403045f1dcc043a44054c8e6bbf--
466`
467
468var Data2 = `Subject: Re: Test Subject 2
469To: info@receiver.com
470References: <2f6b7595-c01e-46e5-42bc-f263e1c4282d@receiver.com>
471 <9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@domain.com>
472Cc: Cc Man <ccman@gmail.com>
473From: Sender Man <sender@domain.com>
474Message-ID: <0e9a21b4-01dc-e5c1-dcd6-58ce5aa61f4f@receiver.com>
475Date: Fri, 7 Apr 2017 12:59:55 +0200
476User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0)
477 Gecko/20100101 Thunderbird/45.8.0
478MIME-Version: 1.0
479In-Reply-To: <9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@receiver.eu>
480Content-Type: multipart/alternative;
481 boundary="------------C70C0458A558E585ACB75FB4"
482
483This is a multi-part message in MIME format.
484--------------C70C0458A558E585ACB75FB4
485Content-Type: text/plain; charset=utf-8; format=flowed
486Content-Transfer-Encoding: 8bit
487
488First level
489> Second level
490>> Third level
491>
492
493
494--------------C70C0458A558E585ACB75FB4
495Content-Type: multipart/related;
496 boundary="------------5DB4A1356834BB602A5F88B2"
497
498
499--------------5DB4A1356834BB602A5F88B2
500Content-Type: text/html; charset=utf-8
501Content-Transfer-Encoding: 8bit
502
503<html>data<img src="part2.9599C449.04E5EC81@develhell.com"/></html>
504
505--------------5DB4A1356834BB602A5F88B2
506Content-Type: image/png
507Content-Transfer-Encoding: base64
508Content-ID: <part2.9599C449.04E5EC81@develhell.com>
509
510iVBORw0KGgoAAAANSUhEUgAAAQEAAAAYCAIAAAB1IN9NAAAACXBIWXMAAAsTAAALEwEAmpwY
511YKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg==
512--------------5DB4A1356834BB602A5F88B2
513
514--------------C70C0458A558E585ACB75FB4--
Dusan Kasanb49ceb62017-04-13 00:00:36 +0200515`
516
517var RFC5322_Example_A11 = `From: John Doe <jdoe@machine.example>
518Sender: Michael Jones <mjones@machine.example>
519To: Mary Smith <mary@example.net>
520Subject: Saying Hello
521Date: Fri, 21 Nov 1997 09:55:06 -0600
522Message-ID: <1234@local.machine.example>
523
524This is a message just to say hello.
525So, "Hello".
526`
527
528var RFC5322_Example_A12 = `From: "Joe Q. Public" <john.q.public@example.com>
529To: Mary Smith <mary@x.test>, jdoe@example.org, Who? <one@y.test>
530Cc: <boss@nil.test>, "Giant; \"Big\" Box" <sysservices@example.net>
531Date: Tue, 1 Jul 2003 10:52:37 +0200
532Message-ID: <5678.21-Nov-1997@example.com>
533
534Hi everyone.
535`
536
537//todo: not yet implemented in net/mail
538//once there is support for this, add it
539var RFC5322_Example_A13 = `From: Pete <pete@silly.example>
540To: A Group:Ed Jones <c@a.test>,joe@where.test,John <jdoe@one.test>;
541Cc: Undisclosed recipients:;
542Date: Thu, 13 Feb 1969 23:32:54 -0330
543Message-ID: <testabcd.1234@silly.example>
544
545Testing.
546`
547
548//we skipped the first message bcause it's the same as A 1.1
549var RFC5322_Example_A2a = `From: Mary Smith <mary@example.net>
550To: John Doe <jdoe@machine.example>
551Reply-To: "Mary Smith: Personal Account" <smith@home.example>
552Subject: Re: Saying Hello
553Date: Fri, 21 Nov 1997 10:01:10 -0600
554Message-ID: <3456@example.net>
555In-Reply-To: <1234@local.machine.example>
556References: <1234@local.machine.example>
557
558This is a reply to your hello.
559`
560
561var RFC5322_Example_A2b = `To: "Mary Smith: Personal Account" <smith@home.example>
562From: John Doe <jdoe@machine.example>
563Subject: Re: Saying Hello
564Date: Fri, 21 Nov 1997 11:00:00 -0600
565Message-ID: <abcd.1234@local.machine.test>
566In-Reply-To: <3456@example.net>
567References: <1234@local.machine.example> <3456@example.net>
568
569This is a reply to your reply.
570`
571
572var RFC5322_Example_A3 = `Resent-From: Mary Smith <mary@example.net>
573Resent-To: Jane Brown <j-brown@other.example>
574Resent-Date: Mon, 24 Nov 1997 14:22:01 -0800
575Resent-Message-ID: <78910@example.net>
576From: John Doe <jdoe@machine.example>
577To: Mary Smith <mary@example.net>
578Subject: Saying Hello
579Date: Fri, 21 Nov 1997 09:55:06 -0600
580Message-ID: <1234@local.machine.example>
581
582This is a message just to say hello.
583So, "Hello".`
584
585var RFC5322_Example_A4 = `Received: from x.y.test
586 by example.net
587 via TCP
588 with ESMTP
589 id ABC12345
590 for <mary@example.net>; 21 Nov 1997 10:05:43 -0600
591Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 -0600
592From: John Doe <jdoe@node.example>
593To: Mary Smith <mary@example.net>
594Subject: Saying Hello
595Date: Fri, 21 Nov 1997 09:55:06 -0600
596Message-ID: <1234@local.node.example>
597
598This is a message just to say hello.
599So, "Hello".`