dinhvh / libetpan

Mail Framework for C Language
www.etpan.org
Other
612 stars 284 forks source link

SELECT: parsing fails if FLAGS or PERMANENTFLAGS responses contain parentheses #438

Open InterLinked1 opened 1 year ago

InterLinked1 commented 1 year ago

Although probably atypical, it's not explicitly prohibited by the RFC for IMAP flags to contain parentheses. However, if a mailbox is selected and it contains flags that have an opening parenthesis in them (and possibly other characters), the function will return an error. Here's an example:

I'd never intentionally include parentheses in labels, but due to a bug in testing, I managed to add a malformed flag to a mailbox, and now I've basically made the mailbox permanently inaccessible to libetpan, since, to my knowledge, there is no way to remove flags from a mailbox (even if the messages with those flags are expunged). The mailbox would need to be deleted, after all messages are moved to another one. Unfortunately, this happened on an INBOX, so I can't do that; therefore, I think it is a somewhat high severity issue.

[2023-07-21 16:03:07.735]   DEBUG[64389]: imap_client.c:425 __imap_client_send_wait_response: => 28 SELECT "INBOX"
[2023-07-21 16:03:07.766]   DEBUG[64389]: imap_client.c:354 client_command_passthru: <= * 197 EXISTS
[2023-07-21 16:03:07.767]   DEBUG[64389]: imap_client.c:354 client_command_passthru: <= * 2 RECENT
[2023-07-21 16:03:07.767]   DEBUG[64389]: imap_client.c:354 client_command_passthru: <= * OK [UIDNEXT 249] Predicted next UID
[2023-07-21 16:03:07.770]   DEBUG[64389]: imap_client.c:354 client_command_passthru: <= * OK [UNSEEN 134] Found
[2023-07-21 16:03:07.770]   DEBUG[64389]: imap_client.c:354 client_command_passthru: <= * OK [HIGHESTMODSEQ 998] Highest
[2023-07-21 16:03:07.770]   DEBUG[64389]: imap_client.c:354 client_command_passthru: <= * OK [UIDVALIDITY 674612150] UIDs valid
[2023-07-21 16:03:07.770]   DEBUG[64389]: imap_client.c:354 client_command_passthru: <= * FLAGS (\Answered \Deleted \Draft \Flagged \Seen (\Seen nonjunk $label1 FLAGS)
[2023-07-21 16:03:07.771]   DEBUG[64389]: imap_client.c:354 client_command_passthru: <= * OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen (\Seen nonjunk $label1 FLAGS \*)] F
[2023-07-21 16:03:07.771]   DEBUG[64389]: imap_client.c:358 client_command_passthru: <= 28 OK [READ-WRITE] SELECT
[2023-07-21 16:03:07.807] WARNING[64388]: mod_webmail.c:946 client_imap_select: SELECT 'XXXX.INBOX' failed: connect