go-imap icon indicating copy to clipboard operation
go-imap copied to clipboard

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

Open uuthink opened this issue 2 years ago • 4 comments

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 == '('
}

uuthink avatar Dec 14 '23 03:12 uuthink

Seems similar to https://github.com/emersion/go-imap/issues/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.

emersion avatar Dec 14 '23 10:12 emersion

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?

uuthink avatar Dec 19 '23 08:12 uuthink

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

emersion avatar Dec 19 '23 08:12 emersion

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

duesee avatar Jan 22 '24 11:01 duesee

For reference, cc @duesee

imap.exmail.qq.com sends:

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

smtp-n.global-mail.cn sends:

* SEARCH<SP><CRLF>

emersion avatar Mar 06 '24 11:03 emersion

Fixed in https://github.com/emersion/go-imap/pull/596

emersion avatar Mar 06 '24 12:03 emersion