changeset: 6504:2dac9fa02842
user:      Kevin McCarthy <[email protected]>
date:      Sun Sep 06 16:31:57 2015 -0700
link:      http://dev.mutt.org/hg/mutt/rev/2dac9fa02842

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().

diffs (79 lines):

diff -r c6a6b7d3b83d -r 2dac9fa02842 imap/browse.c
--- a/imap/browse.c     Sun Sep 06 07:41:36 2015 -0700
+++ b/imap/browse.c     Sun Sep 06 16:31:57 2015 -0700
@@ -43,8 +43,8 @@
   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 @@
   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 @@
      * 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 @@
 
   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 @@
   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)
   {

Reply via email to