Skip to content

Commit

Permalink
commands: fix Fetch BODY[0] formatted as a string
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Mar 31, 2019
1 parent 0e7ff7e commit b4a6ac9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
33 changes: 33 additions & 0 deletions client/cmd_selected_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,39 @@ func TestClient_Fetch_Partial(t *testing.T) {
}
}

func TestClient_Fetch_part(t *testing.T) {
c, s := newTestClient(t)
defer s.Close()

setClientState(c, imap.SelectedState, nil)

seqset, _ := imap.ParseSeqSet("1")
fields := []imap.FetchItem{imap.FetchItem("BODY.PEEK[1]")}

done := make(chan error, 1)
messages := make(chan *imap.Message, 1)
go func() {
done <- c.Fetch(seqset, fields, messages)
}()

tag, cmd := s.ScanCmd()
if cmd != "FETCH 1 (BODY.PEEK[1])" {
t.Fatalf("client sent command %v, want %v", cmd, "FETCH 1 (BODY.PEEK[1])")
}

s.WriteString("* 1 FETCH (BODY[1] {3}\r\n")
s.WriteString("Hey")
s.WriteString(")\r\n")

s.WriteString(tag + " OK FETCH completed\r\n")

if err := <-done; err != nil {
t.Fatalf("c.Fetch() = %v", err)
}

_ = <-messages
}

func TestClient_Fetch_Uid(t *testing.T) {
c, s := newTestClient(t)
defer s.Close()
Expand Down
6 changes: 1 addition & 5 deletions commands/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ type Fetch struct {
func (cmd *Fetch) Command() *imap.Command {
items := make([]interface{}, len(cmd.Items))
for i, item := range cmd.Items {
if section, err := imap.ParseBodySectionName(item); err == nil {
items[i] = section
} else {
items[i] = string(item)
}
items[i] = imap.Atom(item)
}

return &imap.Command{
Expand Down

0 comments on commit b4a6ac9

Please sign in to comment.