-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxitroo.js
57 lines (48 loc) · 2.17 KB
/
xitroo.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fetch = require('node-fetch');
class Xitroo {
constructor(xitrooEmail, refreshCounter = 5, refreshWait = 5, httpTimeout = 15) {
this.xEmail = xitrooEmail;
this.refreshC = refreshCounter;
this.refreshW = refreshWait;
this.httpT = httpTimeout;
}
async getLatestInboxRaw() {
for (let i = 0; i < this.refreshC; i++) {
try {
const response = await fetch(`https://api.xitroo.com/v1/mails?locale=de&mailAddress=${this.xEmail}&mailsPerPage=25&minTimestamp=0.0&maxTimestamp=${Math.floor(Date.now() / 1000) + 500}`, {
timeout: this.httpT * 1000
});
const idSite = await response.json();
try {
const mailResponse = await fetch(`https://api.xitroo.com/v1/mail?locale=de&id=${idSite.mails[0]._id}`);
return await mailResponse.json();
} catch (error) {
console.log(`[Xitroo] ${idSite.type}`);
if (i === this.refreshC - 1) process.exit();
await new Promise(resolve => setTimeout(resolve, this.refreshW * 1000));
}
} catch (error) {
console.log("[Xitroo] HTTP Error");
if (i === this.refreshC - 1) process.exit();
await new Promise(resolve => setTimeout(resolve, this.refreshW * 1000));
}
}
}
async getBodyHtmlStrict() {
const latestInbox = await this.getLatestInboxRaw();
return Buffer.from(latestInbox.bodyHtmlStrict, 'base64').toString('utf-8');
}
async getBodyHtml() {
const latestInbox = await this.getLatestInboxRaw();
return Buffer.from(latestInbox.bodyHtml, 'base64').toString('utf-8');
}
async getBodyText() {
const latestInbox = await this.getLatestInboxRaw();
return Buffer.from(latestInbox.bodyText, 'base64').toString('utf-8');
}
async getSubject() {
const latestInbox = await this.getLatestInboxRaw();
return Buffer.from(latestInbox.subject, 'base64').toString('utf-8');
}
}
module.exports = Xitroo;