Bug 332651

Summary: The "]" character is not accepted for the "astring" grammar rule
Product: [Unmaintained] trojita Reporter: Miguel <migtavares>
Component: IMAPAssignee: Trojita default assignee <trojita-bugs>
Status: RESOLVED FIXED    
Severity: major    
Priority: NOR    
Version: 0.4   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Miguel 2014-03-26 20:46:02 UTC
connectionError "<p>The IMAP server sent us a reply which we could not parse. This might either mean that there's a bug in Trojitá's code, or that the IMAP server you are connected to is broken. Please report this as a bug anyway. Here are the details:</p><p><b>UnexpectedHere</b>: Could not parse list: expected a list enclosed in (), but got something else instead</p><pre>* STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)

                        ^ here</pre>"

Reproducible: Always

Steps to Reproduce:
1. Connect to a IMAP server (using dovecot in localhost here)
2. Expand the tree folder with sub folders.

Actual Results:  
trojita opens a error window, connection to the imap server is lost (and will not be regained unless trojita is restarted).

Expected Results:  
Expansion of the folder tree.

The same IMAP server is working happily with claws, thunderbird and macos Mail App, so I think it's not a issue with it.

Trojita IMAP log (only the part when opening the folder):
===================================================
21:34:41.086 Imap::Mailbox::ListChildMailboxesTask Listing stuff below mailbox BEST Activated
21:34:41.087 >>> y26 LIST "" "BEST.%" RETURN (SUBSCRIBED CHILDREN STATUS (MESSAGES UNSEEN RECENT))␍␊
21:34:41.096 <<< * LIST (\Subscribed \HasNoChildren) "." BEST.[Trainers]␍␊
21:34:41.096 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊
21:34:41.096 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊
21:34:41.096 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊
21:34:41.097 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 44 more bytes)
21:34:41.097 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 98 more bytes)
21:34:41.097 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 150 more bytes)
21:34:41.097 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 208 more bytes)
21:34:41.097 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 265 more bytes)
21:34:41.097 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 325 more bytes)
21:34:41.097 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 386 more bytes)
21:34:41.097 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 450 more bytes)
21:34:41.097 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 505 more bytes)
21:34:41.098 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 563 more bytes)
21:34:41.098 <<< * STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"␍␊* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)␍␊* LIST (\
(+ 587 more bytes)
21:34:41.098 UnexpectedHere Could not parse list: expected a list enclosed in (), but got something else instead␊* STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)␍␊␊                        ^ here
21:34:41.098 Imap::Mailbox::ListChildMailboxesTask Listing stuff below mailbox BEST Failed: Asked to die
21:34:41.099 *** Connection killed.
===================================================
Comment 1 Miguel 2014-03-26 20:52:57 UTC
If it helps, here's the relevant part of a tcpdump -i lo port imap -A -l:
21:50:14.621602 IP 127.0.0.1.46709 > 127.0.0.1.imap: Flags [P.], seq 2349126418:2349126500, ack 2578692290, win 1058, options [nop,nop,TS val 404300889 ecr 404268342], length 82
E.....@.@............u.............".z.....
..$Y...6y7 LIST "" "BEST.%" RETURN (SUBSCRIBED CHILDREN STATUS (MESSAGES UNSEEN RECENT))

21:50:14.625943 IP 127.0.0.1.imap > 127.0.0.1.46709: Flags [P.], seq 1:844, ack 82, win 516, options [nop,nop,TS val 404300893 ecr 404300889], length 843
E....2@.@.`D...........u.......d.....t.....
..$]..$Y* LIST (\Subscribed \HasNoChildren) "." BEST.[Trainers]
* STATUS BEST.[Trainers] (MESSAGES 2025 RECENT 0 UNSEEN 0)
* LIST (\Subscribed \HasNoChildren) "." "BEST.[Carrer support]"
* STATUS "BEST.[Carrer support]" (MESSAGES 90 RECENT 0 UNSEEN 0)
* LIST (\Subscribed \HasNoChildren) "." BEST.Aveiro
* STATUS BEST.Aveiro (MESSAGES 22 RECENT 0 UNSEEN 0)
* LIST (\Subscribed \HasChildren) "." BEST.Coimbra
* STATUS BEST.Coimbra (MESSAGES 18348 RECENT 0 UNSEEN 0)
* LIST (\Subscribed \HasNoChildren) "." BEST.[Portugal]
* STATUS BEST.[Portugal] (MESSAGES 2838 RECENT 0 UNSEEN 0)
* LIST (\Subscribed \HasNoChildren) "." BEST.[TrainersHome]
* STATUS BEST.[TrainersHome] (MESSAGES 4440 RECENT 0 UNSEEN 0)
* LIST (\Subscribed \HasNoChildren) "." BEST.[alumni]
* STATUS BEST.[alumni] (MESSAGES 4049 RECENT 0 UNSEEN 0)
y7 OK List completed.

21:50:14.625969 IP 127.0.0.1.46709 > 127.0.0.1.imap: Flags [.], ack 844, win 1089, options [nop,nop,TS val 404300893 ecr 404300893], length 0
...A.(...............u.....d...
..$]..$]
21:50:14.686698 IP 127.0.0.1.46709 > 127.0.0.1.imap: Flags [P.], seq 82:93, ack 844, win 1089, options [nop,nop,TS val 404300954 ecr 404300893], length 11
...A.3...............u.....d...
..$...$]y8 LOGOUT

21:50:14.687072 IP 127.0.0.1.imap > 127.0.0.1.46709: Flags [P.], seq 844:888, ack 93, win 516, options [nop,nop,TS val 404300954 ecr 404300954], length 44
...o.....T.............u...
..$...$.* BYE Logging out
y8 OK Logout completed.

21:50:14.687091 IP 127.0.0.1.46709 > 127.0.0.1.imap: Flags [.], ack 888, win 1089, options [nop,nop,TS val 404300954 ecr 404300954], length 0
E..4..@.@............u.....o...9...A.(.....
..$...$.
21:50:14.687327 IP 127.0.0.1.imap > 127.0.0.1.46709: Flags [F.], seq 888, ack 93, win 516, options [nop,nop,TS val 404300954 ecr 404300954], length 0
E..4.4@.@.c............u...9...o.....(.....
..$...$.
21:50:14.696904 IP 127.0.0.1.46709 > 127.0.0.1.imap: Flags [F.], seq 93, ack 889, win 1089, options [nop,nop,TS val 404300964 ecr 404300954], length 0
E..4..@.@............u.....o...:...A.(.....
..$...$.
21:50:14.696927 IP 127.0.0.1.imap > 127.0.0.1.46709: Flags [.], ack 94, win 516, options [nop,nop,TS val 404300964 ecr 404300964], length 0
E..4.5@.@.c............u...:...p.....(.....
..$...$.
Comment 2 Jan Kundrát 2014-03-26 22:31:23 UTC
What version of Dovecot is this? The "]" character is forbidden to be sent using the atom syntax as per RFC 3501, so it seems that the bug is in Dovecot in this case.
Comment 3 Jan Kundrát 2014-03-26 23:05:21 UTC
Oops, I got confused because of the ATOM-CHAR = <any CHAR except atom-specials> rule. The "]" character is explicitly allowed in an "astring" via the resp-specials production.
Comment 4 Jan Kundrát 2014-03-26 23:18:15 UTC
Patch under review at https://git.reviewboard.kde.org/r/117105/ .
Comment 5 Miguel 2014-03-27 07:33:12 UTC
dovecot version: 2.2.9
Nice to see a patch show up so fast. Thx.
Comment 6 Miguel 2014-03-27 10:05:58 UTC
Tried the fix proposed and it works.
Comment 7 Jan Kundrát 2014-03-27 10:29:01 UTC
Git commit 8c1a01e97e82f0e3db221c05cc4ae5c1e4cc2dc8 by Jan Kundrát.
Committed on 26/03/2014 at 23:12.
Pushed by jkt into branch 'master'.

IMAP: allow ']' when parsing an astring

The IMAP code would by mistake reject tokens that contain a resp-special
character ']' when asked for parsing astrings. This was because the of the rule:

    ATOM-CHAR       = <any CHAR except atom-specials> rule

...which confused me enough so that I ignored an explicit allowance for the
resp-specials earlier in the ASTRING-CHAR rule.

Thanks to Miguel <migtavares@gmail.com> (DeviantPeer on IRC) for reporting this.
Sorry for the trouble.
REVIEW: 117105

M  +26   -3    src/Imap/Parser/LowLevelParser.cpp
M  +1    -0    src/Imap/Parser/LowLevelParser.h
M  +21   -0    tests/Imap/test_Imap_LowLevelParser.cpp

http://commits.kde.org/trojita/8c1a01e97e82f0e3db221c05cc4ae5c1e4cc2dc8