1package webmail
2
3import (
4 "strings"
5 "testing"
6
7 "github.com/mjl-/mox/dns"
8)
9
10func TestFormatFirstLine(t *testing.T) {
11 check := func(body, expLine string) {
12 t.Helper()
13
14 line, err := formatFirstLine(strings.NewReader(body))
15 tcompare(t, err, nil)
16 if line != expLine {
17 t.Fatalf("got %q, expected %q, for body %q", line, expLine, body)
18 }
19 }
20
21 check("", "")
22 check("single line", "single line\n")
23 check("single line\n", "single line\n")
24 check("> quoted\n", "[...]\n")
25 check("> quoted\nresponse\n", "[...]\nresponse\n")
26 check("> quoted\n[...]\nresponse after author snip\n", "[...]\nresponse after author snip\n")
27 check("[...]\nresponse after author snip\n", "[...]\nresponse after author snip\n")
28 check("[…]\nresponse after author snip\n", "[…]\nresponse after author snip\n")
29 check(">> quoted0\n> quoted1\n>quoted2\n[...]\nresponse after author snip\n", "[...]\nresponse after author snip\n")
30 check(">quoted\n\n>quoted\ncoalesce line-separated quotes\n", "[...]\ncoalesce line-separated quotes\n")
31 check("On <date> <user> wrote:\n> hi\nresponse", "[...]\nresponse\n")
32 check("On <longdate>\n<user> wrote:\n> hi\nresponse", "[...]\nresponse\n")
33 check("> quote\nresponse\n--\nsignature\n", "[...]\nresponse\n")
34 check("> quote\nline1\nline2\nline3\n", "[...]\nline1\nline2\nline3\n")
35}
36
37func TestParseListPostAddress(t *testing.T) {
38 check := func(s string, exp *MessageAddress) {
39 t.Helper()
40 v := parseListPostAddress(s)
41 tcompare(t, v, exp)
42 }
43
44 check("<mailto:list@host.com>", &MessageAddress{User: "list", Domain: dns.Domain{ASCII: "host.com"}})
45 check("<mailto:moderator@host.com> (Postings are Moderated)", &MessageAddress{User: "moderator", Domain: dns.Domain{ASCII: "host.com"}})
46 check("<mailto:moderator@host.com?subject=list%20posting>", &MessageAddress{User: "moderator", Domain: dns.Domain{ASCII: "host.com"}})
47 check("NO (posting not allowed on this list)", nil)
48 check("<https://groups.google.com/group/golang-dev/post>, <mailto:golang-dev@googlegroups.com>", &MessageAddress{User: "golang-dev", Domain: dns.Domain{ASCII: "googlegroups.com"}})
49 check("", nil)
50}
51