Add UTF-7 support where needed for mailbox names

fork
Brian White 12 years ago
parent c270a7054a
commit ec01e96e2b

@ -194,6 +194,7 @@ node-imap exposes one object: **ImapConnection**.
* _Box_ is an object representing the currently open mailbox, and has the following properties:
* **name** - < _string_ > - The name of this mailbox.
* **displayName** - < _string_ > - The UTF-7-decoded name of this mailbox.
* **readOnly** - < _boolean_ > - True if this mailbox was opened in read-only mode.
* **uidvalidity** - < _integer_ > - A 32-bit number that can be used to determine if UIDs in this mailbox have changed since the last time this mailbox was opened. It is possible for this to change during a session, in which case a 'uidvalidity' event will be emitted on the ImapConnection instance.
* **uidnext** - < _integer_ > - The uid that will be assigned to the next message that arrives at this mailbox.
@ -416,6 +417,7 @@ ImapConnection Functions
{ INBOX: // mailbox name
{ attribs: [] // mailbox attributes. An attribute of 'NOSELECT' indicates the mailbox cannot
// be opened
, displayName: 'INBOX' // the UTF-7-decoded version of the mailbox name
, delimiter: '/' // hierarchy delimiter for accessing this mailbox's direct children.
, children: null // an object containing another structure similar in format to this top level,
// otherwise null if no children

@ -3,6 +3,7 @@ var assert = require('assert'),
inherits = require('util').inherits,
Socket = require('net').Socket,
EventEmitter = require('events').EventEmitter,
utf7 = require('utf7').imap,
MIMEParser = require('./mimeparser'),
XRegExp = require('./xregexp').XRegExp;
@ -73,7 +74,8 @@ function ImapConnection (options) {
keywords: [],
permFlags: [],
name: null,
messages: { total: 0, new: 0 }
messages: { total: 0, new: 0 },
_newName: undefined
},
ext: {
// Capability-specific state info
@ -392,6 +394,7 @@ ImapConnection.prototype.connect = function(loginCb) {
return attr.substr(1);
}),
delimiter: m.delimiter,
displayName: undefined,
children: null,
parent: null
},
@ -412,6 +415,7 @@ ImapConnection.prototype.connect = function(loginCb) {
}
box.parent = parent;
}
box.displayName = utf7.decode(name);
if (!curChildren[name])
curChildren[name] = box;
}
@ -569,8 +573,11 @@ ImapConnection.prototype.connect = function(loginCb) {
}
if (requests[0].cmd === 'RENAME') {
state.box.name = state.box._newName;
delete state.box._newName;
if (state.box._newName) {
state.box.name = state.box._newName;
state.box.displayName = utf7.decode(state.box.name);
state.box._newName = undefined;
}
sendBox = true;
}
@ -684,6 +691,7 @@ ImapConnection.prototype.openBox = function(name, readOnly, cb) {
}
this._state.box.name = name;
this._state.box.displayName = utf7.decode(name);
this._send((readOnly ? 'EXAMINE' : 'SELECT') + ' "' + utils.escape(name)
+ '"', cb);
@ -736,7 +744,7 @@ ImapConnection.prototype.addBox = function(name, cb) {
if (typeof name !== 'string' || name.length === 0)
throw new Error('Mailbox name must be a string describing the full path'
+ ' of a new mailbox to be created');
this._send('CREATE "' + utils.escape(name) + '"', cb);
this._send('CREATE "' + utils.escape(utf7.encode(name)) + '"', cb);
};
ImapConnection.prototype.delBox = function(name, cb) {
@ -1286,7 +1294,9 @@ ImapConnection.prototype._resetBox = function() {
this._state.box.uidvalidity = 0;
this._state.box.permFlags = [];
this._state.box.keywords = [];
this._state.box.name = null;
this._state.box.name = undefined;
this._State.box.displayName = undefined;
this._State.box._newName = undefined;
this._state.box.messages.total = 0;
this._state.box.messages.new = 0;
};

@ -4,7 +4,10 @@
"description": "An IMAP module for node.js that makes communicating with IMAP servers easy",
"main": "./lib/imap",
"engines": { "node" : ">=0.4.0" },
"dependencies": {
"utf7": "1.0.0"
},
"keywords": [ "imap", "mail", "email", "reader", "client" ],
"licenses": [ { "type": "MIT", "url": "http://github.com/mscdex/node-imap/raw/master/LICENSE" } ],
"repository" : { "type": "git", "url": "http://github.com/mscdex/node-imap.git" }
"repository": { "type": "git", "url": "http://github.com/mscdex/node-imap.git" }
}
Loading…
Cancel
Save