pop3-to-imap/server.js

38 lines
840 B
JavaScript

const Pop3Command = require("node-pop3");
const fs = require("fs");
const { EventEmitter } = require("events");
const initalConfig = `{
"pop3-config": {
"user": "example@example.com",
"password": "example",
"host": "pop3.example.com"
}
}`;
try {
fs.readFileSync("./config.json");
} catch (e) {
fs.writeFileSync("./config.json", initalConfig, {
encoding: "utf-8"
});
console.warn("WARNING config.json is empty. This file was been created. Please, configure it.");
return process.exit();
}
global.config = require("./config.json");
class POP3 extends EventEmitter {
constructor () {
super();
this.pop3cmd = new Pop3Command(global.config["pop3-config"]);
}
}
const pop3 = new POP3();
let interval = setTimeout(async () => {
const list = await pop3.pop3cmd.UIDL();
console.dir(list);
}, 1);