Fixed a bug when using an empty name in SetAddressHeader

Fixes #54
This commit is contained in:
Alexandre Cesaro 2016-03-20 17:20:50 +01:00
parent 060a5f4e98
commit 84856b343c
2 changed files with 16 additions and 0 deletions

View File

@ -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('"')

View File

@ -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{