Added support to add/remove X-GM-LABELS

fork
Stuart Carnie 12 years ago
parent 867d6dfc4a
commit 295d6ffd06

@ -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
--------------------

@ -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);
},

Loading…
Cancel
Save