forked from DusanKasan/parsemail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsemail_test.go
997 lines (870 loc) · 25.9 KB
/
parsemail_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
package parsemail
import (
"encoding/base64"
"fmt"
"io/ioutil"
"net/mail"
"strings"
"testing"
"time"
)
func TestParseEmail(t *testing.T) {
var testData = map[int]struct {
mailData string
contentType string
content string
subject string
date time.Time
from []mail.Address
sender mail.Address
to []mail.Address
replyTo []mail.Address
cc []mail.Address
bcc []mail.Address
messageID string
resentDate time.Time
resentFrom []mail.Address
resentSender mail.Address
resentTo []mail.Address
resentReplyTo []mail.Address
resentCc []mail.Address
resentBcc []mail.Address
resentMessageID string
inReplyTo []string
references []string
htmlBody string
textBody string
attachments []attachmentData
embeddedFiles []embeddedFileData
headerCheck func(mail.Header, *testing.T)
}{
1: {
mailData: rfc5322exampleA11,
subject: "Saying Hello",
from: []mail.Address{
{
Name: "John Doe",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "Mary Smith",
Address: "[email protected]",
},
},
sender: mail.Address{
Name: "Michael Jones",
Address: "[email protected]",
},
messageID: "[email protected]",
date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"),
textBody: `This is a message just to say hello.
So, "Hello".`,
},
2: {
mailData: rfc5322exampleA12,
from: []mail.Address{
{
Name: "Joe Q. Public",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "Mary Smith",
Address: "[email protected]",
},
{
Name: "",
Address: "[email protected]",
},
{
Name: "Who?",
Address: "[email protected]",
},
},
cc: []mail.Address{
{
Name: "",
Address: "[email protected]",
},
{
Name: "Giant; \"Big\" Box",
Address: "[email protected]",
},
},
messageID: "[email protected]",
date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"),
textBody: `Hi everyone.`,
},
3: {
mailData: rfc5322exampleA2a,
subject: "Re: Saying Hello",
from: []mail.Address{
{
Name: "Mary Smith",
Address: "[email protected]",
},
},
replyTo: []mail.Address{
{
Name: "Mary Smith: Personal Account",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "John Doe",
Address: "[email protected]",
},
},
messageID: "[email protected]",
inReplyTo: []string{"[email protected]"},
references: []string{"[email protected]"},
date: parseDate("Fri, 21 Nov 1997 10:01:10 -0600"),
textBody: `This is a reply to your hello.`,
},
4: {
mailData: rfc5322exampleA2b,
subject: "Re: Saying Hello",
from: []mail.Address{
{
Name: "John Doe",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "Mary Smith: Personal Account",
Address: "[email protected]",
},
},
messageID: "[email protected]",
inReplyTo: []string{"[email protected]"},
references: []string{"[email protected]", "[email protected]"},
date: parseDate("Fri, 21 Nov 1997 11:00:00 -0600"),
textBody: `This is a reply to your reply.`,
},
5: {
mailData: rfc5322exampleA3,
subject: "Saying Hello",
from: []mail.Address{
{
Name: "John Doe",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "Mary Smith",
Address: "[email protected]",
},
},
messageID: "[email protected]",
date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"),
resentFrom: []mail.Address{
{
Name: "Mary Smith",
Address: "[email protected]",
},
},
resentTo: []mail.Address{
{
Name: "Jane Brown",
Address: "[email protected]",
},
},
resentMessageID: "[email protected]",
resentDate: parseDate("Mon, 24 Nov 1997 14:22:01 -0800"),
textBody: `This is a message just to say hello.
So, "Hello".`,
},
6: {
mailData: data1,
contentType: `multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf`,
content: "",
subject: "Peter Paholík",
from: []mail.Address{
{
Name: "Peter Paholík",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "",
Address: "[email protected]",
},
},
messageID: "CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com",
date: parseDate("Fri, 07 Apr 2017 09:17:26 +0200"),
htmlBody: "<div dir=\"ltr\"><br></div>",
attachments: []attachmentData{
{
filename: "Peter Paholík 1 4 2017 2017-04-07.json",
contentType: "application/json",
data: "[1, 2, 3]",
},
},
},
7: {
mailData: data2,
contentType: `multipart/alternative; boundary="------------C70C0458A558E585ACB75FB4"`,
content: "",
subject: "Re: Test Subject 2",
from: []mail.Address{
{
Name: "Sender Man",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "",
Address: "[email protected]",
},
},
cc: []mail.Address{
{
Name: "Cc Man",
Address: "[email protected]",
},
},
messageID: "[email protected]",
inReplyTo: []string{"[email protected]"},
references: []string{"[email protected]", "[email protected]"},
date: parseDate("Fri, 07 Apr 2017 12:59:55 +0200"),
htmlBody: `<html>data<img src="[email protected]"/></html>`,
textBody: `First level
> Second level
>> Third level
>
`,
embeddedFiles: []embeddedFileData{
{
cid: "[email protected]",
contentType: "image/png",
base64data: "iVBORw0KGgoAAAANSUhEUgAAAQEAAAAYCAIAAAB1IN9NAAAACXBIWXMAAAsTAAALEwEAmpwYYKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg==",
},
},
},
8: {
mailData: imageContentExample,
subject: "Saying Hello",
from: []mail.Address{
{
Name: "John Doe",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "Mary Smith",
Address: "[email protected]",
},
},
sender: mail.Address{
Name: "Michael Jones",
Address: "[email protected]",
},
messageID: "[email protected]",
date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"),
contentType: `image/jpeg; x-unix-mode=0644; name="image.gif"`,
content: `GIF89a;`,
},
9: {
contentType: `multipart/mixed; boundary="0000000000007e2bb40587e36196"`,
mailData: textPlainInMultipart,
subject: "Re: kern/54143 (virtualbox)",
from: []mail.Address{
{
Name: "Rares",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "",
Address: "[email protected]",
},
},
date: parseDate("Fri, 02 May 2019 11:25:35 +0300"),
textBody: `plain text part`,
},
10: {
contentType: `multipart/mixed; boundary="0000000000007e2bb40587e36196"`,
mailData: textHTMLInMultipart,
subject: "Re: kern/54143 (virtualbox)",
from: []mail.Address{
{
Name: "Rares",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "",
Address: "[email protected]",
},
},
date: parseDate("Fri, 02 May 2019 11:25:35 +0300"),
textBody: ``,
htmlBody: "<div dir=\"ltr\"><div>html text part</div><div><br></div><div><br><br></div></div>",
},
11: {
mailData: rfc5322exampleA12WithTimezone,
from: []mail.Address{
{
Name: "Joe Q. Public",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "Mary Smith",
Address: "[email protected]",
},
{
Name: "",
Address: "[email protected]",
},
{
Name: "Who?",
Address: "[email protected]",
},
},
cc: []mail.Address{
{
Name: "",
Address: "[email protected]",
},
{
Name: "Giant; \"Big\" Box",
Address: "[email protected]",
},
},
messageID: "[email protected]",
date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"),
textBody: `Hi everyone.`,
},
12: {
contentType: "multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf",
mailData: attachment7bit,
subject: "Peter Foobar",
from: []mail.Address{
{
Name: "Peter Foobar",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "",
Address: "[email protected]",
},
},
messageID: "CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com",
date: parseDate("Tue, 02 Apr 2019 11:12:26 +0000"),
htmlBody: "<div dir=\"ltr\"><br></div>",
attachments: []attachmentData{
{
filename: "unencoded.csv",
contentType: "application/csv",
data: fmt.Sprintf("\n"+`"%s", "%s", "%s", "%s", "%s"`+"\n"+`"%s", "%s", "%s", "%s", "%s"`+"\n", "Some", "Data", "In", "Csv", "Format", "Foo", "Bar", "Baz", "Bum", "Poo"),
},
},
},
13: {
contentType: "multipart/related; boundary=\"000000000000ab2e2205a26de587\"",
mailData: multipartRelatedExample,
subject: "Saying Hello",
from: []mail.Address{
{
Name: "John Doe",
Address: "[email protected]",
},
},
sender: mail.Address{
Name: "Michael Jones",
Address: "[email protected]",
},
to: []mail.Address{
{
Name: "Mary Smith",
Address: "[email protected]",
},
},
messageID: "[email protected]",
date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"),
htmlBody: "<div dir=\"ltr\"><div>Time for the egg.</div><div><br></div><div><br><br></div></div>",
textBody: "Time for the egg.",
},
14: {
contentType: "multipart/alternative; boundary=\"000000000000ab2e1f05a26de586\"",
mailData: base64Content,
subject: "Saying Hello",
from: []mail.Address{
{
Name: "John Doe",
Address: "[email protected]",
},
},
sender: mail.Address{
Name: "Michael Jones",
Address: "[email protected]",
},
to: []mail.Address{
{
Name: "Mary Smith",
Address: "[email protected]",
},
},
messageID: "[email protected]",
date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"),
htmlBody: "<div dir=\"ltr\">👍</div>",
textBody: "👍",
},
}
for index, td := range testData {
e, err := Parse(strings.NewReader(td.mailData))
if err != nil {
t.Error(err)
}
if td.contentType != e.ContentType {
t.Errorf("[Test Case %v] Wrong content type. Expected: %s, Got: %s", index, td.contentType, e.ContentType)
}
if td.content != "" {
b, err := ioutil.ReadAll(e.Content)
if err != nil {
t.Error(err)
} else if td.content != string(b) {
t.Errorf("[Test Case %v] Wrong content. Expected: %s, Got: %s", index, td.content, string(b))
}
}
if td.subject != e.Subject {
t.Errorf("[Test Case %v] Wrong subject. Expected: %s, Got: %s", index, td.subject, e.Subject)
}
if td.messageID != e.MessageID {
t.Errorf("[Test Case %v] Wrong messageID. Expected: '%s', Got: '%s'", index, td.messageID, e.MessageID)
}
if !td.date.Equal(e.Date) {
t.Errorf("[Test Case %v] Wrong date. Expected: %v, Got: %v", index, td.date, e.Date)
}
d := dereferenceAddressList(e.From)
if !assertAddressListEq(td.from, d) {
t.Errorf("[Test Case %v] Wrong from. Expected: %s, Got: %s", index, td.from, d)
}
var sender mail.Address
if e.Sender != nil {
sender = *e.Sender
}
if td.sender != sender {
t.Errorf("[Test Case %v] Wrong sender. Expected: %s, Got: %s", index, td.sender, sender)
}
d = dereferenceAddressList(e.To)
if !assertAddressListEq(td.to, d) {
t.Errorf("[Test Case %v] Wrong to. Expected: %s, Got: %s", index, td.to, d)
}
d = dereferenceAddressList(e.Cc)
if !assertAddressListEq(td.cc, d) {
t.Errorf("[Test Case %v] Wrong cc. Expected: %s, Got: %s", index, td.cc, d)
}
d = dereferenceAddressList(e.Bcc)
if !assertAddressListEq(td.bcc, d) {
t.Errorf("[Test Case %v] Wrong bcc. Expected: %s, Got: %s", index, td.bcc, d)
}
if td.resentMessageID != e.ResentMessageID {
t.Errorf("[Test Case %v] Wrong resent messageID. Expected: '%s', Got: '%s'", index, td.resentMessageID, e.ResentMessageID)
}
if !td.resentDate.Equal(e.ResentDate) && !td.resentDate.IsZero() && !e.ResentDate.IsZero() {
t.Errorf("[Test Case %v] Wrong resent date. Expected: %v, Got: %v", index, td.resentDate, e.ResentDate)
}
d = dereferenceAddressList(e.ResentFrom)
if !assertAddressListEq(td.resentFrom, d) {
t.Errorf("[Test Case %v] Wrong resent from. Expected: %s, Got: %s", index, td.resentFrom, d)
}
var resentSender mail.Address
if e.ResentSender != nil {
resentSender = *e.ResentSender
}
if td.resentSender != resentSender {
t.Errorf("[Test Case %v] Wrong resent sender. Expected: %s, Got: %s", index, td.resentSender, resentSender)
}
d = dereferenceAddressList(e.ResentTo)
if !assertAddressListEq(td.resentTo, d) {
t.Errorf("[Test Case %v] Wrong resent to. Expected: %s, Got: %s", index, td.resentTo, d)
}
d = dereferenceAddressList(e.ResentCc)
if !assertAddressListEq(td.resentCc, d) {
t.Errorf("[Test Case %v] Wrong resent cc. Expected: %s, Got: %s", index, td.resentCc, d)
}
d = dereferenceAddressList(e.ResentBcc)
if !assertAddressListEq(td.resentBcc, d) {
t.Errorf("[Test Case %v] Wrong resent bcc. Expected: %s, Got: %s", index, td.resentBcc, d)
}
if !assertSliceEq(td.inReplyTo, e.InReplyTo) {
t.Errorf("[Test Case %v] Wrong in reply to. Expected: %s, Got: %s", index, td.inReplyTo, e.InReplyTo)
}
if !assertSliceEq(td.references, e.References) {
t.Errorf("[Test Case %v] Wrong references. Expected: %s, Got: %s", index, td.references, e.References)
}
d = dereferenceAddressList(e.ReplyTo)
if !assertAddressListEq(td.replyTo, d) {
t.Errorf("[Test Case %v] Wrong reply to. Expected: %s, Got: %s", index, td.replyTo, d)
}
if td.htmlBody != e.HTMLBody {
t.Errorf("[Test Case %v] Wrong html body. Expected: '%s', Got: '%s'", index, td.htmlBody, e.HTMLBody)
}
if td.textBody != e.TextBody {
t.Errorf("[Test Case %v] Wrong text body. Expected: '%s', Got: '%s'", index, td.textBody, e.TextBody)
}
if len(td.attachments) != len(e.Attachments) {
t.Errorf("[Test Case %v] Incorrect number of attachments! Expected: %v, Got: %v.", index, len(td.attachments), len(e.Attachments))
} else {
attachs := e.Attachments[:]
for _, ad := range td.attachments {
found := false
for i, ra := range attachs {
b, err := ioutil.ReadAll(ra.Data)
if err != nil {
t.Error(err)
}
if ra.Filename == ad.filename && string(b) == ad.data && ra.ContentType == ad.contentType {
found = true
attachs = append(attachs[:i], attachs[i+1:]...)
}
}
if !found {
t.Errorf("[Test Case %v] Attachment not found: %s", index, ad.filename)
}
}
if len(attachs) != 0 {
t.Errorf("[Test Case %v] Email contains %v unexpected attachments: %v", index, len(attachs), attachs)
}
}
if len(td.embeddedFiles) != len(e.EmbeddedFiles) {
t.Errorf("[Test Case %v] Incorrect number of embedded files! Expected: %v, Got: %v.", index, len(td.embeddedFiles), len(e.EmbeddedFiles))
} else {
embeds := e.EmbeddedFiles[:]
for _, ad := range td.embeddedFiles {
found := false
for i, ra := range embeds {
b, err := ioutil.ReadAll(ra.Data)
if err != nil {
t.Error(err)
}
encoded := base64.StdEncoding.EncodeToString(b)
if ra.CID == ad.cid && encoded == ad.base64data && ra.ContentType == ad.contentType {
found = true
embeds = append(embeds[:i], embeds[i+1:]...)
}
}
if !found {
t.Errorf("[Test Case %v] Embedded file not found: %s", index, ad.cid)
}
}
if len(embeds) != 0 {
t.Errorf("[Test Case %v] Email contains %v unexpected embedded files: %v", index, len(embeds), embeds)
}
}
}
}
func parseDate(in string) time.Time {
out, err := time.Parse(time.RFC1123Z, in)
if err != nil {
panic(err)
}
return out
}
type attachmentData struct {
filename string
contentType string
data string
}
type embeddedFileData struct {
cid string
contentType string
base64data string
}
func assertSliceEq(a, b []string) bool {
if len(a) == len(b) && len(a) == 0 {
return true
}
if a == nil && b == nil {
return true
}
if a == nil || b == nil {
return false
}
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
func assertAddressListEq(a, b []mail.Address) bool {
if len(a) == len(b) && len(a) == 0 {
return true
}
if a == nil && b == nil {
return true
}
if a == nil || b == nil {
return false
}
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
func dereferenceAddressList(al []*mail.Address) (result []mail.Address) {
for _, a := range al {
result = append(result, *a)
}
return
}
var data1 = `From: =?UTF-8?Q?Peter_Pahol=C3=ADk?= <[email protected]>
Date: Fri, 7 Apr 2017 09:17:26 +0200
Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com>
Subject: =?UTF-8?Q?Peter_Pahol=C3=ADk?=
Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf
--f403045f1dcc043a44054c8e6bbf
Content-Type: multipart/alternative; boundary=f403045f1dcc043a3f054c8e6bbd
--f403045f1dcc043a3f054c8e6bbd
Content-Type: text/plain; charset=UTF-8
--f403045f1dcc043a3f054c8e6bbd
Content-Type: text/html; charset=UTF-8
<div dir="ltr"><br></div>
--f403045f1dcc043a3f054c8e6bbd--
--f403045f1dcc043a44054c8e6bbf
Content-Type: application/json;
name="=?UTF-8?Q?Peter_Paholi=CC=81k_1?=
=?UTF-8?Q?_4_2017_2017=2D04=2D07=2Ejson?="
Content-Disposition: attachment;
filename="=?UTF-8?Q?Peter_Paholi=CC=81k_1?=
=?UTF-8?Q?_4_2017_2017=2D04=2D07=2Ejson?="
Content-Transfer-Encoding: base64
X-Attachment-Id: f_j17i0f0d0
WzEsIDIsIDNd
--f403045f1dcc043a44054c8e6bbf--
`
var data2 = `Subject: Re: Test Subject 2
References: <[email protected]>
Cc: Cc Man <[email protected]>
From: Sender Man <[email protected]>
Message-ID: <[email protected]>
Date: Fri, 7 Apr 2017 12:59:55 +0200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0)
Gecko/20100101 Thunderbird/45.8.0
MIME-Version: 1.0
In-Reply-To: <[email protected]>
Content-Type: multipart/alternative;
boundary="------------C70C0458A558E585ACB75FB4"
This is a multi-part message in MIME format.
--------------C70C0458A558E585ACB75FB4
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
First level
> Second level
>> Third level
>
--------------C70C0458A558E585ACB75FB4
Content-Type: multipart/related;
boundary="------------5DB4A1356834BB602A5F88B2"
--------------5DB4A1356834BB602A5F88B2
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit
<html>data<img src="[email protected]"/></html>
--------------5DB4A1356834BB602A5F88B2
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-ID: <[email protected]>
iVBORw0KGgoAAAANSUhEUgAAAQEAAAAYCAIAAAB1IN9NAAAACXBIWXMAAAsTAAALEwEAmpwY
YKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg==
--------------5DB4A1356834BB602A5F88B2
--------------C70C0458A558E585ACB75FB4--
`
var textPlainInMultipart = `From: Rares <[email protected]>
Date: Thu, 2 May 2019 11:25:35 +0300
Subject: Re: kern/54143 (virtualbox)
Content-Type: multipart/mixed; boundary="0000000000007e2bb40587e36196"
--0000000000007e2bb40587e36196
Content-Type: text/plain; charset="UTF-8"
plain text part
--0000000000007e2bb40587e36196--
`
var textHTMLInMultipart = `From: Rares <[email protected]>
Date: Thu, 2 May 2019 11:25:35 +0300
Subject: Re: kern/54143 (virtualbox)
Content-Type: multipart/mixed; boundary="0000000000007e2bb40587e36196"
--0000000000007e2bb40587e36196
Content-Type: text/html; charset="UTF-8"
<div dir="ltr"><div>html text part</div><div><br></div><div><br><br></div></div>
--0000000000007e2bb40587e36196--
`
var rfc5322exampleA11 = `From: John Doe <[email protected]>
Sender: Michael Jones <[email protected]>
To: Mary Smith <[email protected]>
Subject: Saying Hello
Date: Fri, 21 Nov 1997 09:55:06 -0600
Message-ID: <[email protected]>
This is a message just to say hello.
So, "Hello".
`
var rfc5322exampleA12 = `From: "Joe Q. Public" <[email protected]>
Cc: <[email protected]>, "Giant; \"Big\" Box" <[email protected]>
Date: Tue, 1 Jul 2003 10:52:37 +0200
Message-ID: <[email protected]>
Hi everyone.
`
var rfc5322exampleA12WithTimezone = `From: "Joe Q. Public" <[email protected]>
Cc: <[email protected]>, "Giant; \"Big\" Box" <[email protected]>
Date: Tue, 1 Jul 2003 10:52:37 +0200 (GMT)
Message-ID: <[email protected]>
Hi everyone.
`
//todo: not yet implemented in net/mail
//once there is support for this, add it
var rfc5322exampleA13 = `From: Pete <[email protected]>
Cc: Undisclosed recipients:;
Date: Thu, 13 Feb 1969 23:32:54 -0330
Message-ID: <[email protected]>
Testing.
`
//we skipped the first message bcause it's the same as A 1.1
var rfc5322exampleA2a = `From: Mary Smith <[email protected]>
To: John Doe <[email protected]>
Reply-To: "Mary Smith: Personal Account" <[email protected]>
Subject: Re: Saying Hello
Date: Fri, 21 Nov 1997 10:01:10 -0600
Message-ID: <[email protected]>
In-Reply-To: <[email protected]>
References: <[email protected]>
This is a reply to your hello.
`
var rfc5322exampleA2b = `To: "Mary Smith: Personal Account" <[email protected]>
From: John Doe <[email protected]>
Subject: Re: Saying Hello
Date: Fri, 21 Nov 1997 11:00:00 -0600
Message-ID: <[email protected]>
In-Reply-To: <[email protected]>
References: <[email protected]> <[email protected]>
This is a reply to your reply.
`
var rfc5322exampleA3 = `Resent-From: Mary Smith <[email protected]>
Resent-To: Jane Brown <[email protected]>
Resent-Date: Mon, 24 Nov 1997 14:22:01 -0800
Resent-Message-ID: <[email protected]>
From: John Doe <[email protected]>
To: Mary Smith <[email protected]>
Subject: Saying Hello
Date: Fri, 21 Nov 1997 09:55:06 -0600
Message-ID: <[email protected]>
This is a message just to say hello.
So, "Hello".`
var rfc5322exampleA4 = `Received: from x.y.test
by example.net
via TCP
with ESMTP
id ABC12345
for <[email protected]>; 21 Nov 1997 10:05:43 -0600
Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 -0600
From: John Doe <[email protected]>
To: Mary Smith <[email protected]>
Subject: Saying Hello
Date: Fri, 21 Nov 1997 09:55:06 -0600
Message-ID: <[email protected]>
This is a message just to say hello.
So, "Hello".`
var imageContentExample = `From: John Doe <[email protected]>
Sender: Michael Jones <[email protected]>
To: Mary Smith <[email protected]>
Subject: Saying Hello
Date: Fri, 21 Nov 1997 09:55:06 -0600
Message-ID: <[email protected]>
Content-Type: image/jpeg;
x-unix-mode=0644;
name="image.gif"
Content-Transfer-Encoding: base64
R0lGODlhAQE7`
var multipartRelatedExample = `MIME-Version: 1.0
From: John Doe <[email protected]>
Sender: Michael Jones <[email protected]>
To: Mary Smith <[email protected]>
Subject: Saying Hello
Date: Fri, 21 Nov 1997 09:55:06 -0600
Message-ID: <[email protected]>
Subject: ooops
Content-Type: multipart/related; boundary="000000000000ab2e2205a26de587"
--000000000000ab2e2205a26de587
Content-Type: multipart/alternative; boundary="000000000000ab2e1f05a26de586"
--000000000000ab2e1f05a26de586
Content-Type: text/plain; charset="UTF-8"
Time for the egg.
--000000000000ab2e1f05a26de586
Content-Type: text/html; charset="UTF-8"
<div dir="ltr"><div>Time for the egg.</div><div><br></div><div><br><br></div></div>
--000000000000ab2e1f05a26de586--
--000000000000ab2e2205a26de587--
`
var attachment7bit = `From: =?UTF-8?Q?Peter_Foobar?= <[email protected]>
Date: Tue, 2 Apr 2019 11:12:26 +0000
Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com>
Subject: =?UTF-8?Q?Peter_Foobar?=
Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf
--f403045f1dcc043a44054c8e6bbf
Content-Type: multipart/alternative; boundary=f403045f1dcc043a3f054c8e6bbd
--f403045f1dcc043a3f054c8e6bbd
Content-Type: text/plain; charset=UTF-8
--f403045f1dcc043a3f054c8e6bbd
Content-Type: text/html; charset=UTF-8
<div dir="ltr"><br></div>
--f403045f1dcc043a3f054c8e6bbd--
--f403045f1dcc043a44054c8e6bbf
Content-Type: application/csv;
name="unencoded.csv"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="unencoded.csv"
"Some", "Data", "In", "Csv", "Format"
"Foo", "Bar", "Baz", "Bum", "Poo"
--f403045f1dcc043a44054c8e6bbf--
`
var base64Content = `MIME-Version: 1.0
From: John Doe <[email protected]>
Sender: Michael Jones <[email protected]>
To: Mary Smith <[email protected]>
Subject: Saying Hello
Date: Fri, 21 Nov 1997 09:55:06 -0600
Message-ID: <[email protected]>
Content-Type: multipart/alternative; boundary="000000000000ab2e1f05a26de586"
--000000000000ab2e1f05a26de586
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64
8J+RjQo=
--000000000000ab2e1f05a26de586
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: base64
PGRpdiBkaXI9Imx0ciI+8J+RjTwvZGl2Pgo=
--000000000000ab2e1f05a26de586--
`