Skip to content

Commit

Permalink
fix(api): Add fetchAll method (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
Remscar authored Jul 9, 2024
1 parent 5f257a3 commit bc09998
Showing 1 changed file with 30 additions and 0 deletions.
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

0 comments on commit bc09998

Please sign in to comment.