fix: add imapflow

This commit is contained in:
2024-05-10 19:47:10 +03:00
parent fb1e88a496
commit 286dddd557
3 changed files with 767 additions and 4 deletions

View File

@@ -1 +1,56 @@
console.log('Heartbeat is ok')
const {ImapFlow} = require('imapflow');
const {simpleParser} = require('mailparser');
const dotenv = require('dotenv')
require('dotenv').config()
const client = new ImapFlow({
host: process.env.EMAIL_IMAP_SERVER,
port: 993,
secure: true,
auth: {
user: process.env.EMAIL_ADDRESS,
pass: process.env.EMAIL_PASSWORD,
}
});
const main = async () => {
await client.connect(); // Wait until client connects and authorizes
//let lock = await client.getMailboxLock('INBOX'); // Select and lock a mailbox. Throws if mailbox does not exist
let mailbox = await client.mailboxOpen('INBOX');
try {
// // fetch latest message source
// // client.mailbox includes information about currently selected mailbox
// // "exists" value is also the largest sequence number available in the mailbox
// let message = await client.fetchOne(client.mailbox.exists, { source: true });
// console.log(message.source.toString());
//
// // list subjects for all messages
// // uid value is always included in FETCH response, envelope strings are in unicode.
// for await (let message of client.fetch('1:*', { envelope: true })) {
// console.log(`${message.uid}: ${message.envelope.subject}`);
// }
// await client.messageFlagsRemove({seen: false}, ["\\Seen"], {uid:true}); // mark all seen messages as unseen by removing Seen flag
// 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);
//console.log('(!) LIST:', list)
} finally {
//lock.release(); // Make sure lock is released, otherwise next `getMailboxLock()` never returns
}
await client.logout(); // log out and close connection
};
main().catch(err => console.error(err));
console.log('Heartbeat is ok')