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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* Test autosync date constraints
*/
var { MessageGenerator } = ChromeUtils.import(
"resource://testing-common/mailnews/MessageGenerator.jsm"
);
var { PromiseTestUtils } = ChromeUtils.import(
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
);
var gMsgImapInboxFolder;
// Adds some messages directly to a mailbox (eg new mail)
function addMessagesToServer(messages, mailbox) {
// Create the ImapMessages and store them on the mailbox
messages.forEach(function (message) {
let dataUri = "data:text/plain," + message.toMessageString();
mailbox.addMessage(new ImapMessage(dataUri, mailbox.uidnext++, []));
});
}
add_setup(function () {
Services.prefs.setIntPref("mail.server.server1.autosync_max_age_days", 4);
setupIMAPPump();
gMsgImapInboxFolder = IMAPPump.inbox.QueryInterface(Ci.nsIMsgImapMailFolder);
// these hacks are required because we've created the inbox before
// running initial folder discovery, and adding the folder bails
// out before we set it as verified online, so we bail out, and
// then remove the INBOX folder since it's not verified.
gMsgImapInboxFolder.hierarchyDelimiter = "/";
gMsgImapInboxFolder.verifiedAsOnlineFolder = true;
// Add a couple of messages to the INBOX
// this is synchronous, afaik
let messageGenerator = new MessageGenerator();
// build up a diverse list of messages
let messages = [];
messages = messages.concat(
messageGenerator.makeMessage({ age: { days: 2, hours: 1 } })
);
messages = messages.concat(
messageGenerator.makeMessage({ age: { days: 8, hours: 1 } })
);
messages = messages.concat(
messageGenerator.makeMessage({ age: { days: 10, hours: 1 } })
);
addMessagesToServer(messages, IMAPPump.daemon.getMailbox("INBOX"));
});
add_task(async function downloadForOffline() {
// ...and download for offline use.
// This downloads all messages, ignoring the autosync age constraints.
let listener = new PromiseTestUtils.PromiseUrlListener();
IMAPPump.inbox.downloadAllForOffline(listener, null);
await listener.promise;
});
add_task(function test_applyRetentionSettings() {
IMAPPump.inbox.applyRetentionSettings();
let enumerator = IMAPPump.inbox.msgDatabase.enumerateMessages();
if (enumerator) {
let now = new Date();
let dateInSeconds = now.getSeconds();
let cutOffDateInSeconds = dateInSeconds - 5 * 60 * 24;
for (let header of enumerator) {
if (header instanceof Ci.nsIMsgDBHdr) {
if (header.dateInSeconds < cutOffDateInSeconds) {
Assert.equal(header.getStringProperty("pendingRemoval"), "1");
} else {
Assert.equal(header.getStringProperty("pendingRemoval"), "");
}
}
}
}
});
add_task(function endTest() {
teardownIMAPPump();
});
|