fix: update mailparser

This commit is contained in:
2024-05-11 00:10:16 +03:00
parent 286dddd557
commit 49f93c7b8a
3 changed files with 52 additions and 78 deletions

70
package-lock.json generated
View File

@@ -9,12 +9,10 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"imap": "^0.8.19",
"imapflow": "^1.0.162",
"mailparser": "^3.7.1"
},
"devDependencies": {
"@types/imap": "^0.8.40",
"@types/imapflow": "^1.0.18",
"@types/mailparser": "^3.4.4",
"dotenv": "^16.4.5",
@@ -96,15 +94,6 @@
"integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
"dev": true
},
"node_modules/@types/imap": {
"version": "0.8.40",
"resolved": "https://registry.npmjs.org/@types/imap/-/imap-0.8.40.tgz",
"integrity": "sha512-kWFwOc88CGwWZlHqCnZiceS6EralsAHdjpQyk1+fIA875NQdIHvLpdD5NU3Pi1yZ8FKFdOF81UDNAo8/XS6HiQ==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/imapflow": {
"version": "1.0.18",
"resolved": "https://registry.npmjs.org/@types/imapflow/-/imapflow-1.0.18.tgz",
@@ -310,11 +299,6 @@
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
"dev": true
},
"node_modules/core-util-is": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
},
"node_modules/create-require": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
@@ -585,18 +569,6 @@
"integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==",
"dev": true
},
"node_modules/imap": {
"version": "0.8.19",
"resolved": "https://registry.npmjs.org/imap/-/imap-0.8.19.tgz",
"integrity": "sha512-z5DxEA1uRnZG73UcPA4ES5NSCGnPuuouUx43OPX7KZx1yzq3N8/vx2mtXEShT5inxB3pRgnfG1hijfu7XN2YMw==",
"dependencies": {
"readable-stream": "1.1.x",
"utf7": ">=1.0.2"
},
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/imapflow": {
"version": "1.0.162",
"resolved": "https://registry.npmjs.org/imapflow/-/imapflow-1.0.162.tgz",
@@ -613,11 +585,6 @@
"socks": "2.8.3"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"node_modules/ip-address": {
"version": "9.0.5",
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz",
@@ -672,11 +639,6 @@
"node": ">=0.12.0"
}
},
"node_modules/isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ=="
},
"node_modules/jsbn": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz",
@@ -989,17 +951,6 @@
"resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz",
"integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg=="
},
"node_modules/readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==",
"dependencies": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"node_modules/readdirp": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
@@ -1130,11 +1081,6 @@
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz",
"integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA=="
},
"node_modules/string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ=="
},
"node_modules/supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
@@ -1260,22 +1206,6 @@
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
"dev": true
},
"node_modules/utf7": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/utf7/-/utf7-1.0.2.tgz",
"integrity": "sha512-qQrPtYLLLl12NF4DrM9CvfkxkYI97xOb5dsnGZHE3teFr0tWiEZ9UdgMPczv24vl708cYMpe6mGXGHrotIp3Bw==",
"dependencies": {
"semver": "~5.3.0"
}
},
"node_modules/utf7/node_modules/semver": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
"integrity": "sha512-mfmm3/H9+67MCVix1h+IXTpDwL6710LyHuk7+cWC9T1mE0qz4iHhh6r4hU2wrIT9iTsAAC2XQRvfblL028cpLw==",
"bin": {
"semver": "bin/semver"
}
},
"node_modules/v8-compile-cache-lib": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",

View File

@@ -11,7 +11,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@types/imap": "^0.8.40",
"@types/imapflow": "^1.0.18",
"@types/mailparser": "^3.4.4",
"dotenv": "^16.4.5",
@@ -20,7 +19,6 @@
"typescript": "^5.4.5"
},
"dependencies": {
"imap": "^0.8.19",
"imapflow": "^1.0.162",
"mailparser": "^3.7.1"
}

View File

@@ -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)