Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('dotenv').config();
- const config = require('./config');
- const { ImapFlow } = require('imapflow');
- const client = new ImapFlow(config);
- const main = async () => {
- // Wait until client connects and authorizes
- await client.connect();
- // Select and lock a mailbox. Throws if mailbox does not exist
- let lock = await client.getMailboxLock('INBOX');
- try {
- let options = [
- { unseen: true },
- {
- envelope: true,
- flags: true,
- labels: true,
- headers: true
- }
- ];
- for await (let message of client.fetch(...options)) {
- let from = (message.envelope.from.map((address) => {
- return `${address.name} <${address.address}>`;
- })).join(',');
- console.log(`${message.uid}: ${message.envelope.date} ${message.envelope.subject} "${from}"`);
- console.trace(message);
- }
- } finally {
- // Make sure lock is released, otherwise next `getMailboxLock()` never returns
- lock.release();
- }
- await client.messageFlagsSet({all: true}, ['\Seen']);
- // log out and close connection
- await client.logout();
- };
- main().catch(err => console.error(err));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement