Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Convert other logic to use only ES5 syntax.
Browse files Browse the repository at this point in the history
Ported from vingtetun's branch by asuth.
  • Loading branch information
vingtetun authored and asutherland committed Feb 23, 2013
1 parent dd14e10 commit 46699fd
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 150 deletions.
6 changes: 3 additions & 3 deletions data/lib/mailapi/a64.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define(
* JS coders) ordering which makes it tractable to eyeball an encoded value and
* not be completely confused/misled.
*/
const ORDERED_ARBITRARY_BASE64_CHARS = [
var ORDERED_ARBITRARY_BASE64_CHARS = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
Expand All @@ -35,7 +35,7 @@ const ORDERED_ARBITRARY_BASE64_CHARS = [
* Zero padding to get us up to the maximum encoding length of a 64-bit value in
* our encoding (11) or for decimal re-conversion (16).
*/
const ZERO_PADDING = '0000000000000000';
var ZERO_PADDING = '0000000000000000';

/**
* Encode a JS int in our base64 encoding.
Expand All @@ -61,7 +61,7 @@ exports.encodeInt = encodeInt;
* 10^14 >> 14 so that its 'lowest' binary 1 ends up in the one's place. It
* is encoded in 33 bits itself.
*/
const E10_14_RSH_14 = Math.pow(10, 14) / Math.pow(2, 14),
var E10_14_RSH_14 = Math.pow(10, 14) / Math.pow(2, 14),
P2_14 = Math.pow(2, 14),
P2_22 = Math.pow(2, 22),
P2_32 = Math.pow(2, 32),
Expand Down
56 changes: 32 additions & 24 deletions data/lib/mailapi/accountcommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ var autoconfigByDomain = exports._autoconfigByDomain = {
* @return the new identities
*/
function recreateIdentities(universe, accountId, oldIdentities) {
let identities = [];
for (let [,oldIdentity] in Iterator(oldIdentities)) {
var identities = [];
for (var iter in Iterator(oldIdentities)) {
var oldIdentity = iter[1];
identities.push({
id: accountId + '/' + $a64.encodeInt(universe.config.nextIdentityNum++),
name: oldIdentity.name,
Expand Down Expand Up @@ -231,7 +232,7 @@ Autoconfigurator.prototype = {
* info, formatted as JSON
*/
_getXmlConfig: function getXmlConfig(url, callback) {
let xhr = new XMLHttpRequest({mozSystem: true});
var xhr = new XMLHttpRequest({mozSystem: true});
xhr.open('GET', url, true);
xhr.timeout = this.timeout;

Expand All @@ -246,31 +247,35 @@ Autoconfigurator.prototype = {
// issue), trying to use responseXML results in a SecurityError when
// running XPath queries. So let's just do an end-run around the
// "security".
let doc = new DOMParser().parseFromString(xhr.responseText, 'text/xml');
var doc = new DOMParser().parseFromString(xhr.responseText, 'text/xml');
function getNode(xpath, rel) {
return doc.evaluate(xpath, rel || doc, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null)
.singleNodeValue;
}

let provider = getNode('/clientConfig/emailProvider');
var provider = getNode('/clientConfig/emailProvider');
// Get the first incomingServer we can use (we assume first == best).
let incoming = getNode('incomingServer[@type="imap"] | ' +
var incoming = getNode('incomingServer[@type="imap"] | ' +
'incomingServer[@type="activesync"]', provider);
let outgoing = getNode('outgoingServer[@type="smtp"]', provider);
var outgoing = getNode('outgoingServer[@type="smtp"]', provider);

if (incoming) {
let config = { type: null, incoming: {}, outgoing: {} };
for (let [,child] in Iterator(incoming.children))
var config = { type: null, incoming: {}, outgoing: {} };
for (var iter in Iterator(incoming.children)) {
var child = iter[1];
config.incoming[child.tagName] = child.textContent;
}

if (incoming.getAttribute('type') === 'activesync') {
config.type = 'activesync';
}
else if (outgoing) {
config.type = 'imap+smtp';
for (let [,child] in Iterator(outgoing.children))
for (var iter in Iterator(outgoing.children)) {
var child = iter[1];
config.outgoing[child.tagName] = child.textContent;
}

// We do not support unencrypted connections outside of unit tests.
if (config.incoming.socketType !== 'SSL' ||
Expand Down Expand Up @@ -355,7 +360,7 @@ Autoconfigurator.prototype = {
return;
}

let autoconfig = {
var autoconfig = {
type: 'activesync',
displayName: config.user.name,
incoming: {
Expand All @@ -380,10 +385,10 @@ Autoconfigurator.prototype = {
*/
_getConfigFromDomain: function getConfigFromDomain(userDetails, domain,
callback) {
let suffix = '/mail/config-v1.1.xml?emailaddress=' +
var suffix = '/mail/config-v1.1.xml?emailaddress=' +
encodeURIComponent(userDetails.emailAddress);
let url = 'http://autoconfig.' + domain + suffix;
let self = this;
var url = 'http://autoconfig.' + domain + suffix;
var self = this;

this._getXmlConfig(url, function(error, config, errorDetails) {
if (self._isSuccessOrFatal(error)) {
Expand All @@ -392,7 +397,7 @@ Autoconfigurator.prototype = {
}

// See <http://tools.ietf.org/html/draft-nottingham-site-meta-04>.
let url = 'http://' + domain + '/.well-known/autoconfig' + suffix;
var url = 'http://' + domain + '/.well-known/autoconfig' + suffix;
self._getXmlConfig(url, function(error, config, errorDetails) {
if (self._isSuccessOrFatal(error)) {
callback(error, config, errorDetails);
Expand Down Expand Up @@ -426,7 +431,7 @@ Autoconfigurator.prototype = {
* domain
*/
_getMX: function getMX(domain, callback) {
let xhr = new XMLHttpRequest({mozSystem: true});
var xhr = new XMLHttpRequest({mozSystem: true});
xhr.open('GET', 'https://live.mozillamessaging.com/dns/mx/' +
encodeURIComponent(domain), true);
xhr.timeout = this.timeout;
Expand Down Expand Up @@ -457,7 +462,7 @@ Autoconfigurator.prototype = {
* info, formatted as JSON
*/
_getConfigFromMX: function getConfigFromMX(domain, callback) {
let self = this;
var self = this;
this._getMX(domain, function(error, mxDomain, errorDetails) {
if (error)
return callback(error, null, errorDetails);
Expand Down Expand Up @@ -499,8 +504,9 @@ Autoconfigurator.prototype = {
* info, formatted as JSON
*/
getConfig: function getConfig(userDetails, callback) {
let [emailLocalPart, emailDomainPart] = userDetails.emailAddress.split('@');
let domain = emailDomainPart.toLowerCase();
var details = userDetails.emailAddress.split('@');
var emailLocalPart = details[0], emailDomainPart = details[1];
var domain = emailDomainPart.toLowerCase();
console.log('Attempting to get autoconfiguration for', domain);

var placeholderFields = {
Expand All @@ -520,12 +526,14 @@ Autoconfigurator.prototype = {

// Fill any placeholder strings in the configuration object we retrieved.
if (config) {
for (let [serverType, fields] in Iterator(placeholderFields)) {
for (var iter in Iterator(placeholderFields)) {
var serverType = iter[0], fields = iter[1];
if (!config.hasOwnProperty(serverType))
continue;

let server = config[serverType];
for (let [,field] in Iterator(fields)) {
var server = config[serverType];
for (var iter in Iterator(fields)) {
var field = iter[1];
if (server.hasOwnProperty(field))
server[field] = fillPlaceholder(server[field]);
}
Expand All @@ -541,7 +549,7 @@ Autoconfigurator.prototype = {
return;
}

let self = this;
var self = this;
console.log(' Looking in local file store');
this._getConfigFromLocalFile(domain, function(error, config, errorDetails) {
if (self._isSuccessOrFatal(error)) {
Expand Down Expand Up @@ -583,7 +591,7 @@ Autoconfigurator.prototype = {
* info, formatted as JSON
*/
tryToCreateAccount: function(universe, userDetails, callback) {
let self = this;
var self = this;
this.getConfig(userDetails, function(error, config, errorDetails) {
if (error)
return callback(error, null, errorDetails);
Expand Down
2 changes: 1 addition & 1 deletion data/lib/mailapi/accountmixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ exports.runOp = function runOp(op, mode, callback) {
* if no such folder exists.
*/
exports.getFirstFolderWithType = function(type) {
const folders = this.folders;
var folders = this.folders;
for (var iFolder = 0; iFolder < folders.length; iFolder++) {
if (folders[iFolder].type === type)
return folders[iFolder];
Expand Down
6 changes: 3 additions & 3 deletions data/lib/mailapi/cronsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ define(
/**
* Sanity demands we do not check more frequently than once a minute.
*/
const MINIMUM_SYNC_INTERVAL_MS = 60 * 1000;
var MINIMUM_SYNC_INTERVAL_MS = 60 * 1000;

/**
* How long should we let a synchronization run before we give up on it and
* potentially try and kill it (if we can)?
*/
const MAX_SYNC_DURATION_MS = 3 * 60 * 1000;
var MAX_SYNC_DURATION_MS = 3 * 60 * 1000;

/**
* Caps the number of notifications we generate per account. It would be
* sitcom funny to let this grow without bound, but would end badly in reality.
*/
const MAX_MESSAGES_TO_REPORT_PER_ACCOUNT = 5;
var MAX_MESSAGES_TO_REPORT_PER_ACCOUNT = 5;

/**
* Implements the interface of `MailSlice` as presented to `FolderStorage`, but
Expand Down
24 changes: 12 additions & 12 deletions data/lib/mailapi/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ define(
*
* !BEFORE(a, b) === SINCE(a, b)
*/
const BEFORE = exports.BEFORE =
var BEFORE = exports.BEFORE =
function BEFORE(testDate, comparisonDate) {
// testDate is numerically less than comparisonDate, so it is chronologically
// before it.
return testDate < comparisonDate;
};

const ON_OR_BEFORE = exports.ON_OR_BEFORE =
var ON_OR_BEFORE = exports.ON_OR_BEFORE =
function ON_OR_BEFORE(testDate, comparisonDate) {
return testDate <= comparisonDate;
};
Expand All @@ -93,28 +93,28 @@ const ON_OR_BEFORE = exports.ON_OR_BEFORE =
*
* !SINCE(a, b) === BEFORE(a, b)
*/
const SINCE = exports.SINCE =
var SINCE = exports.SINCE =
function SINCE(testDate, comparisonDate) {
// testDate is numerically greater-than-or-equal-to comparisonDate, so it
// chronologically after/since it.
return testDate >= comparisonDate;
};

const STRICTLY_AFTER = exports.STRICTLY_AFTER =
var STRICTLY_AFTER = exports.STRICTLY_AFTER =
function STRICTLY_AFTER(testDate, comparisonDate) {
return testDate > comparisonDate;
};

const IN_BS_DATE_RANGE = exports.IN_BS_DATE_RANGE =
var IN_BS_DATE_RANGE = exports.IN_BS_DATE_RANGE =
function IN_BS_DATE_RANGE(testDate, startTS, endTS) {
return testDate >= startTS && testDate < endTS;
};

//function DATE_RANGES_OVERLAP(A_startTS, A_endTS, B_startTS, B_endTS) {
//}

const HOUR_MILLIS = exports.HOUR_MILLIS = 60 * 60 * 1000;
const DAY_MILLIS = exports.DAY_MILLIS = 24 * 60 * 60 * 1000;
var HOUR_MILLIS = exports.HOUR_MILLIS = 60 * 60 * 1000;
var DAY_MILLIS = exports.DAY_MILLIS = 24 * 60 * 60 * 1000;

/**
* Testing override that when present replaces use of Date.now().
Expand All @@ -139,11 +139,11 @@ exports.TEST_LetsDoTheTimewarpAgain = function(fakeNow) {
FUTURE_TIME_WARPED_NOW = quantizeDate(fakeNow + DAY_MILLIS);
};

const NOW = exports.NOW =
var NOW = exports.NOW =
function NOW() {
return TIME_WARPED_NOW || Date.now();
};
const FUTURE = exports.FUTURE =
var FUTURE = exports.FUTURE =
function FUTURE() {
return FUTURE_TIME_WARPED_NOW || null;
};
Expand All @@ -153,22 +153,22 @@ const FUTURE = exports.FUTURE =
* that day. This results in rounding up; if it's noon right now and you
* ask for 2 days ago, you really get 2.5 days worth of time.
*/
const makeDaysAgo = exports.makeDaysAgo =
var makeDaysAgo = exports.makeDaysAgo =
function makeDaysAgo(numDays) {
var //now = quantizeDate(TIME_WARPED_NOW || Date.now()),
//past = now - numDays * DAY_MILLIS;
past = (FUTURE_TIME_WARPED_NOW || quantizeDate(Date.now())) -
(numDays + 1) * DAY_MILLIS;
return past;
};
const makeDaysBefore = exports.makeDaysBefore =
var makeDaysBefore = exports.makeDaysBefore =
function makeDaysBefore(date, numDaysBefore) {
return quantizeDate(date) - numDaysBefore * DAY_MILLIS;
};
/**
* Quantize a date to midnight on that day.
*/
const quantizeDate = exports.quantizeDate =
var quantizeDate = exports.quantizeDate =
function quantizeDate(date) {
if (typeof(date) === 'number')
date = new Date(date);
Expand Down
16 changes: 8 additions & 8 deletions data/lib/mailapi/htmlchew.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ var LEGAL_STYLES = [
*
* ignore-case is not required; the value is checked against the lower-cased tag.
*/
const RE_NODE_NEEDS_TRANSFORM = /^(?:a|area|img)$/;
var RE_NODE_NEEDS_TRANSFORM = /^(?:a|area|img)$/;

const RE_CID_URL = /^cid:/i;
const RE_HTTP_URL = /^http(?:s)?/i;
const RE_MAILTO_URL = /^mailto:/i;
var RE_CID_URL = /^cid:/i;
var RE_HTTP_URL = /^http(?:s)?/i;
var RE_MAILTO_URL = /^mailto:/i;

const RE_IMG_TAG = /^img$/;
var RE_IMG_TAG = /^img$/;

/**
* Transforms src tags, ensure that links are http and transform them too so
Expand Down Expand Up @@ -456,9 +456,9 @@ exports.sanitizeAndNormalizeHtml = function sanitizeAndNormalize(htmlString) {
return sanitizedNode;
};

const ELEMENT_NODE = 1, TEXT_NODE = 3;
var ELEMENT_NODE = 1, TEXT_NODE = 3;

const RE_NORMALIZE_WHITESPACE = /\s+/g;
var RE_NORMALIZE_WHITESPACE = /\s+/g;

/**
* Derive snippet text from the already-sanitized HTML representation.
Expand Down Expand Up @@ -566,7 +566,7 @@ exports.wrapTextIntoSafeHTMLString = function(text, wrapTag,
return wrapNode.outerHTML;
};

const RE_QUOTE_CHAR = /"/g;
var RE_QUOTE_CHAR = /"/g;

/**
* Make an HTML attribute value safe.
Expand Down
2 changes: 1 addition & 1 deletion data/lib/mailapi/jobmixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ exports.local_undo_modtags = function(op, callback) {
exports.local_do_move = function(op, doneCallback, targetFolderId) {
// create a scratch field to store the guid's for check purposes
op.guids = {};
const nukeServerIds = !this.resilientServerIds;
var nukeServerIds = !this.resilientServerIds;

var stateDelta = this._stateDelta, addWait = 0, self = this;
if (!stateDelta.moveMap)
Expand Down
2 changes: 1 addition & 1 deletion data/lib/mailapi/mailapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ MessageComposition.prototype = {
};


const LEGAL_CONFIG_KEYS = ['syncCheckIntervalEnum'];
var LEGAL_CONFIG_KEYS = ['syncCheckIntervalEnum'];

/**
* Error reporting helper; we will probably eventually want different behaviours
Expand Down
6 changes: 3 additions & 3 deletions data/lib/mailapi/mailbridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ define(
$module,
exports
) {
const bsearchForInsert = $imaputil.bsearchForInsert,
bsearchMaybeExists = $imaputil.bsearchMaybeExists;
var bsearchForInsert = $imaputil.bsearchForInsert,
bsearchMaybeExists = $imaputil.bsearchMaybeExists;

function toBridgeWireOn(x) {
return x.toBridgeWire();
}

const FOLDER_TYPE_TO_SORT_PRIORITY = {
var FOLDER_TYPE_TO_SORT_PRIORITY = {
account: 'a',
inbox: 'c',
starred: 'e',
Expand Down
Loading

0 comments on commit 46699fd

Please sign in to comment.