Fix confusing unseen mailbox count behavior

fork
Brian White 12 years ago
parent cd54142b15
commit 321387c0e6

@ -201,7 +201,7 @@ node-imap exposes one object: **ImapConnection**.
* **messages** - <_object_> Contains various message counts for this mailbox:
* **total** - <_integer_> - Total number of messages in this mailbox.
* **new** - <_integer_> - Number of messages in this mailbox having the Recent flag (this IMAP session is the first to see these messages).
* **unseen** - <_integer_> - Number of messages in this mailbox not having the Seen flag (marked as not having been read).
* **unseen** - <_integer_> - **(Only available with status() calls)** Number of messages in this mailbox not having the Seen flag (marked as not having been read).
* _ImapMessage_ is an object representing an email message. It consists of:
* Properties:
* **seqno** - <_integer_> - This message's sequence number. This number changes when messages with smaller sequence numbers are deleted for example (see the ImapConnection's 'deleted' event). This value is **always** available immediately.

@ -72,7 +72,7 @@ function ImapConnection (options) {
keywords: [],
permFlags: [],
name: null,
messages: { total: 0, new: 0, unseen: 0 }
messages: { total: 0, new: 0 }
},
ext: {
// Capability-specific state info
@ -415,7 +415,7 @@ ImapConnection.prototype.connect = function(loginCb) {
messages: {
total: 0,
new: 0,
unseen: 0
unseen: undefined
}
};
if (m.attributes) {
@ -469,9 +469,7 @@ ImapConnection.prototype.connect = function(loginCb) {
} else if (/^ALERT$/i.test(code))
self.emit('alert', m[3]);
else if (state.status === STATES.BOXSELECTING) {
if (m = /^UNSEEN (\d+)/i.exec(code))
state.box.messages.unseen = parseInt(m[1], 10);
else if (m = /^UIDVALIDITY (\d+)/i.exec(code))
if (m = /^UIDVALIDITY (\d+)/i.exec(code))
state.box.uidvalidity = parseInt(m[1], 10);
else if (m = /^UIDNEXT (\d+)/i.exec(code))
state.box.uidnext = parseInt(m[1], 10);
@ -869,48 +867,48 @@ ImapConnection.prototype._fetch = function(which, uids, options) {
options = {};
utils.extend(true, opts, options);
if (Array.isArray(opts.request.body)) {
var rangeInfo;
if (opts.request.body.length !== 2)
throw new Error("Expected Array of length 2 for body byte range");
else if (typeof opts.request.body[1] !== 'string'
|| !(rangeInfo = /^([\d]+)\-([\d]+)$/.exec(opts.request.body[1]))
|| parseInt(rangeInfo[1], 10) >= parseInt(rangeInfo[2], 10))
throw new Error("Invalid body byte range format");
bodyRange = '<' + parseInt(rangeInfo[1], 10) + '.'
+ parseInt(rangeInfo[2], 10) + '>';
opts.request.body = opts.request.body[0];
}
if (opts.request.headers !== false
&& typeof opts.request.body === 'boolean') {
if (Array.isArray(opts.request.headers))
onlyHeaders = opts.request.headers.join(' ').toUpperCase();
if (opts.request.body === true) {
// fetches the whole entire message (including some/all headers)
toFetch = '';
} else if (onlyHeaders) {
// fetch specific headers only
toFetch = 'HEADER.FIELDS (' + onlyHeaders + ')';
} else {
// fetches (all) headers only
toFetch = 'HEADER';
}
useParser = true;
} else if (opts.request.body === true) {
// fetches the whole entire message text (minus the headers), including
// all message parts
toFetch = 'TEXT';
} else if (typeof opts.request.body === 'string') {
if (opts.request.body.toUpperCase() === 'FULL') {
// fetches the whole entire message (including the headers)
// NOTE: does NOT parse the headers!
toFetch = '';
} else if (/^([\d]+[\.]{0,1})*[\d]+$/.test(opts.request.body)) {
// specific message part identifier, e.g. '1', '2', '1.1', '1.2', etc
toFetch = opts.request.body;
} else
throw new Error("Invalid body partID format");
if (Array.isArray(opts.request.body)) {
var rangeInfo;
if (opts.request.body.length !== 2)
throw new Error("Expected Array of length 2 for body byte range");
else if (typeof opts.request.body[1] !== 'string'
|| !(rangeInfo = /^([\d]+)\-([\d]+)$/.exec(opts.request.body[1]))
|| parseInt(rangeInfo[1], 10) >= parseInt(rangeInfo[2], 10))
throw new Error("Invalid body byte range format");
bodyRange = '<' + parseInt(rangeInfo[1], 10) + '.'
+ parseInt(rangeInfo[2], 10) + '>';
opts.request.body = opts.request.body[0];
}
if (opts.request.headers !== false
&& typeof opts.request.body === 'boolean') {
if (Array.isArray(opts.request.headers))
onlyHeaders = opts.request.headers.join(' ').toUpperCase();
if (opts.request.body === true) {
// fetches the whole entire message (including some/all headers)
toFetch = '';
} else if (onlyHeaders) {
// fetch specific headers only
toFetch = 'HEADER.FIELDS (' + onlyHeaders + ')';
} else {
// fetches (all) headers only
toFetch = 'HEADER';
}
useParser = true;
} else if (opts.request.body === true) {
// fetches the whole entire message text (minus the headers), including
// all message parts
toFetch = 'TEXT';
} else if (typeof opts.request.body === 'string') {
if (opts.request.body.toUpperCase() === 'FULL') {
// fetches the whole entire message (including the headers)
// NOTE: does NOT parse the headers!
toFetch = '';
} else if (/^([\d]+[\.]{0,1})*[\d]+$/.test(opts.request.body)) {
// specific message part identifier, e.g. '1', '2', '1.1', '1.2', etc
toFetch = opts.request.body;
} else
throw new Error("Invalid body partID format");
}
// always fetch GMail-specific bits of information when on GMail
if (this._serverSupports('X-GM-EXT-1'))
@ -1254,7 +1252,6 @@ 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