MCPcopy Create free account
hub / github.com/buggregator/server / TestParseAddresses

Function TestParseAddresses

modules/smtp/handler_test.go:224–259  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

222}
223
224func TestParseAddresses(t *testing.T) {
225 t.Run("name and email", func(t *testing.T) {
226 header := make(map[string][]string)
227 header["From"] = []string{"John Doe <john@example.com>"}
228 addrs := parseAddresses(header, "From")
229 if len(addrs) != 1 {
230 t.Fatalf("len = %d", len(addrs))
231 }
232 if addrs[0].Email != "john@example.com" {
233 t.Errorf("Email = %q", addrs[0].Email)
234 }
235 if addrs[0].Name != "John Doe" {
236 t.Errorf("Name = %q", addrs[0].Name)
237 }
238 })
239
240 t.Run("email only", func(t *testing.T) {
241 header := make(map[string][]string)
242 header["To"] = []string{"user@example.com"}
243 addrs := parseAddresses(header, "To")
244 if len(addrs) != 1 {
245 t.Fatalf("len = %d", len(addrs))
246 }
247 if addrs[0].Email != "user@example.com" {
248 t.Errorf("Email = %q", addrs[0].Email)
249 }
250 })
251
252 t.Run("empty header", func(t *testing.T) {
253 header := make(map[string][]string)
254 addrs := parseAddresses(header, "Missing")
255 if len(addrs) != 0 {
256 t.Errorf("expected empty, got %d", len(addrs))
257 }
258 })
259}
260
261func TestParseEmail_RFC2047Subject(t *testing.T) {
262 tests := []struct {

Callers

nothing calls this directly

Calls 2

parseAddressesFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected