You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.0 KiB
JavaScript
112 lines
3.0 KiB
JavaScript
3 years ago
|
"use strict";
|
||
|
|
||
|
const Promise = require("bluebird");
|
||
|
const tap = require("tap");
|
||
|
const pEvent = require("p-event");
|
||
|
const IMAP = require("../../lib/Connection");
|
||
|
|
||
|
const lines = require("../lines");
|
||
|
const createMockServer = require("../mock-server");
|
||
|
|
||
|
tap.test("list", (test) => {
|
||
|
return testFetch(test);
|
||
|
});
|
||
|
|
||
|
function testFetch(test) {
|
||
|
let steps = [{
|
||
|
expected: 'A0 CAPABILITY',
|
||
|
response: lines([
|
||
|
'* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA CHILDREN',
|
||
|
'A0 OK Thats all she wrote!',
|
||
|
]),
|
||
|
}, {
|
||
|
expected: 'A1 LOGIN "foo" "bar"',
|
||
|
response: lines([
|
||
|
'* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA CHILDREN UIDPLUS MOVE',
|
||
|
'A1 OK authenticated (Success)',
|
||
|
]),
|
||
|
}, {
|
||
|
expected: 'A2 NAMESPACE',
|
||
|
response: lines([
|
||
|
'* NAMESPACE (("" "/")) NIL NIL',
|
||
|
'A2 OK Success',
|
||
|
]),
|
||
|
}, {
|
||
|
expected: 'A3 LIST "" ""',
|
||
|
response: lines([
|
||
|
'* LIST (\\HasNoChildren) "/" confirmed-spam',
|
||
|
'* LIST (\\HasNoChildren \\Trash) "/" Trash',
|
||
|
'* LIST (\\HasNoChildren) "/" SpamLikely',
|
||
|
'* LIST (\\HasNoChildren) "/" Spam',
|
||
|
'* LIST (\\HasNoChildren) "/" "Sent Items"',
|
||
|
'* LIST (\\HasNoChildren) "/" Archive',
|
||
|
'* LIST (\\HasNoChildren \\Drafts) "/" Drafts',
|
||
|
'* LIST (\\HasNoChildren) "/" Notes',
|
||
|
'* LIST (\\HasNoChildren) "/" TeamViewer',
|
||
|
'* LIST (\\HasNoChildren \\Sent) "/" "Sent Messages"',
|
||
|
'* LIST (\\HasNoChildren) "/" confirmed-ham',
|
||
|
'* LIST (\\Noselect \\HasChildren) "/" Public',
|
||
|
'* LIST (\\HasNoChildren) "/" Public/office3',
|
||
|
'* LIST (\\HasNoChildren) "/" Public/office4',
|
||
|
'* LIST (\\HasNoChildren) "/" Public/support',
|
||
|
'* LIST (\\HasNoChildren) "/" Public/root',
|
||
|
'* LIST (\\HasNoChildren) "/" Public/updates',
|
||
|
'* LIST (\\HasNoChildren) "/" Public/postmaster',
|
||
|
'* LIST (\\Noselect \\HasChildren) "/" Shared',
|
||
|
'* LIST (\\Noselect \\HasChildren) "/" Shared/d.marteva',
|
||
|
'* LIST (\\HasNoChildren) "/" Shared/d.marteva/INBOX',
|
||
|
'* LIST (\\HasNoChildren) "/" INBOX',
|
||
|
'A3 OK Success',
|
||
|
]),
|
||
|
}, {
|
||
|
expected: 'A4 EXAMINE "INBOX"',
|
||
|
response: lines([
|
||
|
'* FLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen)',
|
||
|
'* OK [PERMANENTFLAGS ()] Flags permitted.',
|
||
|
'* OK [UIDVALIDITY 2] UIDs valid.',
|
||
|
'* 685 EXISTS',
|
||
|
'* 0 RECENT',
|
||
|
'* OK [UIDNEXT 4422] Predicted next UID.',
|
||
|
'A4 OK [READ-ONLY] INBOX selected. (Success)',
|
||
|
]),
|
||
|
}, {
|
||
|
expected: "A5 LOGOUT",
|
||
|
response: lines([
|
||
|
'* BYE LOGOUT Requested',
|
||
|
'A5 OK good day (Success)',
|
||
|
]),
|
||
|
}];
|
||
|
|
||
|
return Promise.try(() => {
|
||
|
return createMockServer({
|
||
|
steps: steps,
|
||
|
test: test
|
||
|
});
|
||
|
}).then(({ server, port, finalize }) => {
|
||
|
const client = new IMAP({
|
||
|
user: "foo",
|
||
|
password: "bar",
|
||
|
host: "127.0.0.1",
|
||
|
port: port,
|
||
|
keepalive: false
|
||
|
});
|
||
|
|
||
|
Promise.promisifyAll(client, { multiArgs: true });
|
||
|
client.connect();
|
||
|
|
||
|
return Promise.try(() => {
|
||
|
return pEvent(client, "ready");
|
||
|
}).then(() => {
|
||
|
server.close(); // Stop listening for new clients
|
||
|
|
||
|
return client.openBoxAsync("INBOX", true);
|
||
|
}).tap(() => {
|
||
|
client.end();
|
||
|
|
||
|
return pEvent(client, "end");
|
||
|
}).then(() => {
|
||
|
finalize();
|
||
|
});
|
||
|
});
|
||
|
}
|