From b697dfe66d6cbfdded6ba6011effed05b1e17f88 Mon Sep 17 00:00:00 2001 From: Dominik Gehl Date: Fri, 4 Oct 2013 21:29:49 -0400 Subject: [PATCH] support for IMAP ID extension (RFC 2971) --- lib/Connection.js | 11 +++++++++++ lib/Parser.js | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Connection.js b/lib/Connection.js index 73a7e2e..afd5bf4 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -306,6 +306,15 @@ 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'); + cmd = ''; + for (var k in identification) + cmd += '"' + k + '" "' + identification[k] + '"'; + return this._enqueue('ID (' + cmd + ')', cb); +} + Connection.prototype.openBox = function(name, readOnly, cb) { if (this.state !== 'authenticated') throw new Error('Not authenticated'); @@ -1093,6 +1102,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') diff --git a/lib/Parser.js b/lib/Parser.js index 4e8c807..6658d12 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -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 = {}; + + 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 = {};