1package message
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestReferencedIDs(t *testing.T) {
9 check := func(msg string, expRefs []string) {
10 t.Helper()
11
12 p, err := Parse(pkglog.Logger, true, strings.NewReader(msg))
13 tcheck(t, err, "parsing message")
14
15 h, err := p.Header()
16 tcheck(t, err, "parsing header")
17
18 refs, err := ReferencedIDs(h["References"], h["In-Reply-To"])
19 tcheck(t, err, "parsing references/in-reply-to")
20 tcompare(t, refs, expRefs)
21 }
22
23 check("References: bogus\r\n", nil)
24 check("References: <User@host>\r\n", []string{"user@host"})
25 check("References: <User@tést.example>\r\n", []string{"user@tést.example"})
26 check("References: <User@xn--tst-bma.example>\r\n", []string{"user@xn--tst-bma.example"})
27 check("References: <User@bad_label.domain>\r\n", []string{"user@bad_label.domain"})
28 check("References: <truncated@hos <user@host>\r\n", []string{"user@host"})
29 check("References: <previously wrapped@host>\r\n", []string{"previouslywrapped@host"})
30 check("References: <user1@host> <user2@other.example>\r\n", []string{"user1@host", "user2@other.example"})
31 check("References: <missinghost>\r\n", []string{"missinghost"})
32 check("References: <user@host@time>\r\n", []string{"user@host@time"})
33 check("References: bogus bad <user@host>\r\n", []string{"user@host"})
34 check("In-Reply-To: <user@host> more stuff\r\nReferences: bogus bad\r\n", []string{"user@host"})
35}
36