fix creating of new local archive folders, 473373, r/sr=standard8
authorDavid Bienvenu <bienvenu@nventure.com>
Fri, 16 Jan 2009 08:48:46 -0800
changeset 1660 339a8dd61afc205790f6ce5c1837b40efd51d006
parent 1659 926804509a09fa3cfeac157bae7163d1b8151242
child 1661 079d27d702c731553c4f062f59e26d0c63b09ff4
push idunknown
push userunknown
push dateunknown
bugs473373
fix creating of new local archive folders, 473373, r/sr=standard8
mail/base/content/mailWindowOverlay.js
mailnews/local/src/nsLocalMailFolder.cpp
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -1080,46 +1080,48 @@ BatchMessageMover.prototype = {
     for (let key in this._batches)
     {
       this._currentKey = key;
       let batch = this._batches[key];
       let srcFolder = batch[0];
       let msgYear = batch[1];
       let dstFolderName = batch[2];
       let msgs = batch.slice(3,batch.length);
-      let subfolder;
+      let subFolder, dstFolder;
 
       let archiveFolderUri =
         getIdentityForHeader(msgs[0], Components.interfaces.nsIMsgCompType.ReplyAll).archiveFolder;
 
       let archiveFolder = GetMsgFolderFromUri(archiveFolderUri, false);
+      // for imap folders, we need to create the sub-folders asynchronously, 
+      // so we chain the urls using the listener called back from 
+      // createStorageIfMissing. For local, creatStorageIfMissing is
+      // synchronous.
+      let isImap = archiveFolder.server.type == "imap";
       if (!archiveFolder.parent)
       {
         archiveFolder.createStorageIfMissing(this);
-        return;
+        if (isImap)
+          return;
       }
-      if (!archiveFolder.containsChildNamed(msgYear))
-      {
-        subfolder = archiveFolder.addSubfolder(msgYear);
-        subfolder.createStorageIfMissing(this);
-        return;
-      }
-      else
+      archiveFolderUri += "/" + msgYear;
+      subFolder = GetMsgFolderFromUri(archiveFolderUri, false);
+      if (!subFolder.parent)
       {
-        subfolder = archiveFolder.getChildNamed(msgYear);
+        subFolder.createStorageIfMissing(this);
+        if (isImap)
+          return;
       }
-      if (!subfolder.containsChildNamed(dstFolderName))
+      archiveFolderUri += "/" + dstFolderName;
+      dstFolder = GetMsgFolderFromUri(archiveFolderUri, false);
+      if (!dstFolder.parent)
       {
-        subfolder = subfolder.addSubfolder(dstFolderName);
-        subfolder.createStorageIfMissing(this);
-        return;
-      }
-      else
-      {
-        dstFolder = subfolder.getChildNamed(dstFolderName);
+        dstFolder.createStorageIfMissing(this);
+        if (isImap)
+          return;
       }
       var mutablearray = Components.classes["@mozilla.org/array;1"].createInstance(Components.interfaces.nsIMutableArray);
       msgs.forEach(function (item) {
         mutablearray.appendElement(item, false);
       });
       gCopyService.CopyMessages(srcFolder, mutablearray,
                                 dstFolder, true, this, msgWindow, true);
       this._currentKey = key;
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -692,16 +692,19 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Crea
     }
   }
 
   if (msgParent)
   {
     nsString folderName;
     GetName(folderName);
     rv = msgParent->CreateSubfolder(folderName, nsnull);
+    // by definition, this is OK.
+    if (rv == NS_MSG_FOLDER_EXISTS)
+      return NS_OK;
   }
   return rv;
 }
 
 NS_IMETHODIMP
 nsMsgLocalMailFolder::CreateSubfolder(const nsAString& folderName, nsIMsgWindow *msgWindow)
 {
   nsCOMPtr<nsIMsgFolder> newFolder;