Skip to content

Commit 746087b

Browse files
LBeernaertProtonemersion
authored andcommitted
Fix FETCH command with ALL, FAST and FULL macro as fetch items
When using one of the macros as fetch item arguments, the IMAP command written to the socket would wrap the macro in parentheses, which is not valid. To address this we check whether there is only one item in the fetch list and if it matches on of the macros we make sure it's serialized in way that does not wrap it in parentheses.
1 parent cc99410 commit 746087b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

commands/fetch.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@ type Fetch struct {
1414
}
1515

1616
func (cmd *Fetch) Command() *imap.Command {
17-
items := make([]interface{}, len(cmd.Items))
18-
for i, item := range cmd.Items {
19-
items[i] = imap.RawString(item)
20-
}
17+
// Handle FETCH macros separately as they should not be serialized within parentheses
18+
if len(cmd.Items) == 1 && (cmd.Items[0] == imap.FetchAll || cmd.Items[0] == imap.FetchFast || cmd.Items[0] == imap.FetchFull) {
19+
return &imap.Command{
20+
Name: "FETCH",
21+
Arguments: []interface{}{cmd.SeqSet, imap.RawString(cmd.Items[0])},
22+
}
23+
} else {
24+
items := make([]interface{}, len(cmd.Items))
25+
for i, item := range cmd.Items {
26+
items[i] = imap.RawString(item)
27+
}
2128

22-
return &imap.Command{
23-
Name: "FETCH",
24-
Arguments: []interface{}{cmd.SeqSet, items},
29+
return &imap.Command{
30+
Name: "FETCH",
31+
Arguments: []interface{}{cmd.SeqSet, items},
32+
}
2533
}
2634
}
2735

0 commit comments

Comments
 (0)