Skip to content
Open
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
4 changes: 2 additions & 2 deletions imapclient/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ func readBodyType1part(dec *imapwire.Decoder, typ string, options *Options) (*im
}

var description string
if !dec.ExpectSP() || !dec.ExpectNString(&bs.ID) || !dec.ExpectSP() || !dec.ExpectNString(&description) || !dec.ExpectSP() || !dec.ExpectNString(&bs.Encoding) || !dec.ExpectSP() || !dec.ExpectBodyFldOctets(&bs.Size) {
if !dec.ExpectSP() || !dec.ExpectNString(&bs.ID) || !dec.ExpectSP() || !dec.ExpectNStringWithDoubleQuoteCompat(&description) || !dec.ExpectSP() || !dec.ExpectNString(&bs.Encoding) || !dec.ExpectSP() || !dec.ExpectBodyFldOctets(&bs.Size) {
return nil, dec.Err()
}

Expand Down Expand Up @@ -1170,7 +1170,7 @@ func readBodyFldParam(dec *imapwire.Decoder, options *Options) (map[string]strin
)
err := dec.ExpectNList(func() error {
var s string
if !dec.ExpectString(&s) {
if !dec.ExpectStringWithDoubleQuoteCompat(&s) {
return dec.Err()
}

Expand Down
60 changes: 60 additions & 0 deletions internal/imapwire/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,46 @@ func (dec *Decoder) Quoted(ptr *string) bool {
return true
}

func (dec *Decoder) QuotedCompatDoubleQuote(ptr *string) bool {
if !dec.Special('"') {
return false
}
var sb strings.Builder
for {
ch, ok := dec.readByte()
if !ok {
return false
}

if ch == '"' {
if peekBytes, err := dec.r.Peek(2); err == nil {
allQuotes := true
for _, b := range peekBytes {
if b != '"' {
allQuotes = false
break
}
}
if allQuotes {
_, _ = dec.r.Discard(2)
}
}
break
}

if ch == '\\' {
ch, ok = dec.readByte()
if !ok {
return false
}
}

sb.WriteByte(ch)
}
*ptr = sb.String()
return true
}

func (dec *Decoder) ExpectAString(ptr *string) bool {
if dec.Quoted(ptr) {
return true
Expand All @@ -422,10 +462,18 @@ func (dec *Decoder) String(ptr *string) bool {
return dec.Quoted(ptr) || dec.Literal(ptr)
}

func (dec *Decoder) StringWithDoubleQuoteCompat(ptr *string) bool {
return dec.QuotedCompatDoubleQuote(ptr) || dec.Literal(ptr)
}

func (dec *Decoder) ExpectString(ptr *string) bool {
return dec.Expect(dec.String(ptr), "string")
}

func (dec *Decoder) ExpectStringWithDoubleQuoteCompat(ptr *string) bool {
return dec.Expect(dec.StringWithDoubleQuoteCompat(ptr), "string")
}

func (dec *Decoder) ExpectNString(ptr *string) bool {
var s string
if dec.Atom(&s) {
Expand All @@ -438,6 +486,18 @@ func (dec *Decoder) ExpectNString(ptr *string) bool {
return dec.ExpectString(ptr)
}

func (dec *Decoder) ExpectNStringWithDoubleQuoteCompat(ptr *string) bool {
var s string
if dec.Atom(&s) {
if !dec.Expect(s == "NIL", "nstring") {
return false
}
*ptr = ""
return true
}
return dec.ExpectStringWithDoubleQuoteCompat(ptr)
}

func (dec *Decoder) ExpectNStringReader() (lit *LiteralReader, nonSync, ok bool) {
var s string
if dec.Atom(&s) {
Expand Down