fix: update mailparser
This commit is contained in:
58
src/index.ts
58
src/index.ts
@@ -1,5 +1,6 @@
|
||||
const {ImapFlow} = require('imapflow');
|
||||
const {simpleParser} = require('mailparser');
|
||||
const simpleParser = require('mailparser').simpleParser
|
||||
|
||||
const dotenv = require('dotenv')
|
||||
|
||||
require('dotenv').config()
|
||||
@@ -16,6 +17,19 @@ const client = new ImapFlow({
|
||||
});
|
||||
|
||||
|
||||
const markString = 'test'
|
||||
|
||||
const concat_RS = (stream: any) => new Promise((res, rej) => {
|
||||
let buffers: any = [];
|
||||
stream.on("data", (data: any) => {
|
||||
buffers.push(data);
|
||||
});
|
||||
stream.on("end", () => {
|
||||
res(Buffer.concat(buffers));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
const main = async () => {
|
||||
await client.connect(); // Wait until client connects and authorizes
|
||||
|
||||
@@ -38,10 +52,39 @@ const main = async () => {
|
||||
// await client.messageFlagsSet({seen: false}, ["\\Seen"]); // mark all unseen messages as seen (and remove other flags)
|
||||
//let list = await client.search({seen: false}); // find all unseen messages
|
||||
|
||||
let lastMsg = await client.fetchOne('*', {uid: true})
|
||||
console.log('(!)FETCH',lastMsg.uid);
|
||||
//let lastMsg = await client.fetchOne('*', {uid: true}) // fetch one message
|
||||
|
||||
//console.log('(!) LIST:', list)
|
||||
let listSeenMsgId = await client.search({seen: false});
|
||||
console.log('📌', 'LIST:', listSeenMsgId)
|
||||
|
||||
// for await (let msg of client.fetch(listSeenMsgId, {uid: false})){
|
||||
// console.log(msg.envelope.subject);
|
||||
// }
|
||||
|
||||
for await (let message of client.fetch(listSeenMsgId,
|
||||
{
|
||||
envelope: true,
|
||||
//bodyParts: true,
|
||||
bodyStructure: true
|
||||
})) {
|
||||
if (message.envelope.subject.includes(markString)) {
|
||||
console.log('📌', message.envelope.subject, message.seq, message.bodyStructure);
|
||||
let bs;
|
||||
if (message.bodyStructure.childNodes) {
|
||||
let nodeHTML = message.bodyStructure?.childNodes?.find((node: any) => node.type?.toLowerCase() === 'text/html');
|
||||
let nodePlainText = message.bodyStructure?.childNodes?.find((node: any) => node.type?.toLowerCase() === 'text/plain');
|
||||
bs = nodePlainText ? nodePlainText : nodeHTML;
|
||||
} else {
|
||||
if (message.bodyStructure.type === 'text/plain') {
|
||||
bs = {
|
||||
part: "1",
|
||||
type: "text/plain"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
||||
@@ -51,6 +94,9 @@ const main = async () => {
|
||||
await client.logout(); // log out and close connection
|
||||
};
|
||||
|
||||
main().catch(err => console.error(err));
|
||||
|
||||
console.log('Heartbeat is ok')
|
||||
main().then().catch(err => console.error(err));
|
||||
|
||||
// setInterval(() => {
|
||||
// main().then(() => console.log('🧡', 'Heartbeat is ok')).catch(err => console.error(err));
|
||||
// }, 60 * 1000)
|
||||
|
||||
Reference in New Issue
Block a user