-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (31 loc) · 1.09 KB
/
index.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
const { getMessage } = require('./gmailApi/getMessage.js');
const { authorize } = require('./authorize.js');
const { writeToFile } = require('./utils/writeToFile.js');
const { getEmails } = require('./gmailApi/getEmails.js');
require('dotenv').config();
(async () => {
try {
const auth = await authorize();
console.log(`Authorization ✅`);
console.log(`Retreiving the IDs...`);
const messageIdArr = await getEmails(
`from:${process.env.FROM_EMAIL}`,
auth
);
console.log(
`Retreiving IDs ✅. Total no of emails ---> ${messageIdArr.length}`
);
// get the raw text of each email in an array and reverse it since the latest email should at the end
console.log(`Retreiving Body...`);
const bodyArr = (await getMessage(auth, messageIdArr)).reverse();
console.log(
`Retreived Body ✅. Total no of rawTextBody ---> ${bodyArr.length}`
);
// write the raw text to file
console.log(`Writing to file...`);
await writeToFile(bodyArr);
console.log(`Written to file ✅`);
} catch (error) {
console.error(error);
}
})();