Skip to content
Browse files

Merge pull request #116 from wavify/unseen-count

Add unread count to Box object
  • Loading branch information...
2 parents 507ea83 + 009ccc6 commit 876a212ab6594a5267dfe20d80f096acefcb7f5c @mscdex committed Oct 4, 2012
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/imap.js
View
15 lib/imap.js
@@ -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() {

0 comments on commit 876a212

Please sign in to comment.
Something went wrong with that request. Please try again.