From 7cf54ed371bd14b389c7a77ea3fa61bd8e3a3c27 Mon Sep 17 00:00:00 2001 From: mscdex Date: Wed, 9 Jan 2013 14:02:34 -0500 Subject: [PATCH] do more utf7 encoding and decoding for mailbox names --- lib/imap.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/imap.js b/lib/imap.js index cc3e99d..e4cde20 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -377,7 +377,7 @@ ImapConnection.prototype.connect = function(loginCb) { now = parseInt(m.num, 10); state.box.messages.total = now; if (state.status !== STATES.BOXSELECTING && now > prev) { - state.box.messages.new = now-prev; + state.box.messages.new = now - prev; self.emit('mail', state.box.messages.new); // new mail } break; @@ -428,7 +428,7 @@ ImapConnection.prototype.connect = function(loginCb) { // m.mailbox = mailbox name (string) m.flags = (m.flags ? m.flags.toUpperCase().split(' ') : []); m.delimiter = parsers.convStr(m.delimiter, indata.literals); - m.mailbox = '' + parsers.convStr(m.mailbox, indata.literals); + m.mailbox = utf7.decode(''+parsers.convStr(m.mailbox, indata.literals)); if (self.delimiter === undefined) self.delimiter = parsers.convStr(m.delimiter, indata.literals); else { @@ -475,7 +475,7 @@ ImapConnection.prototype.connect = function(loginCb) { case 'STATUS': // m.mailbox = mailbox name (string) // m.attributes = expression list (k=>v pairs) of mailbox attributes - m.mailbox = '' + parsers.convStr(m.mailbox, indata.literals); + m.mailbox = utf7.decode(''+parsers.convStr(m.mailbox, indata.literals)); var ret = { name: m.mailbox, uidvalidity: 0, @@ -739,11 +739,12 @@ ImapConnection.prototype.openBox = function(name, readOnly, cb) { readOnly = false; } + name = ''+name; this._state.box.name = name; this._state.box.displayName = utf7.decode(name); - this._send((readOnly ? 'EXAMINE' : 'SELECT') + ' "' + utils.escape(name) - + '"', cb); + this._send((readOnly ? 'EXAMINE' : 'SELECT') + ' "' + + utils.escape(utf7.encode(name)) + '"', cb); }; // also deletes any messages in this box marked with \Deleted @@ -766,7 +767,7 @@ ImapConnection.prototype.status = function(boxName, cb) { throw new Error('Not allowed to call status on the currently selected mailbox'); var cmd = 'STATUS "'; - cmd += utils.escape(boxName); + cmd += utils.escape(utf7.encode(''+boxName)); cmd += '" (MESSAGES RECENT UNSEEN UIDVALIDITY)'; this._send(cmd, cb); @@ -777,9 +778,10 @@ ImapConnection.prototype.removeDeleted = function(cb) { }; ImapConnection.prototype.getBoxes = function(namespace, cb) { - cb = arguments[arguments.length - 1]; - if (arguments.length !== 2) + if (typeof namespace === 'function') { + cb = namespace; namespace = ''; + } this._send((!this._serverSupports('XLIST') ? 'LIST' : 'XLIST') + ' "' + utils.escape(namespace) + '" "*"', cb); }; @@ -789,7 +791,7 @@ ImapConnection.prototype.addBox = function(name, cb) { }; ImapConnection.prototype.delBox = function(name, cb) { - this._send('DELETE "' + utils.escape(''+name) + '"', cb); + this._send('DELETE "' + utils.escape(utf7.encode(''+name)) + '"', cb); }; ImapConnection.prototype.renameBox = function(oldname, newname, cb) { @@ -798,9 +800,9 @@ ImapConnection.prototype.renameBox = function(oldname, newname, cb) { this._state.box._newName = ''+oldname; var cmd = 'RENAME "'; - cmd += utils.escape(''+oldname); + cmd += utils.escape(utf7.encode(''+oldname)); cmd += '" "'; - cmd += utils.escape(''+newname); + cmd += utils.escape(utf7.encode(''+newname)); cmd += '"'; this._send(cmd, cb); }; @@ -817,7 +819,7 @@ ImapConnection.prototype.append = function(data, options, cb) { else options.mailbox = this._state.box.name; } - var cmd = 'APPEND "' + utils.escape(options.mailbox) + '"'; + var cmd = 'APPEND "' + utils.escape(utf7.encode(''+options.mailbox)) + '"'; if (options.flags) { if (!Array.isArray(options.flags)) options.flags = [options.flags]; @@ -1214,8 +1216,8 @@ ImapConnection.prototype._copy = function(which, uids, boxTo, cb) { utils.validateUIDList(uids); - this._send(which + 'COPY ' + uids.join(',') + ' "' + utils.escape(boxTo) - + '"', cb); + this._send(which + 'COPY ' + uids.join(',') + ' "' + + utils.escape(utf7.encode(''+boxTo)) + '"', cb); }; ImapConnection.prototype.move = function(uids, boxTo, cb) {