Skip to content

Commit d83e8e9

Browse files
committed
imapserver: fix encoding ESEARCH response with no result
1 parent 058b429 commit d83e8e9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

imapserver/search.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ func (c *Conn) writeESearch(tag string, data *imap.SearchData, options *imap.Sea
103103
if data.UID {
104104
enc.SP().Atom("UID")
105105
}
106-
if options.ReturnAll && data.All != nil {
106+
// When there is no result, we need to send an ESEARCH response with no ALL
107+
// keyword
108+
if options.ReturnAll && !isNumSetEmpty(data.All) {
107109
enc.SP().Atom("ALL").SP().NumSet(data.All)
108110
}
109111
if options.ReturnMin && data.Min > 0 {
@@ -118,6 +120,17 @@ func (c *Conn) writeESearch(tag string, data *imap.SearchData, options *imap.Sea
118120
return enc.CRLF()
119121
}
120122

123+
func isNumSetEmpty(numSet imap.NumSet) bool {
124+
switch numSet := numSet.(type) {
125+
case imap.SeqSet:
126+
return len(numSet) == 0
127+
case imap.UIDSet:
128+
return len(numSet) == 0
129+
default:
130+
panic("unknown imap.NumSet type")
131+
}
132+
}
133+
121134
func (c *Conn) writeSearch(numSet imap.NumSet) error {
122135
enc := newResponseEncoder(c)
123136
defer enc.end()

0 commit comments

Comments
 (0)