From 295d6ffd064fa6365db3abd5e18becefd590b2cd Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Fri, 21 Sep 2012 12:31:56 -0700 Subject: [PATCH 1/2] Added support to add/remove X-GM-LABELS --- README.md | 6 ++++++ lib/imap.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/README.md b/README.md index d08cfcf..bd26a3f 100644 --- a/README.md +++ b/README.md @@ -596,6 +596,12 @@ ImapConnection Functions * **delKeywords**(<_mixed_>source, <_mixed_>keywords, <_function_>callback) - _(void)_ - Removes keyword(s) from message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. keywords is either a single keyword or an array of keywords. The callback has one parameter: the error (falsey if none). +* **setLabels**(<_mixed_>source, <_mixed_>labels, <_function_>callback) - _(void)_ - When X-GM-EXT1 capability present, replaces labels(s) of message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. labels is either a single label or an array of labels. The callback has one parameter: the error (falsey if none). + +* **addLabels**(<_mixed_>source, <_mixed_>labels, <_function_>callback) - _(void)_ - When X-GM-EXT1 capability present, adds labels(s) to message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. labels is either a single label or an array of labels. The callback has one parameter: the error (falsey if none). + +* **delLabels**(<_mixed_>source, <_mixed_>labels, <_function_>callback) - _(void)_ - When X-GM-EXT1 capability present, removes labels(s) from message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. labels is either a single label or an array of labels. The callback has one parameter: the error (falsey if none). + Extensions Supported -------------------- diff --git a/lib/imap.js b/lib/imap.js index 4bf4928..10df32d 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -962,6 +962,41 @@ ImapConnection.prototype.delKeywords = function(uids, flags, cb) { this._store('UID ', uids, flags, false, cb); }; +ImapConnection.prototype.setLabels = function(uids, labels, cb) { + this._storeLabels('UID ', uids, labels, '', cb); +} + +ImapConnection.prototype.addLabels = function(uids, labels, cb) { + this._storeLabels('UID ', uids, labels, '+', cb); +} + +ImapConnection.prototype.delLabels = function(uids, labels, cb) { + this._storeLabels('UID ', uids, labels, '-', cb); +} + +ImapConnection.prototype._storeLabels = function(which, uids, labels, mode, cb) { + if (!this._serverSupports('X-GM-EXT-1')) + throw new Error('Server must support X-GM-EXT-1 capability'); + if (this._state.status !== STATES.BOXSELECTED) + throw new Error('No mailbox is currently selected'); + if (uids === undefined) + throw new Error('The message ID(s) must be specified'); + + if (!Array.isArray(uids)) + uids = [uids]; + utils.validateUIDList(uids); + + if ((!Array.isArray(labels) && typeof labels !== 'string') + || (Array.isArray(labels) && labels.length === 0)) + throw new Error('labels argument must be a string or a non-empty Array'); + if (!Array.isArray(labels)) + labels = [labels]; + labels = labels.join(' '); + cb = arguments[arguments.length-1]; + + this._send(which + 'STORE ' + uids.join(',') + ' ' + mode + 'X-GM-LABELS.SILENT (' + labels + ')', cb); +} + ImapConnection.prototype.copy = function(uids, boxTo, cb) { return this._copy('UID ', uids, boxTo, cb); }; @@ -1059,6 +1094,15 @@ ImapConnection.prototype.__defineGetter__('seq', function() { addFlags: function(seqnos, flags, cb) { self._store('', seqnos, flags, true, cb); }, + delLabels: function(seqnos, labels, cb) { + self._storeLabels('', seqnos, labels, '-', cb); + }, + addLabels: function(seqnos, labels, cb) { + self._storeLabels('', seqnos, labels, '+', cb); + }, + setLabels: function(seqnos, labels, cb) { + self._storeLabels('', seqnos, labels, '', cb); + }, fetch: function(seqnos, options) { return self._fetch('', seqnos, options); }, From 12d979f976f7e0447cc1c06204dc7893477c02ca Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Fri, 21 Sep 2012 13:46:50 -0700 Subject: [PATCH 2/2] Move APIs to Gmail Extensions --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bd26a3f..813bd98 100644 --- a/README.md +++ b/README.md @@ -596,12 +596,6 @@ ImapConnection Functions * **delKeywords**(<_mixed_>source, <_mixed_>keywords, <_function_>callback) - _(void)_ - Removes keyword(s) from message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. keywords is either a single keyword or an array of keywords. The callback has one parameter: the error (falsey if none). -* **setLabels**(<_mixed_>source, <_mixed_>labels, <_function_>callback) - _(void)_ - When X-GM-EXT1 capability present, replaces labels(s) of message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. labels is either a single label or an array of labels. The callback has one parameter: the error (falsey if none). - -* **addLabels**(<_mixed_>source, <_mixed_>labels, <_function_>callback) - _(void)_ - When X-GM-EXT1 capability present, adds labels(s) to message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. labels is either a single label or an array of labels. The callback has one parameter: the error (falsey if none). - -* **delLabels**(<_mixed_>source, <_mixed_>labels, <_function_>callback) - _(void)_ - When X-GM-EXT1 capability present, removes labels(s) from message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. labels is either a single label or an array of labels. The callback has one parameter: the error (falsey if none). - Extensions Supported -------------------- @@ -622,6 +616,11 @@ Extensions Supported * fetch() will automatically retrieve the thread id, unique message id, and labels with the message properties being 'x-gm-thrid', 'x-gm-msgid', 'x-gm-labels' respectively + * Additional ImapConnection Functions + * **setLabels**(<_mixed_>source, <_mixed_>labels, <_function_>callback) - _(void)_ - Replaces labels(s) of message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. labels is either a single label or an array of labels. The callback has one parameter: the error (falsey if none). + * **addLabels**(<_mixed_>source, <_mixed_>labels, <_function_>callback) - _(void)_ - Adds labels(s) to message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. labels is either a single label or an array of labels. The callback has one parameter: the error (falsey if none). + * **delLabels**(<_mixed_>source, <_mixed_>labels, <_function_>callback) - _(void)_ - Removes labels(s) from message(s). source can be a message UID, a message UID range (e.g. '2504:2507' or '\*' or '2504:\*'), or an array of message UIDs and/or message UID ranges. labels is either a single label or an array of labels. The callback has one parameter: the error (falsey if none). + TODO ----