Compare commits
5 Commits
cdc83ffba6
...
6c4815beb1
Author | SHA1 | Date | |
---|---|---|---|
6c4815beb1 | |||
d87730a09b | |||
6af2abc5e2 | |||
0d8fb7344b | |||
f92557ea85 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -130,3 +130,5 @@ dist
|
|||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
|
# Project
|
||||||
|
config.json
|
||||||
|
56
server.js
Normal file
56
server.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
const Pop3Command = require("node-pop3");
|
||||||
|
const fs = require("fs");
|
||||||
|
const { EventEmitter } = require("events");
|
||||||
|
|
||||||
|
const initalConfig = `{
|
||||||
|
"pop3-config": {
|
||||||
|
"user": "example",
|
||||||
|
"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"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async init () {
|
||||||
|
const msg = (
|
||||||
|
await pop3.pop3cmd.UIDL()
|
||||||
|
).map(async x => {
|
||||||
|
x[1] = {
|
||||||
|
uid: x[1],
|
||||||
|
msg: await await pop3.pop3cmd.RETR(+x[0])
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
});
|
||||||
|
this.msg = Object.fromEntries(
|
||||||
|
await Promise.all(msg)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const pop3 = new POP3();
|
||||||
|
pop3.init().then(() => {
|
||||||
|
let interval = setTimeout(async () => {
|
||||||
|
console.log(pop3.msg);
|
||||||
|
//const list = await pop3.pop3cmd.UIDL();
|
||||||
|
//console.log(list);
|
||||||
|
//const str = await pop3.pop3cmd.RETR(1);
|
||||||
|
//console.log(str);
|
||||||
|
}, 1);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user