57 lines
1.1 KiB
JavaScript
57 lines
1.1 KiB
JavaScript
class IMAPController {
|
|
constructor (socket, tag) {
|
|
this.socket = socket;
|
|
this.tag = tag;
|
|
}
|
|
|
|
out (answer) {
|
|
this.socket.write(`${this.tag} ${answer}`);
|
|
}
|
|
|
|
untaggedOut (answer) {
|
|
this.socket.write(answer);
|
|
}
|
|
|
|
close () {
|
|
this.socket.end();
|
|
}
|
|
}
|
|
|
|
class Commands {
|
|
constructor (client) {
|
|
this.client = client;
|
|
}
|
|
|
|
async capability (args, controller) {
|
|
/*if (args.length > 0)
|
|
return out();*/
|
|
controller.untaggedOut("* CAPABILITY IMAP4rev1 STARTTLS LOGINDISABLED\r\n");
|
|
controller.out("OK CAPABILITY completed\r\n");
|
|
}
|
|
|
|
async logout(args, controller) {
|
|
controller.untaggedOut("* BYE Logging out\r\n");
|
|
controller.out("OK LOGOUT completed\r\n");
|
|
|
|
controller.close();
|
|
}
|
|
}
|
|
|
|
class Client {
|
|
constructor (socket) {
|
|
this.socket = socket;
|
|
this.commands = new Commands(this);
|
|
}
|
|
|
|
command (tag, command, args) {
|
|
//console.debug("this >>", this, this.socket, this.commands);
|
|
const cmd = this.commands[command.toLowerCase()];
|
|
if (cmd === undefined) {
|
|
return this.socket.write(`${tag} BAD unknown command\r\n`);
|
|
}
|
|
cmd.call(this.commands, args, new IMAPController(this.socket, tag));
|
|
}
|
|
}
|
|
|
|
module.exports = { Client };
|