mxk/go-imap — pull request #1 by sgotti (2014-05-08 09:36:03+00:00)
Title: Fix parsing of not quoted mailbox names containing squared brackets returned by a LIST/LSUB command (like Dovecot does)

Hi,

I tried to fix the parsing of not quoted mailbox names containing squared brackets returned by a LIST/LSUB command (Dovecot has this behavior).
RFC 3501 says that a mailbox name can be a quotes string, literal string or a astring:

mailbox-list = "(" [mbx-list-flags] ")" SP
(DQUOTE QUOTED-CHAR DQUOTE / nil) SP mailbox

mailbox = "INBOX" / astring

astring = 1*ASTRING-CHAR / string

ASTRING-CHAR = ATOM-CHAR / resp-specials

ATOM-CHAR =

atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards /
quoted-specials / resp-specials

resp-specials = "]"

The actual fix detects if the response is a LIST/LSUB response and then expects exactly 4 fields. The last one is the mailbox name.
A new method parseAstring is added.
The parseFields method is changed to accept a space as a stop character.
A test is added.

Thanks!