fix: update mailparser
This commit is contained in:
70
package-lock.json
generated
70
package-lock.json
generated
@@ -9,12 +9,10 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"imap": "^0.8.19",
|
|
||||||
"imapflow": "^1.0.162",
|
"imapflow": "^1.0.162",
|
||||||
"mailparser": "^3.7.1"
|
"mailparser": "^3.7.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/imap": "^0.8.40",
|
|
||||||
"@types/imapflow": "^1.0.18",
|
"@types/imapflow": "^1.0.18",
|
||||||
"@types/mailparser": "^3.4.4",
|
"@types/mailparser": "^3.4.4",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
@@ -96,15 +94,6 @@
|
|||||||
"integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
|
"integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/@types/imapflow": {
|
||||||
"version": "1.0.18",
|
"version": "1.0.18",
|
||||||
"resolved": "https://registry.npmjs.org/@types/imapflow/-/imapflow-1.0.18.tgz",
|
"resolved": "https://registry.npmjs.org/@types/imapflow/-/imapflow-1.0.18.tgz",
|
||||||
@@ -310,11 +299,6 @@
|
|||||||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
|
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/create-require": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
||||||
@@ -585,18 +569,6 @@
|
|||||||
"integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==",
|
"integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/imapflow": {
|
||||||
"version": "1.0.162",
|
"version": "1.0.162",
|
||||||
"resolved": "https://registry.npmjs.org/imapflow/-/imapflow-1.0.162.tgz",
|
"resolved": "https://registry.npmjs.org/imapflow/-/imapflow-1.0.162.tgz",
|
||||||
@@ -613,11 +585,6 @@
|
|||||||
"socks": "2.8.3"
|
"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": {
|
"node_modules/ip-address": {
|
||||||
"version": "9.0.5",
|
"version": "9.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz",
|
||||||
@@ -672,11 +639,6 @@
|
|||||||
"node": ">=0.12.0"
|
"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": {
|
"node_modules/jsbn": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz",
|
||||||
"integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg=="
|
"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": {
|
"node_modules/readdirp": {
|
||||||
"version": "3.6.0",
|
"version": "3.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz",
|
||||||
"integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA=="
|
"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": {
|
"node_modules/supports-color": {
|
||||||
"version": "5.5.0",
|
"version": "5.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
||||||
@@ -1260,22 +1206,6 @@
|
|||||||
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
|
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/v8-compile-cache-lib": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/imap": "^0.8.40",
|
|
||||||
"@types/imapflow": "^1.0.18",
|
"@types/imapflow": "^1.0.18",
|
||||||
"@types/mailparser": "^3.4.4",
|
"@types/mailparser": "^3.4.4",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
@@ -20,7 +19,6 @@
|
|||||||
"typescript": "^5.4.5"
|
"typescript": "^5.4.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"imap": "^0.8.19",
|
|
||||||
"imapflow": "^1.0.162",
|
"imapflow": "^1.0.162",
|
||||||
"mailparser": "^3.7.1"
|
"mailparser": "^3.7.1"
|
||||||
}
|
}
|
||||||
|
|||||||
58
src/index.ts
58
src/index.ts
@@ -1,5 +1,6 @@
|
|||||||
const {ImapFlow} = require('imapflow');
|
const {ImapFlow} = require('imapflow');
|
||||||
const {simpleParser} = require('mailparser');
|
const simpleParser = require('mailparser').simpleParser
|
||||||
|
|
||||||
const dotenv = require('dotenv')
|
const dotenv = require('dotenv')
|
||||||
|
|
||||||
require('dotenv').config()
|
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 () => {
|
const main = async () => {
|
||||||
await client.connect(); // Wait until client connects and authorizes
|
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)
|
// 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 list = await client.search({seen: false}); // find all unseen messages
|
||||||
|
|
||||||
let lastMsg = await client.fetchOne('*', {uid: true})
|
//let lastMsg = await client.fetchOne('*', {uid: true}) // fetch one message
|
||||||
console.log('(!)FETCH',lastMsg.uid);
|
|
||||||
|
|
||||||
//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 {
|
} finally {
|
||||||
|
|
||||||
@@ -51,6 +94,9 @@ const main = async () => {
|
|||||||
await client.logout(); // log out and close connection
|
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