emersion / go-imap

📥 An IMAP library for clients and servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v2: in capability-data: imapwire: expected atom, got \"\\r\""

uuthink opened this issue · comments

commented

Sometimes while fetching a mail with UIDFetch I get the following error:

Expected nil, but got: &errors.errorString{s:"in response-data: in capability-data: imapwire: expected atom, got \"\\r\""}

Here are the logs

* CAPABILITY IMAP4 IMAP4rev1 XLIST MOVE IDLE XAPPLEPUSHSERVICE NAMESPACE CHILDREN ID UIDPLUS 

I noticed that there is a space before the ending newline character

I try to modify the SP method to solve this problem. The modification is as follows. Is it correct?

func (dec *Decoder) SP() bool {
	if dec.acceptByte(' ') {
		if dec.CRLF() {
			dec.mustUnreadByte()
			return false
		}
		return true
	}

	// Special case: SP is optional if the next field is a parenthesized list
	b, ok := dec.readByte()
	if !ok {
		return false
	}
	dec.mustUnreadByte()
	return b == '('
}

Seems similar to #540

I'm worried about calling mustUnreadByte after CRLF though. I think I'd prefer peeking at the next byte and checking whether it's \r or \n.

commented

Thank you very much, I will using dec.r.Peek(1) to get the next byte and checking.
Is this a bug? or is it caused by not strictly following the RFC? and it will fix in the furture?

This is a server bug: they are not strictly following the RFC's grammar.

Hey @uuthink, can you say which server generated the CAPABILITY response with the trailing space?

For reference, cc @duesee

imap.exmail.qq.com sends:

* CAPABILITY IMAP4<SP>IMAP4rev1<SP><CRLF>

smtp-n.global-mail.cn sends:

* SEARCH<SP><CRLF>

Fixed in #596