Merge pull request #307 from dominikgehl/dgl/idExtension

support for IMAP ID extension (RFC 2971)
fork
Brian White 11 years ago
commit 9f5ba4de8c

@ -307,6 +307,29 @@ Connection.prototype.getBoxes = function(namespace, cb) {
this._enqueue('LIST "' + namespace + '" "*"', cb);
};
Connection.prototype.id = function(identification, cb) {
if (!this.serverSupports('ID'))
throw new Error('Server does not support ID');
var cmd = 'ID';
if ((identification === null) || (Object.keys(identification).length === 0))
cmd += ' NIL';
else {
if (Object.keys(identification).length > 30)
throw new Error('Max allowed number of keys is 30');
var kv = [];
for (var k in identification) {
if (Buffer.byteLength(k) > 30)
throw new Error('Max allowed key length is 30');
if (Buffer.byteLength(identification[k]) > 1024)
throw new Error('Max allowed value length is 1024');
kv.push('"' + escape(k) + '"');
kv.push('"' + escape(identification[k]) + '"');
}
cmd += ' (' + kv.join(' ') + ')';
}
this._enqueue(cmd, cb);
};
Connection.prototype.openBox = function(name, readOnly, cb) {
if (this.state !== 'authenticated')
throw new Error('Not authenticated');
@ -1094,6 +1117,8 @@ Connection.prototype._resUntagged = function(info) {
this._sock.end();
else if (type === 'namespace')
this.namespaces = info.text;
else if (type === 'id')
this._curReq.cbargs.push(info.text);
else if (type === 'capability')
this._caps = info.text.map(function(v) { return v.toUpperCase(); });
else if (type === 'preauth')

@ -14,7 +14,7 @@ var CH_LF = 10,
RE_SEQNO = /^\* (\d+)/,
RE_LISTCONTENT = /^\((.*)\)$/,
RE_LITERAL = /\{(\d+)\}$/,
RE_UNTAGGED = /^\* (?:(OK|NO|BAD|BYE|FLAGS|LIST|LSUB|SEARCH|STATUS|CAPABILITY|NAMESPACE|PREAUTH|SORT|THREAD|ESEARCH|QUOTA|QUOTAROOT)|(\d+) (EXPUNGE|FETCH|RECENT|EXISTS))(?: (?:\[([^\]]+)\] )?(.+))?$/i,
RE_UNTAGGED = /^\* (?:(OK|NO|BAD|BYE|FLAGS|ID|LIST|LSUB|SEARCH|STATUS|CAPABILITY|NAMESPACE|PREAUTH|SORT|THREAD|ESEARCH|QUOTA|QUOTAROOT)|(\d+) (EXPUNGE|FETCH|RECENT|EXISTS))(?: (?:\[([^\]]+)\] )?(.+))?$/i,
RE_TAGGED = /^A(\d+) (OK|NO|BAD) (?:\[([^\]]+)\] )?(.+)$/i,
RE_CONTINUE = /^\+(?: (?:\[([^\]]+)\] )?(.+))?$/i,
RE_CRLF = /\r\n/g,
@ -249,6 +249,8 @@ Parser.prototype._resUntagged = function() {
val = [];
} else if (type === 'list' || type === 'lsub')
val = parseBoxList(m[5], this._literals);
else if (type === 'id')
val = parseId(m[5], this._literals);
else if (type === 'status')
val = parseStatus(m[5], this._literals);
else if (type === 'fetch')
@ -329,6 +331,17 @@ function parseESearch(text, literals) {
return attrs;
}
function parseId(text, literals) {
var r = parseExpr(text, literals),
id = {};
if (r[0] === null)
return null;
for (var i = 0, len = r[0].length; i < len; i += 2)
id[r[0][i].toLowerCase()] = r[0][i + 1]
return id;
}
function parseQuota(text, literals) {
var r = parseExpr(text, literals),
resources = {};

Loading…
Cancel
Save