-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmime_test.go
115 lines (109 loc) · 3.69 KB
/
mime_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
package marcel
import (
"bytes"
"net/mail"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMime(t *testing.T) {
data := strings.NewReader("oh hi I am an attachment")
moreData := strings.NewReader("oh hi I am another totally different attachment")
testEmails := []Email{
Email{
To: "[email protected]",
From: "[email protected]",
ReplyTo: "[email protected]",
Text: "this is the text part of a test run",
HTML: "this <i>is the HTML part of a test</i> run",
Subject: "attachment test run",
Attachments: []Attachment{
Attachment{
ContentType: "text/plain",
Data: data,
Filename: "test_data.txt",
},
Attachment{
ContentType: "text/plain",
Data: moreData,
Filename: "more_test_data.txt",
},
},
},
Email{
To: "[email protected]",
From: "[email protected]",
ReplyTo: "[email protected]",
Text: "this is the text part of a test run",
HTML: "this <i>is the HTML part of a test</i> run",
Subject: "alternative test run",
},
Email{
To: "[email protected]",
From: "[email protected]",
ReplyTo: "[email protected]",
Text: "this is the text part of a test run",
HTML: "this <i>is the <b>HTML</b> part of a test</i> run. And it has LINKS <a href=\"https://google.com\">https://google.com</a>",
Subject: "rich html test run",
},
Email{
To: "[email protected]",
From: "[email protected]",
ReplyTo: "[email protected]",
Text: "this is the text, and only, part of a test run",
Subject: "text only test run",
},
Email{
To: "[email protected]",
From: "[email protected]",
ReplyTo: "[email protected]",
HTML: "this is the <i>html</i>, and only, part of a test run",
Subject: "html only test run",
},
Email{
To: "[email protected]",
From: "[email protected]",
ReplyTo: "[email protected]",
Text: "this is the text part of a test run",
HTML: "this is the <b>HTML</b> part of a test run",
Subject: "Non-ASCII subject - “–“ - test run",
},
Email{
To: "[email protected]",
From: "[email protected]",
ReplyTo: "[email protected]",
Text: "this is the text part of a test run",
HTML: "this is the <b>HTML</b> part of a test run",
Subject: "Long with non-ASCII - “–“ - test This is a seriously long subject line I mean it is just silly what a ridiculous length of string to put in a subject who would do a think like this it is a bloody outrage do you not know that the maximum length of a MIME header is 75 characters and there's all sorts of nonsense we need to do in order to support multiline headers in combination with encoded words so that non-ASCII characters are supported I mean have you even read rfc2047 20 times?",
},
Email{
To: "[email protected]",
From: "[email protected]",
ReplyTo: "[email protected]",
Text: "This contains weird non breaking spaces Dear [[",
HTML: "This contains weird non breaking spaces Dear [[",
Subject: "Text encodings are a pain in the bum.",
},
Email{
To: "[email protected]",
From: "[email protected]",
ReplyTo: "[email protected]",
Text: "this is the text part of a cutom header mail",
HTML: "this <i>is the HTML part of a custom header</i> run",
Subject: "custom header",
Headers: map[string]string{
"X-Auto-Response-Suppress": "AutoReply, OOF, RN, NRN",
},
},
}
for _, email := range testEmails {
result, err := email.ToMIME()
assert.Nil(t, err)
msg, err := mail.ReadMessage(bytes.NewBuffer(result))
assert.Nil(t, err)
for k, v := range email.Headers {
val := msg.Header.Get(k)
assert.Equal(t, v, val)
}
}
}