Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fetchAll method #207

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/imap-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,36 @@ class ImapFlow extends EventEmitter {
}
}

/**
* Fetch messages from currently opened mailbox
* This will fetch all messages before resolving the promise, unlike .fetch() which is async generator
*
* @param {SequenceString | Number[] | SearchObject} range Range of messages to fetch
* @param {FetchQueryObject} query Fetch query
* @param {Object} [options]
* @param {Boolean} [options.uid] If `true` then uses UID numbers instead of sequence numbers for `range`
* @param {BigInt} [options.changedSince] If set then only messages with a higher modseq value are returned. Ignored if server does not support `CONDSTORE` extension.
* @param {Boolean} [options.binary=false] If `true` then requests a binary response if the server supports this
* @returns {Promise<FetchMessageObject[]>} Array of Message data object
*
* @example
* let mailbox = await client.mailboxOpen('INBOX');
* // fetch UID for all messages in a mailbox
* const messages = await client.fetchAll('1:*', {uid: true});
* for (let msg of messages){
* console.log(msg.uid);
* // You can not run any IMAP commands in this loop
* }
*/
async fetchAll(range, query, options) {
const results = [];
const generator = this.fetch(range, query, options);
for await (const message of generator) {
results.push(message);
}
return results;
}

/**
* Fetch a single message from currently opened mailbox
*
Expand Down
Loading