From 1e020b47c12a5ee703609f868d804cbe2b6bc947 Mon Sep 17 00:00:00 2001 From: mscdex Date: Sun, 7 Apr 2013 11:03:22 -0400 Subject: [PATCH] cache part id check regexp and perform type check in object(s) passed to fetch() --- lib/imap.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/imap.js b/lib/imap.js index 8f842ab..3b236b2 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -28,6 +28,7 @@ var CRLF = '\r\n', RE_TEXT_CODE = /([^ ]+)(?: (.*))?$/, RE_RES_IDLE = /^IDLE /i, RE_RES_NOOP = /^NOOP /i, + RE_PARTID = /^(?:[\d]+[\.]{0,1})*[\d]+$/, //RE_ISPARTIAL = /<(\d+)>$/, RE_DBLQ = /"/g, RE_CMD = /^([^ ]+)(?: |$)/, @@ -1045,9 +1046,9 @@ ImapConnection.prototype._fetch = function(which, uids, options, what, cb) { for (var i = 0, wp, pprefix, len = what.length; i < len; ++i) { wp = what[i]; parse = true; - if (wp.id !== undefined && !/^(?:[\d]+[\.]{0,1})*[\d]+$/.test(''+wp.id)) + if (wp.id !== undefined && !RE_PARTID.test(''+wp.id)) throw new Error('Invalid part id: ' + wp.id); - if (( (wp.headers + if (( (typeof wp.headers === 'object' && (!wp.headers.fields || (Array.isArray(wp.headers.fields) && wp.headers.fields.length === 0) @@ -1055,7 +1056,7 @@ ImapConnection.prototype._fetch = function(which, uids, options, what, cb) { && wp.headers.parse === false ) || - (wp.headersNot + (typeof wp.headersNot === 'object' && (!wp.headersNot.fields || (Array.isArray(wp.headersNot.fields) && wp.headersNot.fields.length === 0)