Files

62 lines
1.4 KiB
Go

package mailparser_test
import (
"reflect"
"testing"
)
func TestBCCAddresses(t *testing.T) {
tests := []struct {
name string
headers string
want []string
}{
{
name: "missing",
headers: "",
want: nil,
},
{
name: "single",
headers: "Bcc: alice@example.com\r\n",
want: []string{"alice@example.com"},
},
{
name: "multiple with display names, lowercased and deduplicated",
headers: "Bcc: Alice <Alice@Example.com>, bob@example.com, ALICE@example.com\r\n",
want: []string{"alice@example.com", "bob@example.com"},
},
{
name: "unparseable yields nothing",
headers: "Bcc: not an address <<<\r\n",
want: nil,
},
{
name: "empty header",
headers: "Bcc: \r\n",
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pm := parseHeaders(t, tt.headers)
if !reflect.DeepEqual(pm.BCC, tt.want) {
t.Errorf("BCC = %#v, want %#v", pm.BCC, tt.want)
}
})
}
}
func TestBCCDoesNotAffectToCC(t *testing.T) {
pm := parseHeaders(t, "Cc: erin@example.com\r\nBcc: frank@example.com\r\n")
if !reflect.DeepEqual(pm.To, []string{"dave@example.org"}) {
t.Errorf("To = %#v", pm.To)
}
if !reflect.DeepEqual(pm.CC, []string{"erin@example.com"}) {
t.Errorf("CC = %#v", pm.CC)
}
if !reflect.DeepEqual(pm.BCC, []string{"frank@example.com"}) {
t.Errorf("BCC = %#v", pm.BCC)
}
}