1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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;
});
|