-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { BingChat } from "bing-chat"; | ||
import MailListener from "mail-listener2"; | ||
import Nodemailer from "nodemailer"; | ||
import dotenv from "dotenv"; | ||
|
||
dotenv.config(); | ||
|
||
const mailTransporter = Nodemailer.createTransport({ | ||
service: "gmail", | ||
auth: { | ||
user: "[email protected]", | ||
pass: process.env.GMAIL_PASSWORD, | ||
}, | ||
}); | ||
|
||
const mailListener = new MailListener({ | ||
username: "[email protected]", | ||
password: process.env.GMAIL_PASSWORD, | ||
host: "imap.gmail.com", | ||
port: 993, // imap port | ||
tls: true, | ||
connTimeout: 10000, // Default by node-imap | ||
authTimeout: 5000, // Default by node-imap, | ||
debug: console.log, // Or your custom function with only one incoming argument. Default: null | ||
tlsOptions: { rejectUnauthorized: false }, | ||
mailbox: "INBOX", // mailbox to monitor | ||
searchFilter: ["UNSEEN"], // , "FLAGGED" the search filter being used after an IDLE notification has been retrieved | ||
markSeen: true, // all fetched email willbe marked as seen and not fetched next time | ||
fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`, | ||
mailParserOptions: { streamAttachments: true }, // options to be passed to mailParser lib. | ||
attachments: true, // download attachments as they are encountered to the project directory | ||
attachmentOptions: { directory: "attachments/" }, // specify a download directory for attachments | ||
}); | ||
|
||
mailListener.start(); // start listening | ||
|
||
// stop listening | ||
//mailListener.stop(); | ||
|
||
mailListener.on("server:connected", function () { | ||
console.log("imapConnected"); | ||
}); | ||
|
||
mailListener.on("server:disconnected", function () { | ||
console.log("imapDisconnected"); | ||
}); | ||
|
||
mailListener.on("error", function (err) { | ||
console.log(err); | ||
}); | ||
|
||
mailListener.on("mail", async function (mail, seqno, attributes) { | ||
// do something with mail object including attachments | ||
// console.log("emailParsed", mail); | ||
console.log(mail); | ||
const senderEmail = mail.headers["return-path"]; | ||
const messageId = mail.headers["message-id"]; | ||
const subject = mail.headers["subject"]; | ||
console.log("Sender email:", senderEmail); | ||
console.log("Content:", mail.text); | ||
|
||
const api = new BingChat({ | ||
cookie: process.env.BING_CHAT_COOKIE, | ||
}); | ||
|
||
const res = await api.sendMessage("Is this a scam email?\n\n" + mail.text); | ||
|
||
console.log(res.text); | ||
// mail processing code goes here | ||
|
||
let mailDetails = { | ||
from: "[email protected]", | ||
to: senderEmail, | ||
inReplyTo: messageId, | ||
subject: "Re: " + subject, | ||
text: res.text, | ||
}; | ||
|
||
mailTransporter.sendMail(mailDetails, function (err, data) { | ||
if (err) { | ||
console.log("Error Occurs"); | ||
} else { | ||
console.log("Email sent successfully"); | ||
} | ||
}); | ||
}); | ||
|
||
mailListener.on("attachment", function (attachment) { | ||
console.log(attachment.path); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"dependencies": { | ||
"bing-chat": "^0.2.3", | ||
"dotenv": "^16.0.3", | ||
"mail-listener2": "^0.3.1", | ||
"nodemailer": "^6.9.2" | ||
}, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
addressparser@~1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/addressparser/-/addressparser-1.0.1.tgz#47afbe1a2a9262191db6838e4fd1d39b40821746" | ||
integrity sha512-aQX7AISOMM7HFE0iZ3+YnD07oIeJqWGVnJ+ZIKaBZAk03ftmVYVqsGas/rbXKR21n4D/hKCSHypvcyOkds/xzg== | ||
|
||
async@^0.9.0: | ||
version "0.9.2" | ||
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d" | ||
integrity sha512-l6ToIJIotphWahxxHyzK9bnLR6kM4jJIIgLShZeqLY7iboHoGkdgFl7W2/Ivi4SkMJYGKqW8vSuk0uKUj6qsSw== | ||
|
||
bing-chat@^0.2.3: | ||
version "0.2.3" | ||
resolved "https://registry.yarnpkg.com/bing-chat/-/bing-chat-0.2.3.tgz#aba19c55e5dfbe12ceae6e26cbbaf405c146703f" | ||
integrity sha512-q9JIGqrrEhBEgIhTdtawvxcwQO5sdhMN3uATbLxpd52sH0+Jm7QhtsaodlLUbQgEQGo+YXfFPWWpK5lWMXGvHw== | ||
dependencies: | ||
ws "^8.13.0" | ||
|
||
core-util-is@~1.0.0: | ||
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85" | ||
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ== | ||
|
||
dotenv@^16.0.3: | ||
version "16.0.3" | ||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07" | ||
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ== | ||
|
||
encoding@>=0.1.4, encoding@~0.1.12: | ||
version "0.1.13" | ||
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.13.tgz#56574afdd791f54a8e9b2785c0582a2d26210fa9" | ||
integrity sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A== | ||
dependencies: | ||
iconv-lite "^0.6.2" | ||
|
||
iconv-lite@^0.6.2: | ||
version "0.6.3" | ||
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501" | ||
integrity sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw== | ||
dependencies: | ||
safer-buffer ">= 2.1.2 < 3.0.0" | ||
|
||
imap@~0.8.14: | ||
version "0.8.19" | ||
resolved "https://registry.yarnpkg.com/imap/-/imap-0.8.19.tgz#3678873934ab09cea6ba48741f284da2af59d8d5" | ||
integrity sha512-z5DxEA1uRnZG73UcPA4ES5NSCGnPuuouUx43OPX7KZx1yzq3N8/vx2mtXEShT5inxB3pRgnfG1hijfu7XN2YMw== | ||
dependencies: | ||
readable-stream "1.1.x" | ||
utf7 ">=1.0.2" | ||
|
||
inherits@~2.0.1: | ||
version "2.0.4" | ||
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" | ||
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== | ||
|
||
[email protected]: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" | ||
integrity sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ== | ||
|
||
mail-listener2@^0.3.1: | ||
version "0.3.1" | ||
resolved "https://registry.yarnpkg.com/mail-listener2/-/mail-listener2-0.3.1.tgz#1814497d9632fd8eaf4e3cb083aa90129661fa89" | ||
integrity sha512-gn4yhOcy2Cw6QPmU0AH3Wp54KtA9SUEIQJ3NlEwbdn/RWDIwv1KZ05HqS0oI3qVVorLjzzx3HzF9/zwlVP8uFg== | ||
dependencies: | ||
async "^0.9.0" | ||
imap "~0.8.14" | ||
mailparser "~0.4.6" | ||
|
||
mailparser@~0.4.6: | ||
version "0.4.9" | ||
resolved "https://registry.yarnpkg.com/mailparser/-/mailparser-0.4.9.tgz#1d0a48d6faaaa2f09ac1398ed023d8ef8eb19e2b" | ||
integrity sha512-hynXKucUPiN7CNpuy+2XW4NluQyB6sEP6GVqxaZN/I4ssX2+yxo8w1zRCWCXgeQgG6ZO2rtZnBVQFCdhLnQBVQ== | ||
dependencies: | ||
encoding ">=0.1.4" | ||
mime "*" | ||
mimelib ">=0.2.17" | ||
uue "~1.0.0" | ||
|
||
mime@*: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/mime/-/mime-3.0.0.tgz#b374550dca3a0c18443b0c950a6a58f1931cf7a7" | ||
integrity sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A== | ||
|
||
mimelib@>=0.2.17: | ||
version "0.3.1" | ||
resolved "https://registry.yarnpkg.com/mimelib/-/mimelib-0.3.1.tgz#787add2415d827acb3af6ec4bca1ea9596418853" | ||
integrity sha512-ipzNp6TBsNfD3hButGlPVlGmuCgybIM9SBf8YwIG+SYmBgtU0u8wjf+BSrJX0mvqtv59SLmwphw/XiCbkLWv7w== | ||
dependencies: | ||
addressparser "~1.0.1" | ||
encoding "~0.1.12" | ||
|
||
nodemailer@^6.9.2: | ||
version "6.9.2" | ||
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.9.2.tgz#b79051811edd52c2436ad1c6aed2dc45b9c9cf1f" | ||
integrity sha512-4+TYaa/e1nIxQfyw/WzNPYTEZ5OvHIDEnmjs4LPmIfccPQN+2CYKmGHjWixn/chzD3bmUTu5FMfpltizMxqzdg== | ||
|
||
[email protected]: | ||
version "1.1.14" | ||
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9" | ||
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" | ||
|
||
"safer-buffer@>= 2.1.2 < 3.0.0": | ||
version "2.1.2" | ||
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" | ||
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== | ||
|
||
semver@~5.3.0: | ||
version "5.3.0" | ||
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" | ||
integrity sha512-mfmm3/H9+67MCVix1h+IXTpDwL6710LyHuk7+cWC9T1mE0qz4iHhh6r4hU2wrIT9iTsAAC2XQRvfblL028cpLw== | ||
|
||
string_decoder@~0.10.x: | ||
version "0.10.31" | ||
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" | ||
integrity sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ== | ||
|
||
utf7@>=1.0.2: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/utf7/-/utf7-1.0.2.tgz#955f490aae653ba220b9456a0a8776c199360991" | ||
integrity sha512-qQrPtYLLLl12NF4DrM9CvfkxkYI97xOb5dsnGZHE3teFr0tWiEZ9UdgMPczv24vl708cYMpe6mGXGHrotIp3Bw== | ||
dependencies: | ||
semver "~5.3.0" | ||
|
||
uue@~1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/uue/-/uue-1.0.0.tgz#213b9448b98b98b9d03caf601a223589bd886430" | ||
integrity sha512-gEwvMeDsv0Q4SFsjhp/PmsXizTfEn3B8SXqtRiz5jE2nsRgEBCY5W5gmxOFrPVzbnDCELwOKyMnOEoL/W/TG7w== | ||
|
||
ws@^8.13.0: | ||
version "8.13.0" | ||
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" | ||
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== |