From 917ba80f21b2fe485154acd252d6565b838e73e6 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Mon, 6 May 2024 09:49:30 +0300 Subject: [PATCH] fix(listTree): pass listing options as an optional argument --- lib/imap-flow.js | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/imap-flow.js b/lib/imap-flow.js index 1374ae6..f0ee6fc 100644 --- a/lib/imap-flow.js +++ b/lib/imap-flow.js @@ -768,7 +768,7 @@ class ImapFlow extends EventEmitter { this.writeSocket.destroySoon = () => { try { if (this.socket) { - if (typeof this.socket.destroySoon === "function") { + if (typeof this.socket.destroySoon === 'function') { this.socket.destroySoon(); } else { this.socket.destroy(); @@ -1484,7 +1484,7 @@ class ImapFlow extends EventEmitter { if (this.writeSocket && !this.writeSocket.destroyed) { try { - if (typeof this.writeSocket.destroySoon === "function") { + if (typeof this.writeSocket.destroySoon === 'function') { this.writeSocket.destroySoon(); } else { this.writeSocket.destroy(); @@ -1496,7 +1496,7 @@ class ImapFlow extends EventEmitter { if (this.socket && !this.socket.destroyed && this.writeSocket !== this.socket) { try { - if (typeof this.socket.destroySoon === "function") { + if (typeof this.socket.destroySoon === 'function') { this.socket.destroySoon(); } else { this.socket.destroy(); @@ -1544,7 +1544,7 @@ class ImapFlow extends EventEmitter { * @property {String} pathAsListed mailbox path as listed in the LIST/LSUB response * @property {String} name mailbox name (last part of path after delimiter) * @property {String} delimiter mailbox path delimiter, usually "." or "/" - * @property {Array} parent An array of parent folder names. All names are in unicode + * @property {String[]} parent An array of parent folder names. All names are in unicode * @property {String} parentPath Same as `parent`, but as a complete string path (unicode string) * @property {Set} flags a set of flags for this mailbox * @property {String} specialUse one of special-use flags (if applicable): "\All", "\Archive", "\Drafts", "\Flagged", "\Junk", "\Sent", "\Trash". Additionally INBOX has non-standard "\Inbox" flag set @@ -1553,22 +1553,27 @@ class ImapFlow extends EventEmitter { * @property {StatusObject} [status] If `statusQuery` was used, then this value includes the status response */ + /** + * @typedef {Object} ListOptions + * @global + * @property {Object} [statusQuery] request status items for every listed entry + * @property {Boolean} [statusQuery.messages] if `true` request count of messages + * @property {Boolean} [statusQuery.recent] if `true` request count of messages with \\Recent tag + * @property {Boolean} [statusQuery.uidNext] if `true` request predicted next UID + * @property {Boolean} [statusQuery.uidValidity] if `true` request mailbox `UIDVALIDITY` value + * @property {Boolean} [statusQuery.unseen] if `true` request count of unseen messages + * @property {Boolean} [statusQuery.highestModseq] if `true` request last known modseq value + * @property {Object} [specialUseHints] set specific paths as special use folders, this would override special use flags provided from the server + * @property {String} [specialUseHints.sent] Path to "Sent Mail" folder + * @property {String} [specialUseHints.trash] Path to "Trash" folder + * @property {String} [specialUseHints.junk] Path to "Junk Mail" folder + * @property {String} [specialUseHints.drafts] Path to "Drafts" folder + */ + /** * Lists available mailboxes as an Array * - * @param {Object} [options] defines additional listing options - * @param {Object} [options.statusQuery] request status items for every listed entry - * @param {Boolean} [options.statusQuery.messages] if `true` request count of messages - * @param {Boolean} [options.statusQuery.recent] if `true` request count of messages with \\Recent tag - * @param {Boolean} [options.statusQuery.uidNext] if `true` request predicted next UID - * @param {Boolean} [options.statusQuery.uidValidity] if `true` request mailbox `UIDVALIDITY` value - * @param {Boolean} [options.statusQuery.unseen] if `true` request count of unseen messages - * @param {Boolean} [options.statusQuery.highestModseq] if `true` request last known modseq value - * @param {Object} [options.specialUseHints] set specific paths as special use folders, this would override special use flags provided from the server - * @param {String} [options.specialUseHints.sent] Path to "Sent Mail" folder - * @param {String} [options.specialUseHints.trash] Path to "Trash" folder - * @param {String} [options.specialUseHints.junk] Path to "Junk Mail" folder - * @param {String} [options.specialUseHints.drafts] Path to "Drafts" folder + * @param {ListOptions} [options] defines additional listing options * @returns {Promise} An array of ListResponse objects * * @example @@ -1589,7 +1594,7 @@ class ImapFlow extends EventEmitter { * @property {String} path mailbox path * @property {String} name mailbox name (last part of path after delimiter) * @property {String} delimiter mailbox path delimiter, usually "." or "/" - * @property {array} flags list of flags for this mailbox + * @property {String[]} flags list of flags for this mailbox * @property {String} specialUse one of special-use flags (if applicable): "\All", "\Archive", "\Drafts", "\Flagged", "\Junk", "\Sent", "\Trash". Additionally INBOX has non-standard "\Inbox" flag set * @property {Boolean} listed `true` if mailbox was found from the output of LIST command * @property {Boolean} subscribed `true` if mailbox was found from the output of LSUB command @@ -1600,14 +1605,16 @@ class ImapFlow extends EventEmitter { /** * Lists available mailboxes as a tree structured object * + * @param {ListOptions} [options] defines additional listing options * @returns {Promise} Tree structured object * * @example * let tree = await client.listTree(); * tree.folders.forEach(mailbox=>console.log(mailbox.path)); */ - async listTree() { - let folders = await this.run('LIST', '', '*'); + async listTree(options) { + options = options || {}; + let folders = await this.run('LIST', '', '*', options); this.folders = new Map(folders.map(folder => [folder.path, folder])); return getFolderTree(folders); }