From c1e29d131a4306221f03c361564f343f62017d70 Mon Sep 17 00:00:00 2001 From: Brian White Date: Tue, 11 Sep 2012 11:49:12 -0400 Subject: [PATCH] Style changes and fix function references --- lib/imap.utilities.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/imap.utilities.js b/lib/imap.utilities.js index cba6bab..929d0e6 100644 --- a/lib/imap.utilities.js +++ b/lib/imap.utilities.js @@ -64,7 +64,7 @@ exports.extend = function() { } // Handle case when target is a string or something (possible in deep copy) - if (typeof target !== "object" && !typeof target === 'function') + if (typeof target !== "object" && typeof target !== 'function') target = {}; var isPlainObject = function(obj) { @@ -127,15 +127,15 @@ exports.extend = function() { exports.isNotEmpty = function(str) { return str.trim().length > 0; -} +}; exports.escape = function(str) { return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); -} +}; exports.unescape = function(str) { return str.replace(/\\"/g, '"').replace(/\\\\/g, '\\'); -} +}; exports.buildSearchQuery = function(options, extensions, isOrChild) { var searchargs = ''; @@ -157,9 +157,9 @@ exports.buildSearchQuery = function(options, extensions, isOrChild) { if (args.length !== 2) throw new Error('OR must have exactly two arguments'); searchargs += ' OR ('; - searchargs += buildSearchQuery(args[0], extensions, true); + searchargs += exports.buildSearchQuery(args[0], extensions, true); searchargs += ') ('; - searchargs += buildSearchQuery(args[1], extensions, true); + searchargs += exports.buildSearchQuery(args[1], extensions, true); searchargs += ')'; } else { if (criteria[0] === '!') { @@ -194,7 +194,8 @@ exports.buildSearchQuery = function(options, extensions, isOrChild) { if (!args || args.length !== 1) throw new Error('Incorrect number of arguments for search option: ' + criteria); - searchargs += modifier + criteria + ' "' + escape(''+args[0]) + '"'; + searchargs += modifier + criteria + ' "' + exports.escape(''+args[0]) + + '"'; break; case 'BEFORE': case 'ON': @@ -226,7 +227,7 @@ exports.buildSearchQuery = function(options, extensions, isOrChild) { if (!args || args.length !== 1) throw new Error('Incorrect number of arguments for search option: ' + criteria); - var num = parseInt(args[0]); + var num = parseInt(args[0], 10); if (isNaN(num)) throw new Error('Search option argument must be a number'); searchargs += modifier + criteria + ' ' + args[0]; @@ -235,8 +236,8 @@ exports.buildSearchQuery = function(options, extensions, isOrChild) { if (!args || args.length !== 2) throw new Error('Incorrect number of arguments for search option: ' + criteria); - searchargs += modifier + criteria + ' "' + escape(''+args[0]) + '" "' - + escape(''+args[1]) + '"'; + searchargs += modifier + criteria + ' "' + exports.escape(''+args[0]) + + '" "' + exports.escape(''+args[1]) + '"'; break; case 'UID': if (!args) @@ -267,7 +268,8 @@ exports.buildSearchQuery = function(options, extensions, isOrChild) { if (!args || args.length !== 1) throw new Error('Incorrect number of arguments for search option: ' + criteria); - searchargs += modifier + criteria + ' "' + escape(''+args[0]) + '"'; + searchargs += modifier + criteria + ' "' + exports.escape(''+args[0]) + + '"'; break; case 'X-GM-LABELS': // Gmail labels if (extensions.indexOf('X-GM-EXT-1') === -1) @@ -293,7 +295,7 @@ exports.buildSearchQuery = function(options, extensions, isOrChild) { break; } return searchargs; -} +}; exports.validateUIDList = function(uids) { for (var i=0,len=uids.length,intval; i