-
Notifications
You must be signed in to change notification settings - Fork 1
/
listinfo_test.go
88 lines (72 loc) · 2.51 KB
/
listinfo_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
package ulist
import (
"regexp"
"testing"
)
var messageIdPattern = regexp.MustCompile("[0-9a-z-_]{32}") // RFC5322 Message-Id compliant
func TestBounceAddress(t *testing.T) {
tests := []struct {
input ListInfo
expected string
}{
{ListInfo{1, Addr{Display: "", Local: `foo`, Domain: `example.com`}}, `[email protected]`},
{ListInfo{2, Addr{Display: "", Local: `foo.bar`, Domain: `example.com`}}, `[email protected]`}, // one dot is okay
{ListInfo{3, Addr{Display: "", Local: `foo..bar`, Domain: `example.com`}}, `"foo..bar+bounces"@example.com`}, // local-parts with consecutive dots must be quoted
{ListInfo{4, Addr{Display: "", Local: `foo bar`, Domain: `example.com`}}, `"foo bar+bounces"@example.com`}, // some characters are only allowed in quotes
{ListInfo{5, Addr{Display: "", Local: `foo@bar`, Domain: `example.com`}}, `"foo@bar+bounces"@example.com`}, // some characters are only allowed in quotes
{ListInfo{6, Addr{Display: "", Local: `"foo@bar"`, Domain: `example.com`}}, `"\"foo@bar\"+bounces"@example.com`}, // double quotes must be escaped
}
for _, test := range tests {
if result := test.input.BounceAddress(); result != test.expected {
t.Errorf("got %s, want %s", result, test.expected)
}
}
}
// we can't test the uniqueness across test runs here
func TestNewMessageId(t *testing.T) {
var li = &ListInfo{
1,
Addr{
Local: "list",
Domain: "example.com",
},
}
var gotPrev string
var want = "<[email protected]>"
for i := 0; i < 1000; i++ {
var got = li.NewMessageId()
if got == gotPrev {
t.Errorf("got previous, want different")
}
gotPrev = got
if got = messageIdPattern.ReplaceAllString(got, "message-id"); got != want {
t.Errorf("got %s, want %s", got, want)
}
}
}
func TestPrefixSubject(t *testing.T) {
list := &List{}
list.Display = "List"
tests := []struct {
input string
expected string
}{
{"", "[List] "},
{"Foo", "[List] Foo"},
{"Re: Foo", "[List] Re: Foo"},
{"[List] Foo", "[List] Foo"},
{"Re: FW: [List] Foo", "Re: FW: [List] Foo"},
{"[", "[List] ["},
{"Re: [", "[List] Re: ["},
{"[ <- Bracket", "[List] [ <- Bracket"},
{"Re: [ <- Bracket", "[List] Re: [ <- Bracket"},
{"[Bar] [List]", "[List] [Bar] [List]"},
{"Re: [Bar] [List]", "[List] Re: [Bar] [List]"},
{"=?UTF-8?Q?=5BList=5D_Hello?=", "[List] Hello"},
}
for _, test := range tests {
if result := list.PrefixSubject(test.input); result != test.expected {
t.Errorf("got %s, want %s", result, test.expected)
}
}
}