From 84856b343c307d0d076818e93d6122b71591c4a7 Mon Sep 17 00:00:00 2001 From: Alexandre Cesaro Date: Sun, 20 Mar 2016 17:20:50 +0100 Subject: [PATCH] Fixed a bug when using an empty name in SetAddressHeader Fixes #54 --- message.go | 4 ++++ message_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) 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{