-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpop3.js
40 lines (35 loc) · 1.31 KB
/
pop3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const Client = require('node-poplib-gowhich').Client;
module.exports.getEmails = (scenario, subject) => {
let config = {
hostname: scenario.protocol_host,
port: scenario.protocol_port,
tls: scenario.protocol_tls | false,
mailparser: true,
};
if (scenario.protocol_user && scenario.protocol_password) {
config["username"] = scenario.protocol_user;
config["password"] = scenario.protocol_password;
}
const client = new Client(config);
let startProtocolTime = new Date().getTime();
return new Promise((resolve, reject) => {
client.connect((err) => {
if (err) reject(err);
if (global.debug) console.log('Getting POP3 email');
client.retrieveAll(function (err, messages) {
if (err) reject(err);
for (let num in messages) {
let mail = messages[num];
if (mail.subject === subject) {
const {receivedDate} = mail;
resolve({receivedDate, startProtocolTime});
client.dele(num, (err, data) => {
if (err) reject(err);
});
}
}
client.quit();
})
})
})
};