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.
246 lines
6.1 KiB
JavaScript
246 lines
6.1 KiB
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
const pEvent = require("p-event");
|
|
const tap = require("tap");
|
|
const BL = require("bl");
|
|
const { Parser } = require("../../lib/Parser");
|
|
|
|
tap.test("parse-session", (test) => {
|
|
let session = `
|
|
Server: * PREAUTH [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS SPECIAL-USE BINARY MOVE ACL RIGHTS=texk] Logged in as m.markov at domain.com
|
|
Client: 1 LIST "" "*"
|
|
Server: * LIST (\\HasNoChildren) "/" confirmed-spam
|
|
Server: * LIST (\\HasNoChildren \\Trash) "/" Trash
|
|
Server: * LIST (\\HasNoChildren) "/" SpamLikely
|
|
Server: * LIST (\\HasNoChildren) "/" Spam
|
|
Server: * LIST (\\HasNoChildren) "/" "Sent Items"
|
|
Server: * LIST (\\HasNoChildren) "/" Archive
|
|
Server: * LIST (\\HasNoChildren \\Drafts) "/" Drafts
|
|
Server: * LIST (\\HasNoChildren) "/" Notes
|
|
Server: * LIST (\\HasNoChildren) "/" TeamViewer
|
|
Server: * LIST (\\HasNoChildren \\Sent) "/" "Sent Messages"
|
|
Server: * LIST (\\HasNoChildren) "/" confirmed-ham
|
|
Server: * LIST (\\Noselect \\HasChildren) "/" Public
|
|
Server: * LIST (\\HasNoChildren) "/" Public/office3
|
|
Server: * LIST (\\HasNoChildren) "/" Public/office4
|
|
Server: * LIST (\\HasNoChildren) "/" Public/support
|
|
Server: * LIST (\\HasNoChildren) "/" Public/root
|
|
Server: * LIST (\\HasNoChildren) "/" Public/updates
|
|
Server: * LIST (\\HasNoChildren) "/" Public/postmaster
|
|
Server: * LIST (\\Noselect \\HasChildren) "/" Shared
|
|
Server: * LIST (\\Noselect \\HasChildren) "/" Shared/d.marteva
|
|
Server: * LIST (\\HasNoChildren) "/" Shared/d.marteva/INBOX
|
|
Server: * LIST (\\HasNoChildren) "/" INBOX
|
|
Server: 1 OK List completed.
|
|
Client: 2 LOGOUT
|
|
`.replace(/\n/g, "\r\n").replace(/^\t+/gm, "");
|
|
|
|
let serverSession = session
|
|
.split("\n")
|
|
.filter((line) => line.startsWith("Server:"))
|
|
.map((line) => line.replace(/^Server: /, ""))
|
|
.join("\n");
|
|
|
|
let serverBuffer = new BL([ Buffer.from(serverSession) ]);
|
|
|
|
let expectedResults = [{
|
|
"type": "preauth",
|
|
"textCode": {
|
|
"key": "CAPABILITY",
|
|
"val": ["IMAP4rev1", "LITERAL+", "SASL-IR", "LOGIN-REFERRALS", "ID", "ENABLE", "IDLE", "SORT", "SORT=DISPLAY", "THREAD=REFERENCES", "THREAD=REFS", "THREAD=ORDEREDSUBJECT", "MULTIAPPEND", "URL-PARTIAL", "CATENATE", "UNSELECT", "CHILDREN", "NAMESPACE", "UIDPLUS", "LIST-EXTENDED", "I18NLEVEL=1", "CONDSTORE", "QRESYNC", "ESEARCH", "ESORT", "SEARCHRES", "WITHIN", "CONTEXT=SEARCH", "LIST-STATUS", "SPECIAL-USE", "BINARY", "MOVE", "ACL", "RIGHTS=texk"]
|
|
},
|
|
"text": "Logged in as m.markov at domain.com"
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "confirmed-spam"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren", "\\Trash"],
|
|
"delimiter": "/",
|
|
"name": "Trash"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "SpamLikely"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Spam"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Sent Items"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Archive"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren", "\\Drafts"],
|
|
"delimiter": "/",
|
|
"name": "Drafts"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Notes"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "TeamViewer"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren", "\\Sent"],
|
|
"delimiter": "/",
|
|
"name": "Sent Messages"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "confirmed-ham"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\Noselect", "\\HasChildren"],
|
|
"delimiter": "/",
|
|
"name": "Public"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Public/office3"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Public/office4"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Public/support"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Public/root"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Public/updates"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Public/postmaster"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\Noselect", "\\HasChildren"],
|
|
"delimiter": "/",
|
|
"name": "Shared"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\Noselect", "\\HasChildren"],
|
|
"delimiter": "/",
|
|
"name": "Shared/d.marteva"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "Shared/d.marteva/INBOX"
|
|
}
|
|
}, {
|
|
"type": "list",
|
|
"text": {
|
|
"flags": ["\\HasNoChildren"],
|
|
"delimiter": "/",
|
|
"name": "INBOX"
|
|
}
|
|
}];
|
|
|
|
let stream = new BL.BufferListStream(serverBuffer);
|
|
let parser = new Parser(stream);
|
|
let results = [];
|
|
|
|
parser.on("tagged", (item) => {
|
|
// console.log("tagged", item);
|
|
results.push(item);
|
|
});
|
|
|
|
parser.on("untagged", (item) => {
|
|
// console.log("untagged", item);
|
|
results.push(item);
|
|
});
|
|
|
|
parser.on("continue", (... args) => {
|
|
// console.log("continue", args);
|
|
});
|
|
|
|
parser.on("other", (... args) => {
|
|
// console.log("other", args);
|
|
});
|
|
|
|
parser.on("body", (... args) => {
|
|
// console.log("body", args);
|
|
});
|
|
|
|
return Promise.try(() => {
|
|
// NOTE: Parser does not expose an 'end' event
|
|
return pEvent(stream, "end");
|
|
}).then(() => {
|
|
// Hack for clearing out `undefined` properties
|
|
let normalizedResults = JSON.parse(JSON.stringify(results));
|
|
|
|
test.same(normalizedResults, expectedResults);
|
|
});
|
|
});
|