Skip to content

Instantly share code, notes, and snippets.

@georgyfarniev
Created October 9, 2020 15:10
Show Gist options
  • Save georgyfarniev/8c9893a6f5906119bb53753978b6d976 to your computer and use it in GitHub Desktop.
Save georgyfarniev/8c9893a6f5906119bb53753978b6d976 to your computer and use it in GitHub Desktop.
Pooling email messages issue repro
const { ImapFlow } = require('imapflow');
// Suppressing unnecessary output
const dummyLogger = {
debug() {},
info() {},
warn() {},
error() {}
};
const client = new ImapFlow({
host: 'mail.example.com',
port: 993,
secure: true,
auth: {
user: 'test@example.com',
pass: 'example'
},
logger: dummyLogger
});
const sleep = (msecs) => new Promise((r) => setTimeout(r, msecs));
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 {
// fetch latest message source
while(true) {
let message = await client.fetchOne('*', { source: true });
console.log('messge:', message.uid);
await sleep(1000);
}
} finally {
// Make sure lock is released, otherwise next `getMailboxLock()` never returns
lock.release();
}
// log out and close connection
await client.logout();
};
main().catch(err => console.error(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment