8func TestMessageIDCanonical(t *testing.T) {
9 check := func(s string, expID string, expRaw bool, expErr error) {
12 id, raw, err := MessageIDCanonical(s)
13 if id != expID || raw != expRaw || (expErr == nil) != (err == nil) || err != nil && !errors.Is(err, expErr) {
14 t.Fatalf("got message-id %q, raw %v, err %v, expected %q %v %v, for message-id %q", id, raw, err, expID, expRaw, expErr, s)
18 check("bogus", "", false, errBadMessageID)
19 check("<bogus@host", "", false, errBadMessageID)
20 check("bogus@host>", "", false, errBadMessageID)
21 check("<>", "", false, errBadMessageID)
22 check("<user@domain>", "user@domain", false, nil)
23 check("<USER@DOMAIN>", "user@domain", false, nil)
24 check("<user@[10.0.0.1]>", "user@[10.0.0.1]", true, nil)
25 check("<user@domain> (added by postmaster@isp.example)", "user@domain", false, nil)
26 check("<user@domain> other", "user@domain", false, nil)
27 check("<User@Domain@Time>", "user@domain@time", true, nil)
28 check("<User>", "user", true, nil)