Skip to content

Commit

Permalink
fix(GODT-2201): Fix fetch parsing of body section parts without text
Browse files Browse the repository at this point in the history
  • Loading branch information
LBeernaertProton authored and jameshoulahan committed Feb 16, 2023
1 parent 169bd00 commit 5640ba1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
16 changes: 11 additions & 5 deletions imap/command/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,19 @@ func parseSectionSpec(p *rfcparser.Parser) (BodySection, error) {
return nil, err
}

// Note: trailing . is consumed by parserSectionPart().
text, err := parseSectionText(p)
if err != nil {
return nil, err
var textSection BodySection

if p.Check(rfcparser.TokenTypeChar) {
// Note: trailing . is consumed by parserSectionPart().
text, err := parseSectionText(p)
if err != nil {
return nil, err
}

textSection = text
}

return &BodySectionPart{Part: part, Section: text}, nil
return &BodySectionPart{Part: part, Section: textSection}, nil
}

return parseSectionMsgText(p)
Expand Down
20 changes: 20 additions & 0 deletions imap/command/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,26 @@ func TestParser_FetchCommandMultiple(t *testing.T) {
require.Equal(t, expected, cmd)
}

func TestParser_FetchCommandBodySectionPartOnly(t *testing.T) {
expected := Command{Tag: "A005", Payload: &Fetch{
SeqSet: []SeqRange{{Begin: 1, End: 1}},
Attributes: []FetchAttribute{
&FetchAttributeBodySection{
Section: &BodySectionPart{
Part: []int{1, 1},
Section: nil,
},
Peek: false,
Partial: nil,
},
},
}}

cmd, err := testParseCommand(`A005 FETCH 1 (BODY[1.1])`)
require.NoError(t, err)
require.Equal(t, expected, cmd)
}

func BenchmarkParser_Fetch(b *testing.B) {
input := toIMAPLine(`tag FETCH 2:4 (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY.PEEK[1.3.TEXT]<50.100>)`)

Expand Down

0 comments on commit 5640ba1

Please sign in to comment.