diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/local/test/unit/test_pop3MultiCopy.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/local/test/unit/test_pop3MultiCopy.js')
-rw-r--r-- | comm/mailnews/local/test/unit/test_pop3MultiCopy.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/comm/mailnews/local/test/unit/test_pop3MultiCopy.js b/comm/mailnews/local/test/unit/test_pop3MultiCopy.js new file mode 100644 index 0000000000..42a0f67e23 --- /dev/null +++ b/comm/mailnews/local/test/unit/test_pop3MultiCopy.js @@ -0,0 +1,97 @@ +/* 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. + */ + +/* import-globals-from ../../../test/resources/POP3pump.js */ +load("../../../resources/POP3pump.js"); +const { PromiseTestUtils } = ChromeUtils.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(async 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"]; + await 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 = []; + let msgCount = 0; + for (let hdr of inbox.msgDatabase.enumerateMessages()) { + msgCount++; + messages.push(hdr); + Assert.equal(hdr.subject, testSubjects[msgCount - 1]); + } + Assert.equal(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 + ); + await promiseCopyListener.promise; + + // Check the destination headers. + messages = []; + msgCount = 0; + let subjects = []; + for (let hdr of testFolder.msgDatabase.enumerateMessages()) { + msgCount++; + messages.push(hdr); + dump("Subject: " + hdr.subject + "\n"); + subjects.push(hdr.subject); + } + Assert.equal(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) { + Assert.ok(subjects.includes(subject)); + } + + // Make sure the body matches the message. + for (let hdr of testFolder.msgDatabase.enumerateMessages()) { + let body = mailTestUtils.loadMessageToString(testFolder, hdr); + Assert.ok(body.includes(hdr.subject)); + } + + gPOP3Pump = null; +}); |