|
|
|
@ -187,7 +187,7 @@ ImapConnection.prototype.connect = function(loginCb) {
|
|
|
|
|
if (b.length === 0 || b.p >= b.length) return;
|
|
|
|
|
self.debug&&self.debug('\n<== ' + inspect(b.toString('binary', b.p)) + '\n');
|
|
|
|
|
|
|
|
|
|
var r, m, litType;
|
|
|
|
|
var r, m, litType, i, len, msg;
|
|
|
|
|
if (indata.expect > 0) {
|
|
|
|
|
r = read(b);
|
|
|
|
|
if (indata.streaming) {
|
|
|
|
@ -228,7 +228,7 @@ ImapConnection.prototype.connect = function(loginCb) {
|
|
|
|
|
if (indata.expect > -1) {
|
|
|
|
|
if ((m = /\* (\d+) FETCH/i.exec(indata.line))
|
|
|
|
|
&& /^BODY\[/i.test(litType)) {
|
|
|
|
|
var msg = new ImapMessage();
|
|
|
|
|
msg = new ImapMessage();
|
|
|
|
|
msg.seqno = parseInt(m[1], 10);
|
|
|
|
|
requests[0]._msg = msg;
|
|
|
|
|
requests[0]._fetcher.emit('message', msg);
|
|
|
|
@ -271,7 +271,7 @@ ImapConnection.prototype.connect = function(loginCb) {
|
|
|
|
|
switch (m.type) {
|
|
|
|
|
case 'FETCH':
|
|
|
|
|
// m.info = message details
|
|
|
|
|
var msg = (requests[0] && requests[0]._msg
|
|
|
|
|
msg = (requests[0] && requests[0]._msg
|
|
|
|
|
? requests[0]._msg
|
|
|
|
|
: new ImapMessage());
|
|
|
|
|
parsers.parseFetch(m.info, indata.literals, msg);
|
|
|
|
@ -383,7 +383,7 @@ ImapConnection.prototype.connect = function(loginCb) {
|
|
|
|
|
var path = name.split(box.delimiter).filter(utils.isNotEmpty),
|
|
|
|
|
parent = null;
|
|
|
|
|
name = path.pop();
|
|
|
|
|
for (var i=0,len=path.length; i<len; i++) {
|
|
|
|
|
for (i=0,len=path.length; i<len; i++) {
|
|
|
|
|
if (!curChildren[path[i]])
|
|
|
|
|
curChildren[path[i]] = {};
|
|
|
|
|
if (!curChildren[path[i]].children)
|
|
|
|
@ -418,7 +418,7 @@ ImapConnection.prototype.connect = function(loginCb) {
|
|
|
|
|
};
|
|
|
|
|
if (m.attributes) {
|
|
|
|
|
m.attributes = parsers.parseExpr(m.attributes, indata.literals);
|
|
|
|
|
for (var i=0,len=m.attributes.length; i<len; ++i) {
|
|
|
|
|
for (i=0,len=m.attributes.length; i<len; ++i) {
|
|
|
|
|
switch (m.attributes[i].toUpperCase()) {
|
|
|
|
|
case 'RECENT':
|
|
|
|
|
ret.messages.new = parseInt(m.attributes[++i], 10);
|
|
|
|
@ -483,7 +483,7 @@ ImapConnection.prototype.connect = function(loginCb) {
|
|
|
|
|
state.box.keywords = keywords = permFlags.filter(function(f) {
|
|
|
|
|
return (f[0] !== '\\');
|
|
|
|
|
});
|
|
|
|
|
for (var i=0,len=keywords.length; i<len; ++i)
|
|
|
|
|
for (i=0,len=keywords.length; i<len; ++i)
|
|
|
|
|
permFlags.splice(permFlags.indexOf(keywords[i]), 1);
|
|
|
|
|
state.box.permFlags = permFlags.map(function(f) {
|
|
|
|
|
return f.substr(1);
|
|
|
|
@ -971,38 +971,39 @@ ImapConnection.prototype.delKeywords = function(uids, flags, 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);
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
@ -1168,7 +1169,7 @@ ImapConnection.prototype._store = function(which, uids, flags, isAdding, cb) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isKeywords)
|
|
|
|
|
flags = flags.map(function(flag) {return '\\' + flag;})
|
|
|
|
|
flags = flags.map(function(flag) {return '\\' + flag;});
|
|
|
|
|
flags = flags.join(' ');
|
|
|
|
|
cb = arguments[arguments.length-1];
|
|
|
|
|
|
|
|
|
@ -1198,7 +1199,8 @@ ImapConnection.prototype._login = function(cb) {
|
|
|
|
|
if (this._serverSupports('AUTH=XOAUTH') && 'xoauth' in this._options) {
|
|
|
|
|
this._send('AUTHENTICATE XOAUTH ' + utils.escape(this._options.xoauth),
|
|
|
|
|
fnReturn);
|
|
|
|
|
} else if (this._serverSupports('AUTH=XOAUTH2') && 'xoauth2' in this._options) {
|
|
|
|
|
} else if (this._serverSupports('AUTH=XOAUTH2')
|
|
|
|
|
&& 'xoauth2' in this._options) {
|
|
|
|
|
this._send('AUTHENTICATE XOAUTH2 ' + utils.escape(this._options.xoauth2),
|
|
|
|
|
fnReturn);
|
|
|
|
|
} else if (this._options.username !== undefined
|
|
|
|
@ -1264,8 +1266,8 @@ ImapConnection.prototype._send = function(cmdstr, cb, bypass) {
|
|
|
|
|
cbargs: []
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (this._state.ext.idle.state === IDLE_WAIT ||
|
|
|
|
|
(this._state.ext.idle.state == IDLE_DONE && cmdstr !== 'DONE'))
|
|
|
|
|
if (this._state.ext.idle.state === IDLE_WAIT
|
|
|
|
|
|| (this._state.ext.idle.state === IDLE_DONE && cmdstr !== 'DONE'))
|
|
|
|
|
return;
|
|
|
|
|
if ((cmdstr === undefined && this._state.requests.length)
|
|
|
|
|
|| this._state.requests.length === 1 || bypass) {
|
|
|
|
|