diff --git a/message.go b/message.go index 4a3fd0e..8543811 100644 --- a/message.go +++ b/message.go @@ -127,6 +127,10 @@ func (m *Message) SetAddressHeader(field, address, name string) { // FormatAddress formats an address and a name as a valid RFC 5322 address. func (m *Message) FormatAddress(address, name string) string { + if name == "" { + return address + } + enc := m.encodeString(name) if enc == name { m.buf.WriteByte('"') diff --git a/message_test.go b/message_test.go index 9dc51fc..37aaa68 100644 --- a/message_test.go +++ b/message_test.go @@ -531,6 +531,18 @@ func TestBase64LineLength(t *testing.T) { testMessage(t, m, 0, want) } +func TestEmptyName(t *testing.T) { + m := NewMessage() + m.SetAddressHeader("From", "from@example.com", "") + + want := &message{ + from: "from@example.com", + content: "From: from@example.com\r\n", + } + + testMessage(t, m, 0, want) +} + func TestEmptyHeader(t *testing.T) { m := NewMessage() m.SetHeaders(map[string][]string{