Bug 1152651, copy multiple messages from maildir to maildir fails, r=neil, a=rkent
authorR Kent James <rkent@caspia.com>
Sun, 13 Sep 2015 20:41:11 -0700
changeset 26353 4b40a0f14dea36aa9f52d4e2e96d363d1da708ac
parent 26352 d65237cd6a9c24a5557ae40eb4a867a84bcfe389
child 26354 8f8ed2761bf70e9ca1708f49d2d4ce4651065ecb
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
bugs1152651
Bug 1152651, copy multiple messages from maildir to maildir fails, r=neil, a=rkent
mailnews/local/src/nsMsgMaildirStore.cpp
mailnews/local/test/unit/test_pop3MultiCopy.js
mailnews/local/test/unit/xpcshell.ini
mailnews/test/resources/POP3pump.js
--- a/mailnews/local/src/nsMsgMaildirStore.cpp
+++ b/mailnews/local/src/nsMsgMaildirStore.cpp
@@ -1044,17 +1044,17 @@ nsMsgMaildirStore::CopyMessages(bool aIs
       MOZ_LOG(MailDirLog, mozilla::LogLevel::Info,
              ("srcHdr null\n"));
       continue;
     }
     nsMsgKey srcKey;
     srcHdr->GetMessageKey(&srcKey);
     msgTxn->AddSrcKey(srcKey);
     nsAutoCString fileName;
-    msgHdr->GetStringProperty("storeToken", getter_Copies(fileName));
+    srcHdr->GetStringProperty("storeToken", getter_Copies(fileName));
     if (fileName.IsEmpty())
     {
       MOZ_LOG(MailDirLog, mozilla::LogLevel::Info,
              ("GetMsgInputStream - empty storeToken!!\n"));
       return NS_ERROR_FAILURE;
     }
 
     nsCOMPtr<nsIFile> srcFile;
new file mode 100644
--- /dev/null
+++ b/mailnews/local/test/unit/test_pop3MultiCopy.js
@@ -0,0 +1,95 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * This tests that copied multiple messages in maildir are correct.
+ */
+
+load("../../../resources/POP3pump.js");
+Components.utils.import("resource://gre/modules/Promise.jsm");
+Components.utils.import("resource://testing-common/mailnews/PromiseTestUtils.jsm");
+
+var testSubjects = ["[Bug 397009] A filter will let me tag, but not untag",
+                    "Hello, did you receive my bugmail?"];
+
+Services.prefs.setCharPref("mail.serverDefaultStoreContractID",
+                           "@mozilla.org/msgstore/maildirstore;1");
+
+add_task(function* runPump() {
+  // Test for multiple message copy for maildir.
+  let storeID = "@mozilla.org/msgstore/maildirstore;1";
+  gPOP3Pump.resetPluggableStore(storeID);
+  // Set the default mailbox store.
+  Services.prefs.setCharPref("mail.serverDefaultStoreContractID", storeID);
+
+  // We want to test cross-server copy, so don't defer.
+  gPOP3Pump.fakeServer.deferredToAccount = "";
+
+  gPOP3Pump.files = ["../../../data/bugmail1",
+                     "../../../data/draft1"];
+  yield gPOP3Pump.run();
+
+  // get message headers for the inbox folder
+  let inbox = gPOP3Pump.fakeServer
+                       .rootMsgFolder
+                       .getFolderWithFlags(Ci.nsMsgFolderFlags.Inbox);
+  dump("inbox is at " + inbox.filePath.path + "\n");
+
+  // Accumulate messages to copy.
+  let messages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
+  let enumerator = inbox.msgDatabase.EnumerateMessages();
+  let msgCount = 0;
+  while (enumerator.hasMoreElements()) {
+    msgCount++;
+    let hdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
+    messages.appendElement(hdr, false);
+    do_check_eq(hdr.subject, testSubjects[msgCount - 1]);
+  }
+  do_check_eq(messages.length, 2);
+
+  // Create a test folder on the Local Folders account.
+  let testFolder = localAccountUtils.rootFolder
+                                    .QueryInterface(Ci.nsIMsgLocalMailFolder)
+                                    .createLocalSubfolder("test");
+  dump("testFolder is at " + testFolder.filePath.path + "\n");
+
+  // Copy messages to that folder.
+  let promiseCopyListener = new PromiseTestUtils.PromiseCopyListener();
+  MailServices.copy.CopyMessages(inbox, messages, testFolder, false,
+                                 promiseCopyListener, null, false);
+  yield promiseCopyListener.promise;
+
+  // Check the destination headers.
+  messages.clear();
+  enumerator = testFolder.msgDatabase.EnumerateMessages();
+  msgCount = 0;
+  let subjects = [];
+  while (enumerator.hasMoreElements()) {
+    msgCount++;
+    let hdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
+    messages.appendElement(hdr, false);
+    dump("Subject: " + hdr.subject + "\n");
+    subjects.push(hdr.subject);
+  }
+  do_check_eq(messages.length, 2);
+
+  // Check for subjects. maildir order for messages may not match
+  // order for creation, hence the array.includes.
+  for (let subject of testSubjects) {
+    do_check_true(subjects.includes(subject));
+  }
+
+  // Make sure the body matches the message.
+  enumerator = testFolder.msgDatabase.EnumerateMessages();
+  while (enumerator.hasMoreElements()) {
+    let hdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
+    let body = mailTestUtils.loadMessageToString(testFolder, hdr);
+    do_check_true(body.indexOf(hdr.subject) >= 0);
+  }
+
+  gPOP3Pump = null;
+});
+
+function run_test() {
+  run_next_test();
+}
--- a/mailnews/local/test/unit/xpcshell.ini
+++ b/mailnews/local/test/unit/xpcshell.ini
@@ -24,16 +24,17 @@ requesttimeoutfactor = 2
 [test_pop3Download.js]
 [test_pop3DownloadTempFileHandling.js]
 [test_pop3Duplicates.js]
 [test_pop3FilterActions.js]
 [test_pop3GSSAPIFail.js]
 [test_pop3GetNewMail.js]
 [test_pop3MoveFilter.js]
 [test_pop3MoveFilter2.js]
+[test_pop3MultiCopy.js]
 [test_pop3Password.js]
 [test_pop3Password2.js]
 [test_pop3Password3.js]
 [test_pop3PasswordFailure.js]
 [test_pop3PasswordFailure2.js]
 [test_pop3PasswordFailure3.js]
 [test_pop3Pump.js]
 [test_pop3ServerBrokenCRAMDisconnect.js]
--- a/mailnews/test/resources/POP3pump.js
+++ b/mailnews/test/resources/POP3pump.js
@@ -189,18 +189,21 @@ POP3Pump.prototype._testNext = function 
     else
     {
       this._server.resetTest();
     }
 
     // Set up the test
     this._daemon.setMessages(thisFiles);
 
-    // Now get the mail
-    this._pop3Service.GetNewMail(null, this, localAccountUtils.inboxFolder,
+    // Now get the mail, get inbox in case it got un-deferred.
+    let inbox = this._incomingServer
+                    .rootMsgFolder
+                    .getFolderWithFlags(Ci.nsMsgFolderFlags.Inbox);
+    this._pop3Service.GetNewMail(null, this, inbox,
                                  this._incomingServer);
 
     this._server.performTest();
   } catch (e)
   {
     this._server.stop();
 
     do_throw(e);