Skip to content

Commit

Permalink
fix(listTree): pass listing options as an optional argument
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed May 6, 2024
1 parent 569b17b commit 917ba80
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions lib/imap-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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<string>} 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<string>} 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
Expand All @@ -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<ListResponse[]>} An array of ListResponse objects
*
* @example
Expand All @@ -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
Expand All @@ -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<ListTreeResponse>} 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);
}
Expand Down

0 comments on commit 917ba80

Please sign in to comment.