25 lines
672 B
JavaScript
25 lines
672 B
JavaScript
const net = require("net");
|
|
const imap = require("./logic");
|
|
//const EventEmitter = require("events");
|
|
|
|
const server = net.createServer((socket) => {
|
|
const client = new imap.Client(socket);
|
|
socket.write("* OK IMAP4rev1 NodeIMAP Ready\r\n");
|
|
|
|
let state = "not_authenticated";
|
|
let currentMailbox = null;
|
|
//let tag = "";
|
|
|
|
socket.on("data", (data) => {
|
|
const line = data.toString().trim();
|
|
console.debug("IMAP data:", line);
|
|
const splitted = line.split(/\s{1,}/g);
|
|
if (splitted.length < 2) return socket.write(". BAD unknown command\r\n");
|
|
const [tag, command, ...args] = splitted;
|
|
|
|
client.command(tag, command, args);
|
|
});
|
|
});
|
|
|
|
module.exports = server;
|