Merge pull request #107 from Contatta/addDel-Labels

Added support to add/remove/store X-GM-LABELS
fork
Brian White 12 years ago
commit 49e85a43ec

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

@ -963,6 +963,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);
};
@ -1060,6 +1095,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