Merge pull request #116 from wavify/unseen-count

Add unread count to Box object
fork
Brian White 12 years ago
commit 876a212ab6

@ -71,7 +71,7 @@ function ImapConnection (options) {
keywords: [],
permFlags: [],
name: null,
messages: { total: 0, new: 0 }
messages: { total: 0, new: 0, unseen: 0 }
},
ext: {
// Capability-specific state info
@ -412,7 +412,8 @@ ImapConnection.prototype.connect = function(loginCb) {
uidvalidity: undefined,
messages: {
total: undefined,
new: undefined
new: undefined,
unseen: undefined
}
};
if (m.attributes) {
@ -422,6 +423,9 @@ ImapConnection.prototype.connect = function(loginCb) {
case 'RECENT':
ret.messages.new = parseInt(m.attributes[++i], 10);
break;
case 'UNSEEN':
ret.messages.unseen = parseInt(m.attributes[++i], 10);
break;
case 'MESSAGES':
ret.messages.total = parseInt(m.attributes[++i], 10);
break;
@ -463,7 +467,9 @@ ImapConnection.prototype.connect = function(loginCb) {
} else if (/^ALERT$/i.test(code))
self.emit('alert', m[3]);
else if (state.status === STATES.BOXSELECTING) {
if (m = /^UIDVALIDITY (\d+)/i.exec(code))
if (m = /^UNSEEN (\d+)/i.exec(code))
state.box.messages.unseen = parseInt(m[1], 10);
else if (m = /^UIDVALIDITY (\d+)/i.exec(code))
state.box.uidvalidity = m[1];
else if (m = /^UIDNEXT (\d+)/i.exec(code))
state.box.uidnext = m[1];
@ -671,7 +677,7 @@ ImapConnection.prototype.status = function(boxName, cb) {
var cmd = 'STATUS "';
cmd += utils.escape(boxName);
cmd += '" (MESSAGES RECENT UIDVALIDITY)';
cmd += '" (MESSAGES RECENT UNSEEN UIDVALIDITY)';
this._send(cmd, cb);
};
@ -1238,6 +1244,7 @@ ImapConnection.prototype._resetBox = function() {
this._state.box.name = null;
this._state.box.messages.total = 0;
this._state.box.messages.new = 0;
this._state.box.messages.unseen = 0;
};
ImapConnection.prototype._noop = function() {

Loading…
Cancel
Save