Bug 1156669 - Trash folder duplication while using IMAP with localized TB, r=neil, a=rkent
authorR Kent James <rkent@caspia.com>
Wed, 06 May 2015 16:38:07 -0700
changeset 25914 2ed97196ca01800c2b0b6f35519415e728e0abb4
parent 25913 52cb7271bb32bfe922548fb92c5a02fbd0750d21
child 25915 f70c422c7904fddaac456c2787b342bbca964401
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil, rkent
bugs1156669
Bug 1156669 - Trash folder duplication while using IMAP with localized TB, r=neil, a=rkent
mailnews/imap/src/nsImapIncomingServer.cpp
--- a/mailnews/imap/src/nsImapIncomingServer.cpp
+++ b/mailnews/imap/src/nsImapIncomingServer.cpp
@@ -348,16 +348,18 @@ nsImapIncomingServer::SetDeleteModel(int
     nsresult rv = GetTrashFolderName(trashFolderName);
     if (NS_SUCCEEDED(rv))
     {
       nsAutoCString trashFolderNameUtf7;
       rv = CopyUTF16toMUTF7(trashFolderName, trashFolderNameUtf7);
       if (NS_SUCCEEDED(rv))
       {
         nsCOMPtr<nsIMsgFolder> trashFolder;
+        // XXX GetFolder only returns folders one level below root.
+        //     trashFolderName is a leaf name. So this will not find INBOX.Trash
         rv = GetFolder(trashFolderNameUtf7, getter_AddRefs(trashFolder));
         NS_ENSURE_SUCCESS(rv, rv);
         nsCString trashURI;
         trashFolder->GetURI(trashURI);
         GetMsgFolderFromURI(trashFolder, trashURI, getter_AddRefs(trashFolder));
         if (NS_SUCCEEDED(rv) && trashFolder)
         {
            // If the trash folder is used, set the flag, otherwise clear it.
@@ -1548,27 +1550,36 @@ NS_IMETHODIMP nsImapIncomingServer::Disc
               imapFolder->GetBoxFlags(&boxFlags);
               if (boxFlags & kImapXListTrash)
               {
                 continue;
               }
             }
             else
             {
-              nsAutoString folderName;
-              if (NS_FAILED(trashFolder->GetName(folderName)) ||
-                  folderName.Equals(trashName))
+              // trashName is the leaf name on the folder URI, which will be
+              // different from the folder GetName if the trash name is
+              // localized.
+              nsAutoCString trashURL;
+              trashFolder->GetFolderURL(trashURL);
+              int32_t leafPos = trashURL.RFindChar('/');
+              nsAutoCString unescapedName;
+              MsgUnescapeString(Substring(trashURL, leafPos + 1),
+                                nsINetUtil::ESCAPE_URL_PATH, unescapedName);
+              nsAutoString nameUnicode;
+              if (NS_FAILED(CopyMUTF7toUTF16(unescapedName, nameUnicode)) ||
+                  trashName.Equals(nameUnicode))
               {
                 continue;
               }
               if (numFolders == 1)
               {
                 // We got here because the preferred trash folder does not
                 // exist, but a folder got discovered to be the trash folder.
-                SetUnicharValue(PREF_TRASH_FOLDER_NAME, folderName);
+                SetUnicharValue(PREF_TRASH_FOLDER_NAME, nameUnicode);
                 continue;
               }
             }
             trashFolder->ClearFlag(nsMsgFolderFlags::Trash);
           }
         }
       }
     }