Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion imap/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func tryParseAddressList(val string) []*mail.Address {
addr, err := rfc5322.ParseAddressList(val)
if err != nil {
logrus.WithError(err).Error("Failed to parse address")
return []*mail.Address{{Name: val}}
return nil // RFC3501 empty address list should return NIL
}

return addr
Expand Down
29 changes: 29 additions & 0 deletions imap/envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,32 @@ func TestEnvelope(t *testing.T) {

assert.Equal(t, "(\"Sat, 03 Apr 2021 15:13:53 +0000\" \"this is currently a draft\" ((NIL NIL \"somebody\" \"pm.me\")) ((NIL NIL \"somebody\" \"pm.me\")) ((NIL NIL \"somebody\" \"pm.me\")) ((\"Somebody\" NIL \"somebody\" \"pm.me\")) NIL NIL NIL \"<X9xiWTZnfxfC0wGLBI9t-WEJCOSO_pT67TjlDDKZxzs7TFRCvzCF8lCtqrflZ9n2Z8Ve3rhwYE-vzUGkgOJWaZK4VWMk_WbertE5uklqS8A=@pm.me>\")", envelope)
}

func TestEnvelopeEmptyAddressList(t *testing.T) {
t.Parallel()

for name, tc := range map[string]struct {
msg string
envelope string
}{
"empty To": {
msg: "From: a@b.com\r\nTo:\r\nSubject: test\r\n\r\nbody",
envelope: `(NIL "test" ((NIL NIL "a" "b.com")) ((NIL NIL "a" "b.com")) ((NIL NIL "a" "b.com")) NIL NIL NIL NIL NIL)`,
},
"empty Cc": {
msg: "From: a@b.com\r\nTo: x@y.com\r\nCc:\r\nSubject: test\r\n\r\nbody",
envelope: `(NIL "test" ((NIL NIL "a" "b.com")) ((NIL NIL "a" "b.com")) ((NIL NIL "a" "b.com")) ((NIL NIL "x" "y.com")) NIL NIL NIL NIL)`,
},
} {
t.Run(name, func(t *testing.T) {
t.Parallel()

header, err := rfc822.Parse([]byte(tc.msg)).ParseHeader()
require.NoError(t, err)

envelope, err := imap.Envelope(header)
require.NoError(t, err)
assert.Equal(t, tc.envelope, envelope)
})
}
}
4 changes: 4 additions & 0 deletions imap/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (c *paramList) addMap(writer parListWriter, v map[string]string) *paramList
}

func (c *paramList) addAddresses(writer parListWriter, v []*mail.Address) *paramList {
if len(v) == 0 {
return c.addString(writer, "")
}

c.onWrite(writer)

child := c.newChildList(writer)
Expand Down
Loading