Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unread count to Box object #116

Merged
merged 2 commits into from Oct 4, 2012
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/imap.js
Expand Up @@ -412,7 +412,8 @@ ImapConnection.prototype.connect = function(loginCb) {
uidvalidity: undefined,
messages: {
total: undefined,
new: undefined
new: undefined,
unseen: undefined
}
};
if (m.attributes) {
Expand All @@ -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;
Expand Down Expand Up @@ -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.unseen = m[1];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be parsed as an integer like above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also should be in state.box.messages.unseen. I'll fix it.

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];
Expand Down Expand Up @@ -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);
};
Expand Down