From: Kevin McCarthy Date: Sun, 6 Sep 2015 23:31:57 +0000 (-0700) Subject: Fix double-decode during IMAP browse. X-Git-Tag: mutt-1-6-rel~95 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7dcc4f7999212da689537f70229b1b279a00d276;p=mutt Fix double-decode during IMAP browse. cmd_parse_list() already calls imap_unmunge_mbox_name() on the mailbox names returned from the server. However, browse_add_list_result() was taking those mailbox names and passing them to imap_add_folder(), which was calling imap_unmunge_mbox_name() yet again. The reason is that imap_browse() was directly calling imap_add_folder() too, passing in a previously encoded "mbox" name. After looking carefully at the code, I could find no reason that mbox needed to be encoded outside of the LIST commands.. Therefore I changed imap_browse() to call imap_munge_mbox_name() on mbox for the two LIST commands generated from it instead, and removed the imap_unmunge_mbox_name() call inside imap_add_folder(). --- diff --git a/imap/browse.c b/imap/browse.c index 2cd091dd..6050f283 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -43,8 +43,8 @@ int imap_browse (char* path, struct browser_state* state) IMAP_DATA* idata; IMAP_LIST list; char buf[LONG_STRING]; - char buf2[LONG_STRING]; char mbox[LONG_STRING]; + char munged_mbox[LONG_STRING]; char list_cmd[5]; int n; int nsup; @@ -72,13 +72,7 @@ int imap_browse (char* path, struct browser_state* state) if (mx.mbox && mx.mbox[0] != '\0') { int rc; - char *ptr; imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox)); - ptr = safe_strdup (mbox); - imap_utf_encode (idata, &ptr); - mbox[sizeof (mbox) - 1] = '\0'; - strncpy (mbox, ptr, sizeof (mbox) - 1); - FREE (&ptr); n = mutt_strlen (mbox); dprint (3, (debugfile, "imap_browse: mbox: %s\n", mbox)); @@ -87,7 +81,8 @@ int imap_browse (char* path, struct browser_state* state) * aren't already going to */ if (mbox[n-1] != idata->delim) { - snprintf (buf, sizeof (buf), "%s \"\" \"%s\"", list_cmd, mbox); + imap_munge_mbox_name (idata, munged_mbox, sizeof (munged_mbox), mbox); + snprintf (buf, sizeof (buf), "%s \"\" %s", list_cmd, munged_mbox); imap_cmd_start (idata, buf); idata->cmdtype = IMAP_CT_LIST; idata->cmddata = &list; @@ -180,9 +175,9 @@ int imap_browse (char* path, struct browser_state* state) dprint (3, (debugfile, "imap_browse: Quoting mailbox scan: %s -> ", mbox)); snprintf (buf, sizeof (buf), "%s%%", mbox); - imap_quote_string (buf2, sizeof (buf2), buf); - dprint (3, (debugfile, "%s\n", buf2)); - snprintf (buf, sizeof (buf), "%s \"\" %s", list_cmd, buf2); + imap_munge_mbox_name (idata, munged_mbox, sizeof (munged_mbox), buf); + dprint (3, (debugfile, "%s\n", munged_mbox)); + snprintf (buf, sizeof (buf), "%s \"\" %s", list_cmd, munged_mbox); if (browse_add_list_result (idata, buf, state, 0)) goto fail; @@ -392,22 +387,21 @@ static int browse_add_list_result (IMAP_DATA* idata, const char* cmd, return rc == IMAP_CMD_OK ? 0 : -1; } -/* imap_add_folder: add a folder name to the browser list, formatting it as - * necessary. */ +/* imap_add_folder: + * add a folder name to the browser list, formatting it as necessary. + * + * The folder parameter should already be 'unmunged' via + * imap_unmunge_mbox_name(). + */ static void imap_add_folder (char delim, char *folder, int noselect, int noinferiors, struct browser_state *state, short isparent) { char tmp[LONG_STRING]; char relpath[LONG_STRING]; IMAP_MBOX mx; - IMAP_DATA* idata; if (imap_parse_path (state->folder, &mx)) return; - if (!(idata = imap_conn_find (&(mx.account), 0))) - return; - - imap_unmunge_mbox_name (idata, folder); if (state->entrylen + 1 == state->entrymax) {