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 25996 62b5abd46440f9d83a6503c7b731a0f94aed85f3
parent 25995 7fc89b45e3fc4ae92f89b91b3f3bc7ed2cc88af8
child 25997 080b115a0f696dd115dfbf76bab5cc9f8209df5b
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);
           }
         }
       }
     }