-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-domain.mjs
38 lines (30 loc) · 1.03 KB
/
find-domain.mjs
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
import path from "node:path";
import fs from "node:fs/promises";
import { simpleParser } from "mailparser";
const emailDir = "./emails";
const desiredDomain = "fotball.no";
async function main() {
const files = await fs.readdir(emailDir, { recursive: true });
for (const file of files) {
let filePath = path.join(emailDir, file);
if (filePath.endsWith(".pdf") || file.includes("old")) {
continue;
}
const data = await Bun.file(filePath).text();
try {
const parsed = await simpleParser(data);
const sender = parsed.from.value[0].address;
// const recipient = parsed.to.value[0].address;
const senderDomain = sender.split("@")[1].toLowerCase();
if (senderDomain === desiredDomain) {
console.log(`Email from ${sender} found in ${file}`);
}
// if (recipient === "[email protected]") {
// console.log(parsed.text);
// }
} catch (parseErr) {
console.error("Error parsing email:", parseErr);
}
}
}
main().catch(console.error);