Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
Merge pull request #11 from pianoslum/fixForLoops
Browse files Browse the repository at this point in the history
Fix for loops
  • Loading branch information
protz committed Apr 17, 2015
2 parents 818282a + e06d679 commit 5894a98
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 55 deletions.
8 changes: 4 additions & 4 deletions RestartlessMenuItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ monkeyPatchWindowObserver.prototype = {
observe: function (aSubject, aTopic, aData) {
if (aTopic == "domwindowopened") {
aSubject.QueryInterface(Ci.nsIDOMWindow);
for each (let aMenuItem in _menuItems)
for (let aMenuItem of _menuItems)
monkeyPatchWindow(aSubject.window, false, aMenuItem);
}
},
Expand Down Expand Up @@ -213,7 +213,7 @@ var RestartlessMenuItems = {
_menuItems.push(options);

// Patch all existing windows
for each (let w in fixIterator(Services.wm.getEnumerator("mail:3pane"), Ci.nsIDOMWindow)) {
for (let w of fixIterator(Services.wm.getEnumerator("mail:3pane"), Ci.nsIDOMWindow)) {
// True means the window's been loaded already, so add the menu item right
// away (the default is: wait for the "load" event).
monkeyPatchWindow(w.window, true, options);
Expand All @@ -239,7 +239,7 @@ var RestartlessMenuItems = {

// Un-patch all existing windows
if (found)
for each (let w in fixIterator(Services.wm.getEnumerator("mail:3pane")))
for (let w of fixIterator(Services.wm.getEnumerator("mail:3pane")))
unMonkeyPatchWindow(w, _menuItems[index]);

if (!keepArray) {
Expand All @@ -257,7 +257,7 @@ var RestartlessMenuItems = {
removeAll: function _RestartlessMenuItems_removeAll () {
if (isThunderbird()) {
// Remove all added menuitems
for each (let aMenuItem in _menuItems)
for (let aMenuItem of _menuItems)
this.remove(aMenuItem, true);
_menuItems = [];
monkeyPatchFutureWindow.unregister();
Expand Down
38 changes: 17 additions & 21 deletions compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ function simpleWrap(txt, width) {

let lines = txt.split(/\r?\n/);

for each (let [i, line] in Iterator(lines)) {
lines.forEach(function(line, i) {
if (line.length > width && line[0] != ">")
lines[i] = splitLongLine([], line);
}
});
return lines.join("\n");
}

Expand Down Expand Up @@ -299,7 +299,7 @@ function plainTextToHtml(txt) {
let lines = txt.split(/\r?\n/);
let newLines = [];
let level = 0;
for each (let [, line] in Iterator(lines)) {
for (let line of lines) {
let newLevel = citeLevel(line);
if (newLevel > level)
for (let i = level; i < newLevel; ++i)
Expand Down Expand Up @@ -343,16 +343,15 @@ function replyAllParams(aIdentity, aMsgHdr, k) {
let [ccList, ccListEmailAddresses] = parse(aMsgHdr.ccList);
let [bccList, bccListEmailAddresses] = parse(aMsgHdr.bccList);
authorEmailAddress = authorEmailAddress.toLowerCase();
recipientsEmailAddresses = [x.toLowerCase()
for each ([, x] in Iterator(recipientsEmailAddresses))];
ccListEmailAddresses = [x.toLowerCase() for each ([, x] in Iterator(ccListEmailAddresses))];
bccListEmailAddresses = [x.toLowerCase() for each ([, x] in Iterator(bccListEmailAddresses))];
recipientsEmailAddresses = recipientsEmailAddresses.map(x => x.toLowerCase());
ccListEmailAddresses = ccListEmailAddresses.map(x => x.toLowerCase());
bccListEmailAddresses = bccListEmailAddresses.map(x => x.toLowerCase());
let identity = aIdentity;
let identityEmail = identity.email.toLowerCase();
let to = [], cc = [], bcc = [];

let isReplyToOwnMsg = false;
for each (let currentIdentity in getIdentities()) {
for (let currentIdentity of getIdentities()) {
let email = currentIdentity.identity.email.toLowerCase();
if (email == authorEmailAddress)
isReplyToOwnMsg = true;
Expand All @@ -365,25 +364,22 @@ function replyAllParams(aIdentity, aMsgHdr, k) {
// Actually we are implementing the "Reply all" logic... that's better, no one
// wants to really use reply anyway ;-)
if (isReplyToOwnMsg) {
to = [[r, recipientsEmailAddresses[i]]
for each ([i, r] in Iterator(recipients))];
to = recipients.map((r, i) => [r, recipientsEmailAddresses[i]]);
} else {
to = [[author, authorEmailAddress]];
}
cc = [[cc, ccListEmailAddresses[i]]
for each ([i, cc] in Iterator(ccList))
if (ccListEmailAddresses[i] != identityEmail)];
if (!isReplyToOwnMsg)
cc = ccList.filter((e, i) => ccListEmailAddresses[i] != identityEmail).
map((cc, i) => [cc, ccListEmailAddresses[i]]);
if (!isReplyToOwnMsg) {
cc = cc.concat
([[r, recipientsEmailAddresses[i]]
for each ([i, r] in Iterator(recipients))
if (recipientsEmailAddresses[i] != identityEmail)]);
bcc = [[bcc, bccListEmailAddresses[i]]
for each ([i, bcc] in Iterator(bccList))];
(recipients.filter((e, i) => recipientsEmailAddresses[i] != identityEmail).
map((r, i) => [r, recipientsEmailAddresses[i]]));
}
bcc = bccList.map((bcc, i) => [bcc, bccListEmailAddresses]);

let finish = function (to, cc, bcc) {
let hashMap = {};
for each (let [name, email] in to)
for (let [name, email] of to)
hashMap[email] = null;
cc = cc.filter(function ([name, email]) {
let r = (email in hashMap);
Expand All @@ -402,7 +398,7 @@ function replyAllParams(aIdentity, aMsgHdr, k) {
msgHdrGetHeaders(aMsgHdr, function (aHeaders) {
if (aHeaders.has("reply-to")) {
let [names, emails] = parse(aHeaders.get("reply-to"));
emails = [email.toLowerCase() for each (email in emails)];
emails = emails.map(email => email.toLowerCase());
if (emails.length) {
// Invariant: at this stage, we only have one item in to.
cc = cc.concat([to[0]]); // move the to in cc
Expand Down
12 changes: 6 additions & 6 deletions misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function* entries(anObject) {
*/
function MixIn(aConstructor, aMixIn) {
let proto = aConstructor.prototype;
for (let [name, func] in Iterator(aMixIn)) {
for (let [name, func] of entries(aMixIn)) {
if (name.substring(0, 4) == "get_")
proto.__defineGetter__(name.substring(4), func);
else
Expand Down Expand Up @@ -160,7 +160,7 @@ function fillIdentities(aSkipNntp) {
Log.warn("fillIdentities is deprecated! Use getIdentities instead!");
Log.debug("Filling identities with skipnntp = ", aSkipNntp);

for each (let currentIdentity in getIdentities(aSkipNntp)) {
for (let currentIdentity of getIdentities(aSkipNntp)) {
gIdentities[currentIdentity.identity.email] = currentIdentity.identity;
if (currentIdentity.isDefault) {
gIdentities["default"] = currentIdentity.identity;
Expand All @@ -187,12 +187,12 @@ function getDefaultIdentity() {
*/
function getIdentities(aSkipNntpIdentities = true) {
let identities = [];
for each (let account in fixIterator(MailServices.accounts.accounts, Ci.nsIMsgAccount)) {
for (let account of fixIterator(MailServices.accounts.accounts, Ci.nsIMsgAccount)) {
let server = account.incomingServer;
if (aSkipNntpIdentities && (!server || server.type != "pop3" && server.type != "imap")) {
continue;
}
for each (let currentIdentity in fixIterator(account.identities, Ci.nsIMsgIdentity)) {
for (let currentIdentity of fixIterator(account.identities, Ci.nsIMsgIdentity)) {
// We're only interested in identities that have a real email.
if (currentIdentity.email) {
identities.push({ isDefault: (currentIdentity == MailServices.accounts.defaultAccount.defaultIdentity), identity: currentIdentity });
Expand Down Expand Up @@ -312,7 +312,7 @@ function parseMimeLine (aMimeLine, aDontFix) {
*/
function encodeUrlParameters(aObj) {
let kv = [];
for each (let [k, v] in Iterator(aObj)) {
for (let [k, v] of entries(aObj)) {
kv.push(k+"="+encodeURIComponent(v));
}
return kv.join("&");
Expand All @@ -330,7 +330,7 @@ function decodeUrlParameters(aStr) {
if (i >= 0) {
let query = aStr.substring(i+1, aStr.length);
let keyVals = query.split("&");
for each (let [, keyVal] in Iterator(keyVals)) {
for (let keyVal of keyVals) {
let [key, val] = keyVal.split("=");
val = decodeURIComponent(val);
params[key] = val;
Expand Down
31 changes: 12 additions & 19 deletions msgHdrUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,12 @@ function msgHdrGetTags (aMsgHdr) {
let keywords = aMsgHdr.getStringProperty("keywords");
let keywordList = keywords.split(' ');
let keywordMap = {};
for (let [, keyword] in Iterator(keywordList)) {
for (let keyword of keywordList) {
keywordMap[keyword] = true;
}

let tagArray = MailServices.tags.getAllTags({});
let tags = [];
for (let [iTag, tag] in Iterator(tagArray)) {
let tag = tagArray[iTag];
if (tag.key in keywordMap)
tags.push(tag);
}
let tags = tagArray.filter(tag => tag.key in keywordMap);
return tags;
}

Expand All @@ -215,18 +210,16 @@ function msgHdrGetTags (aMsgHdr) {
function msgHdrSetTags (aMsgHdr, aTags) {
let oldTagList = msgHdrGetTags(aMsgHdr);
let oldTags = {}; // hashmap
for each (let [, tag] in Iterator(oldTagList))
for (let tag of oldTagList)
oldTags[tag.key] = null;

let newTags = {};
let newTagList = aTags;
for each (let [, tag] in Iterator(newTagList))
for (let tag of newTagList)
newTags[tag.key] = null;

let toAdd = [x.key for each ([, x] in Iterator(newTagList))
if (!(x.key in oldTags))];
let toRemove = [x.key for each ([, x] in Iterator(oldTagList))
if (!(x.key in newTags))];
let toAdd = newTagList.filter(x => !(x.key in oldTags)).map(x => x.key);
let toRemove = oldTagList.filter(x => !(x.key in newTags)).map(x => x.key);

let folder = aMsgHdr.folder;
let msgHdr = toXPCOMArray([aMsgHdr], Ci.nsIMutableArray);
Expand All @@ -242,7 +235,7 @@ function msgHdrSetTags (aMsgHdr, aTags) {
*/
function msgHdrsMarkAsRead(msgHdrs, read) {
let pending = {};
for each (let msgHdr in msgHdrs) {
for (let msgHdr of msgHdrs) {
if (msgHdr.isRead == read)
continue;
if (!pending[msgHdr.folder.URI]) {
Expand All @@ -253,7 +246,7 @@ function msgHdrsMarkAsRead(msgHdrs, read) {
}
pending[msgHdr.folder.URI].msgs.appendElement(msgHdr, false);
}
for each (let { folder, msgs } in pending) {
for (let [ uri, { folder, msgs } ] of entries(pending)) {
folder.markMessagesRead(msgs, read);
folder.msgDatabase = null; /* don't leak */
}
Expand All @@ -265,7 +258,7 @@ function msgHdrsMarkAsRead(msgHdrs, read) {
*/
function msgHdrsDelete(msgHdrs) {
let pending = {};
for each (let msgHdr in msgHdrs) {
for (let msgHdr of msgHdrs) {
if (!pending[msgHdr.folder.URI]) {
pending[msgHdr.folder.URI] = {
folder: msgHdr.folder,
Expand All @@ -274,7 +267,7 @@ function msgHdrsDelete(msgHdrs) {
}
pending[msgHdr.folder.URI].msgs.appendElement(msgHdr, false);
}
for each (let { folder, msgs } in pending) {
for (let [ uri, { folder, msgs } ] of pending) {
folder.deleteMessages(msgs, getMail3Pane().msgWindow, false, false, null, true);
folder.msgDatabase = null; /* don't leak */
}
Expand Down Expand Up @@ -406,7 +399,7 @@ function msgHdrGetHeaders(aMsgHdr, k) {
let str = aRawString.replace(re, " ");
let lines = str.split(/\r?\n/);
let obj = {};
for each (let [, line] in Iterator(lines)) {
for (let line of lines) {
let i = line.indexOf(":");
if (i < 0)
continue;
Expand Down Expand Up @@ -481,7 +474,7 @@ function msgHdrsModifyRaw(aMsgHdrs, aTransformer) {
copyNext();
}

for each (let [, aMsgHdr] in Iterator(aMsgHdrs)) {
for (let aMsgHdr of aMsgHdrs) {
let msgHdr = aMsgHdr;
let uri = msgHdrGetUri(msgHdr);
let messageService = MailServices.messenger.messageServiceFromURI(uri);
Expand Down
6 changes: 3 additions & 3 deletions send.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function sendMessage(aParams,
}

case mCompType.ForwardAsAttachment: {
for each (let [, url] in Iterator(urls)) {
for (let url of urls) {
let msgHdr = msgUriToMsgHdr(url);
references.push(msgHdr.messageId);
}
Expand All @@ -287,9 +287,9 @@ function sendMessage(aParams,
break;
}
}
references = ["<"+x+">" for each ([, x] in Iterator(references))];
references = ["<"+x+">" for (x of references)];
fields.references = references.join(" ");
[fields.addAttachment(x) for each ([, x] in Iterator(attachments))];
[fields.addAttachment(x) for (x of attachments)];

let fccFolder = identity.fccFolder;
let fccSameFolder = identity.fccReplyFollowsParent;
Expand Down
4 changes: 2 additions & 2 deletions tests/test_SimpleStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function test_sync_api () {
r = yield ss.set("myKey", o);
do_check_false(r); // Value was updated in-place
r = yield ss.get("myKey");
for each (key in Object.keys(r))
for (key of Object.keys(r))
do_check_true(r[key] == o[key]);
for each (key in Object.keys(o))
for (key of Object.keys(o))
do_check_true(r[key] == o[key]);

// Test nested async actions. Not recommended for the casual user because of
Expand Down

0 comments on commit 5894a98

Please sign in to comment.