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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that IMAP over a SOCKS proxy works.
var { NetworkTestUtils } = ChromeUtils.import(
"resource://testing-common/mailnews/NetworkTestUtils.jsm"
);
var { PromiseTestUtils } = ChromeUtils.import(
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
);
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
load("../../../resources/MessageGenerator.jsm");
var server, daemon, incomingServer;
const PORT = 143;
add_setup(async function () {
// Disable new mail notifications
Services.prefs.setBoolPref("mail.biff.play_sound", false);
Services.prefs.setBoolPref("mail.biff.show_alert", false);
Services.prefs.setBoolPref("mail.biff.show_tray_icon", false);
Services.prefs.setBoolPref("mail.biff.animate_dock_icon", false);
daemon = new ImapDaemon();
server = makeServer(daemon, "");
let messages = [];
let messageGenerator = new MessageGenerator();
messages = messages.concat(messageGenerator.makeMessage());
let dataUri = Services.io.newURI(
"data:text/plain;base64," + btoa(messages[0].toMessageString())
);
let imapMsg = new ImapMessage(dataUri.spec, daemon.inbox.uidnext++, []);
daemon.inbox.addMessage(imapMsg);
NetworkTestUtils.configureProxy("imap.tinderbox.invalid", PORT, server.port);
// Set up the basic accounts and folders
incomingServer = createLocalIMAPServer(PORT, "imap.tinderbox.invalid");
let identity = MailServices.accounts.createIdentity();
let imapAccount = MailServices.accounts.createAccount();
imapAccount.addIdentity(identity);
imapAccount.defaultIdentity = identity;
imapAccount.incomingServer = incomingServer;
});
add_task(async function downloadEmail() {
let inboxFolder = incomingServer.rootFolder.getChildNamed("INBOX");
// Check that we haven't got any messages in the folder, if we have its a test
// setup issue.
Assert.equal(inboxFolder.getTotalMessages(false), 0);
// Now get the mail
let asyncUrlListener = new PromiseTestUtils.PromiseUrlListener();
inboxFolder.getNewMessages(null, asyncUrlListener);
await asyncUrlListener.promise;
// We downloaded a message, so it works!
Assert.equal(inboxFolder.getTotalMessages(false), 1);
});
add_task(async function cleanUp() {
NetworkTestUtils.shutdownServers();
incomingServer.closeCachedConnections();
server.stop();
});
|