From 6e90579f53b4bd93ccc208881a9cc9ca566f0fc0 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Tue, 23 Apr 2019 19:06:11 -0700 Subject: [PATCH] Add RECURSIVEMATCH LIST-EXTENDED selection option to query. LSUB is required to include mailboxes with subscribed children, but the just added "LIST (SUBSCRIBED)" by default does not do that. To match previous behavior, add RECURSIVEMATCH to make sure the children are included. Fix the parser to trim off the CHILDINFO suffix in the response. Parse \NonExistent LIST attribute the same as \NoSelect. --- imap/browse.c | 11 +++++------ imap/command.c | 25 ++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/imap/browse.c b/imap/browse.c index 8a2a9a6a..ab965803 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -46,7 +46,7 @@ int imap_browse (const char* path, struct browser_state* state) char buf[LONG_STRING*2]; char mbox[LONG_STRING]; char munged_mbox[LONG_STRING]; - char list_cmd[18]; + const char *list_cmd; int len; int n; int nsup; @@ -69,18 +69,17 @@ int imap_browse (const char* path, struct browser_state* state) if (option (OPTIMAPLSUB)) { - const char *lsub_cmd = "LSUB"; - /* RFC3348 section 3 states LSUB is unreliable for hierarchy information. * The newer LIST extensions are designed for this. */ if (mutt_bit_isset (idata->capabilities, LIST_EXTENDED)) - lsub_cmd = "LIST (SUBSCRIBED)"; - strfcpy (list_cmd, lsub_cmd, sizeof (list_cmd)); + list_cmd = "LIST (SUBSCRIBED RECURSIVEMATCH)"; + else + list_cmd = "LSUB"; } else { - strfcpy (list_cmd, "LIST", sizeof (list_cmd)); + list_cmd = "LIST"; } mutt_message _("Getting folder list..."); diff --git a/imap/command.c b/imap/command.c index 91457a11..a7b44712 100644 --- a/imap/command.c +++ b/imap/command.c @@ -928,10 +928,11 @@ static void cmd_parse_list (IMAP_DATA* idata, char* s) { if (!ascii_strncasecmp (s, "\\NoSelect", 9)) list->noselect = 1; + else if (!ascii_strncasecmp (s, "\\NonExistent", 12)) /* rfc5258 */ + list->noselect = 1; else if (!ascii_strncasecmp (s, "\\NoInferiors", 12)) list->noinferiors = 1; - /* See draft-gahrns-imap-child-mailbox-?? */ - else if (!ascii_strncasecmp (s, "\\HasNoChildren", 14)) + else if (!ascii_strncasecmp (s, "\\HasNoChildren", 14)) /* rfc5258*/ list->noinferiors = 1; s = imap_next_word (s); @@ -958,12 +959,30 @@ static void cmd_parse_list (IMAP_DATA* idata, char* s) idata->status = IMAP_FATAL; return; } + + if (strlen(idata->buf) < litlen) + { + dprint (1, (debugfile, "Error parsing LIST mailbox\n")); + return; + } + list->name = idata->buf; + s = list->name + litlen; + if (*s) + { + *s = '\0'; + s++; + SKIPWS(s); + } } else { - imap_unmunge_mbox_name (idata, s); list->name = s; + /* Exclude rfc5258 RECURSIVEMATCH CHILDINFO suffix */ + s = imap_next_word (s); + if (*s) + *(s - 1) = '\0'; + imap_unmunge_mbox_name (idata, list->name); } if (list->name[0] == '\0') -- 2.50.1