Bug 1515877 - Turn on ESLint in mailnews/imap draft
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 08 May 2019 14:21:13 +1200
changeset 73478 b9faaabd7de921dd304e5f7efd8a9b02cc98c786
parent 73477 03240e408d6702390e63f456110895988c99b77e
child 73479 32676853179de1d0f98b01c093caf12b121c39dd
push id8409
push usergeoff@darktrojan.net
push dateWed, 08 May 2019 02:22:29 +0000
treeherdertry-comm-central@f8d9091c9d1c [default view] [failures only]
bugs1515877
Bug 1515877 - Turn on ESLint in mailnews/imap
.eslintignore
mailnews/imap/test/unit/.eslintrc.js
mailnews/imap/test/unit/head_imap_maildir.js
mailnews/imap/test/unit/head_server.js
mailnews/imap/test/unit/test_autosync_date_constraints.js
mailnews/imap/test/unit/test_bccProperty.js
mailnews/imap/test/unit/test_bug460636.js
mailnews/imap/test/unit/test_cacheParts.js
mailnews/imap/test/unit/test_chunkLastLF.js
mailnews/imap/test/unit/test_compactOfflineStore.js
mailnews/imap/test/unit/test_converterImap.js
mailnews/imap/test/unit/test_copyThenMove.js
mailnews/imap/test/unit/test_customCommandReturnsFetchResponse.js
mailnews/imap/test/unit/test_dod.js
mailnews/imap/test/unit/test_dontStatNoSelect.js
mailnews/imap/test/unit/test_downloadOffline.js
mailnews/imap/test/unit/test_fetchCustomAttribute.js
mailnews/imap/test/unit/test_filterCustomHeaders.js
mailnews/imap/test/unit/test_filterNeedsBody.js
mailnews/imap/test/unit/test_folderOfflineFlags.js
mailnews/imap/test/unit/test_gmailAttributes.js
mailnews/imap/test/unit/test_gmailOfflineMsgStore.js
mailnews/imap/test/unit/test_imapAttachmentSaves.js
mailnews/imap/test/unit/test_imapAuthMethods.js
mailnews/imap/test/unit/test_imapAutoSync.js
mailnews/imap/test/unit/test_imapChunks.js
mailnews/imap/test/unit/test_imapContentLength.js
mailnews/imap/test/unit/test_imapCopyTimeout.js
mailnews/imap/test/unit/test_imapFilterActions.js
mailnews/imap/test/unit/test_imapFilterActionsPostplugin.js
mailnews/imap/test/unit/test_imapFlagChange.js
mailnews/imap/test/unit/test_imapFolderCopy.js
mailnews/imap/test/unit/test_imapHdrChunking.js
mailnews/imap/test/unit/test_imapHdrStreaming.js
mailnews/imap/test/unit/test_imapHighWater.js
mailnews/imap/test/unit/test_imapID.js
mailnews/imap/test/unit/test_imapMove.js
mailnews/imap/test/unit/test_imapPasswordFailure.js
mailnews/imap/test/unit/test_imapProtocols.js
mailnews/imap/test/unit/test_imapProxy.js
mailnews/imap/test/unit/test_imapRename.js
mailnews/imap/test/unit/test_imapSearch.js
mailnews/imap/test/unit/test_imapStatusCloseDBs.js
mailnews/imap/test/unit/test_imapStoreMsgOffline.js
mailnews/imap/test/unit/test_imapUndo.js
mailnews/imap/test/unit/test_imapUrls.js
mailnews/imap/test/unit/test_largeOfflineStore.js
mailnews/imap/test/unit/test_listClosesDB.js
mailnews/imap/test/unit/test_listSubscribed.js
mailnews/imap/test/unit/test_localToImapFilter.js
mailnews/imap/test/unit/test_localToImapFilterQuarantine.js
mailnews/imap/test/unit/test_lsub.js
mailnews/imap/test/unit/test_mailboxes.js
mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
mailnews/imap/test/unit/test_offlineCopy.js
mailnews/imap/test/unit/test_offlineDraftDataloss.js
mailnews/imap/test/unit/test_offlinePlayback.js
mailnews/imap/test/unit/test_offlineStoreLocking.js
mailnews/imap/test/unit/test_partsOnDemand.js
mailnews/imap/test/unit/test_preserveDataOnMove.js
mailnews/imap/test/unit/test_saveImapDraft.js
mailnews/imap/test/unit/test_saveTemplate.js
mailnews/imap/test/unit/test_starttlsFailure.js
mailnews/imap/test/unit/test_stopMovingToLocalFolder.js
mailnews/imap/test/unit/test_subfolderLocation.js
mailnews/imap/test/unit/test_syncChanges.js
mailnews/imap/test/unit/test_trustSpamAssassin.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -59,17 +59,16 @@ editor/ui/dialogs/content/EdSnapToGrid.j
 editor/ui/dialogs/content/EdSnapToGrid.xul
 editor/ui/texzilla/**
 
 # mailnews exclusions
 mailnews/mailnews.js
 mailnews/extensions/dsn/content/dsn.js
 mailnews/extensions/mdn/content/mdn.js
 mailnews/extensions/smime/content/smime.js
-mailnews/imap/*
 mailnews/import/*
 mailnews/intl/*
 mailnews/jsaccount/*
 mailnews/mime/*
 
 # mail exclusions
 mail/app/profile/all-thunderbird.js
 mail/app/profile/channel-prefs.js
new file mode 100644
--- /dev/null
+++ b/mailnews/imap/test/unit/.eslintrc.js
@@ -0,0 +1,14 @@
+"use strict";
+
+module.exports = {
+  "extends": "plugin:mozilla/xpcshell-test",
+
+  "rules": {
+    "func-names": "off",
+    "mozilla/import-headjs-globals": "error",
+    "no-unused-vars": ["error", {
+      "args": "none",
+      "vars": "all",
+    }],
+  },
+};
--- a/mailnews/imap/test/unit/head_imap_maildir.js
+++ b/mailnews/imap/test/unit/head_imap_maildir.js
@@ -1,6 +1,7 @@
+/* import-globals-from head_server.js */
 load("head_server.js");
 
 info("Running test with maildir");
 
 Services.prefs.setCharPref("mail.serverDefaultStoreContractID",
                            "@mozilla.org/msgstore/maildirstore;1");
--- a/mailnews/imap/test/unit/head_server.js
+++ b/mailnews/imap/test/unit/head_server.js
@@ -62,17 +62,17 @@ function makeServer(daemon, infoString, 
     }
     return handler;
   }
   var server = new nsMailServer(createHandler, daemon);
   server.start();
   return server;
 }
 
-function createLocalIMAPServer(port, hostname="localhost") {
+function createLocalIMAPServer(port, hostname = "localhost") {
   let server = localAccountUtils.create_incoming_server("imap", port,
     "user", "password", hostname);
   server.QueryInterface(Ci.nsIImapIncomingServer);
   return server;
 }
 
 // <copied from="head_maillocal.js">
 /**
@@ -85,41 +85,39 @@ function createLocalIMAPServer(port, hos
  *    e.g. "authenticate CRAM-MD5".
  */
 function do_check_transaction(fromServer, expected, withParams) {
   // If we don't spin the event loop before starting the next test, the readers
   // aren't expired. In this case, the "real" real transaction is the last one.
   if (fromServer instanceof Array)
     fromServer = fromServer[fromServer.length - 1];
 
-  var realTransaction = new Array();
-  for (var i = 0; i < fromServer.them.length; i++)
-  {
+  let realTransaction = [];
+  for (let i = 0; i < fromServer.them.length; i++) {
     var line = fromServer.them[i]; // e.g. '1 login "user" "password"'
     var components = line.split(" ");
     if (components.length < 2)
-      throw "IMAP command in transaction log missing: " + line;
+      throw new Error("IMAP command in transaction log missing: " + line);
     if (withParams)
       realTransaction.push(line.substr(components[0].length + 1));
     else if (components[1] == "authenticate")
       realTransaction.push(components[1] + " " + components[2].toUpperCase());
     else
       realTransaction.push(components[1]);
   }
 
   Assert.equal(realTransaction.join(", "), expected.join(", "));
 }
 
 /**
  * add a simple message to the IMAP pump mailbox
  */
-function addImapMessage()
-{
+function addImapMessage() {
   let messages = [];
-  let messageGenerator = new MessageGenerator();
+  let messageGenerator = new MessageGenerator(); // eslint-disable-line no-undef
   messages = messages.concat(messageGenerator.makeMessage());
   let dataUri = Services.io.newURI("data:text/plain;base64," +
                   btoa(messages[0].toMessageString()));
   let imapMsg = new imapMessage(dataUri.spec, IMAPPump.mailbox.uidnext++, []);
   IMAPPump.mailbox.addMessage(imapMsg);
 }
 
 registerCleanupFunction(function() {
--- a/mailnews/imap/test/unit/test_autosync_date_constraints.js
+++ b/mailnews/imap/test/unit/test_autosync_date_constraints.js
@@ -1,28 +1,27 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Test autosync date constraints
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
-var gRootFolder;
-var gIMAPTrashFolder, gMsgImapInboxFolder;
-var gImapInboxOfflineStoreSize;
+var gMsgImapInboxFolder;
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox)
-{
+function addMessagesToServer(messages, mailbox) {
   // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
-  {
-    let dataUri = 'data:text/plain,' + message.toMessageString();
+  messages.forEach(function(message) {
+    let dataUri = "data:text/plain," + message.toMessageString();
     mailbox.addMessage(new imapMessage(dataUri, mailbox.uidnext++, []));
   });
 }
 
 var tests = [
   setup,
   function* downloadForOffline() {
     // ...and download for offline use.
@@ -43,38 +42,36 @@ var tests = [
           if (header.dateInSeconds < cutOffDateInSeconds)
             Assert.equal(header.getStringProperty("pendingRemoval"), "1");
           else
             Assert.equal(header.getStringProperty("pendingRemoval"), "");
         }
       }
     }
   },
-  teardown
+  teardown,
 ];
 
 function setup() {
   Services.prefs.setIntPref("mail.server.server1.autosync_max_age_days", 4);
 
   setupIMAPPump();
 
-  gRootFolder = IMAPPump.incomingServer.rootFolder;
   gMsgImapInboxFolder = IMAPPump.inbox.QueryInterface(Ci.nsIMsgImapMailFolder);
   // these hacks are required because we've created the inbox before
   // running initial folder discovery, and adding the folder bails
   // out before we set it as verified online, so we bail out, and
   // then remove the INBOX folder since it's not verified.
-  gMsgImapInboxFolder.hierarchyDelimiter = '/';
+  gMsgImapInboxFolder.hierarchyDelimiter = "/";
   gMsgImapInboxFolder.verifiedAsOnlineFolder = true;
 
 
   // Add a couple of messages to the INBOX
   // this is synchronous, afaik
   let messageGenerator = new MessageGenerator();
-  let scenarioFactory = new MessageScenarioFactory(messageGenerator);
 
   // build up a diverse list of messages
   let messages = [];
   messages = messages.concat(messageGenerator.makeMessage({age: {days: 2, hours: 1}}));
   messages = messages.concat(messageGenerator.makeMessage({age: {days: 8, hours: 1}}));
   messages = messages.concat(messageGenerator.makeMessage({age: {days: 10, hours: 1}}));
 
   addMessagesToServer(messages, IMAPPump.daemon.getMailbox("INBOX"));
--- a/mailnews/imap/test/unit/test_bccProperty.js
+++ b/mailnews/imap/test/unit/test_bccProperty.js
@@ -2,27 +2,29 @@
 /*
  * Test to ensure that BCC gets added to message headers on IMAP download
  *
  * adapted from test_downloadOffline.js
  *
  * original author Kent James <kent@caspia.com>
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 var gFileName = "draft1";
 var gMsgFile = do_get_file("../../../data/" + gFileName);
 
 var tests = [
   setup,
   downloadAllForOffline,
   checkBccs,
-  teardown
+  teardown,
 ];
 
 function* setup() {
   setupIMAPPump();
 
   /*
    * Ok, prelude done. Read the original message from disk
    * (through a file URI), and add it to the Inbox.
@@ -41,17 +43,17 @@ function* setup() {
 function* downloadAllForOffline() {
   IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
   yield false;
 }
 
 function checkBccs() {
   // locate the new message by enumerating through the database
   let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
-  while(enumerator.hasMoreElements()) {
+  while (enumerator.hasMoreElements()) {
     let hdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
     Assert.ok(hdr.bccList.includes("Another Person"));
     Assert.ok(hdr.bccList.includes("<u1@example.com>"));
     Assert.ok(!hdr.bccList.includes("IDoNotExist"));
   }
 }
 
 function teardown() {
--- a/mailnews/imap/test/unit/test_bug460636.js
+++ b/mailnews/imap/test/unit/test_bug460636.js
@@ -1,27 +1,29 @@
 /*
  * Test bug 460636 - nsMsgSaveAsListener sometimes inserts extra LF characters
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 var gSavedMsgFile;
 
 var gIMAPService = Cc["@mozilla.org/messenger/messageservice;1?type=imap"]
                        .getService(Ci.nsIMsgMessageService);
 
 var gFileName = "bug460636";
 var gMsgFile = do_get_file("../../../data/" + gFileName);
 
 var tests = [
   setup,
   checkSavedMessage,
-  teardown
+  teardown,
 ];
 
 function* setup() {
   setupIMAPPump();
 
   /*
    * Ok, prelude done. Read the original message from disk
    * (through a file URI), and add it to the Inbox.
@@ -48,31 +50,30 @@ function* setup() {
    *                        in boolean aGenerateDummyEnvelope,
    *                        in nsIUrlListener aUrlListener, out nsIURI aURL,
    *                        in boolean canonicalLineEnding,
    *                        in nsIMsgWindow aMsgWindow);
    * Enforcing canonicalLineEnding (i.e., CRLF) makes sure that the
    * test also runs successfully on platforms not using CRLF by default.
    */
   gIMAPService.SaveMessageToDisk("imap-message://user@localhost/INBOX#"
-                                 + (IMAPPump.mailbox.uidnext-1), gSavedMsgFile,
+                                 + (IMAPPump.mailbox.uidnext - 1), gSavedMsgFile,
                                  false, asyncUrlListener, {}, true, null);
   yield false;
 }
 
 function checkSavedMessage() {
   Assert.equal(IOUtils.loadFileToString(gMsgFile),
                IOUtils.loadFileToString(gSavedMsgFile));
 }
 
 function teardown() {
   try {
     gSavedMsgFile.remove(false);
-  }
-  catch (ex) {
+  } catch (ex) {
     dump(ex);
     do_throw(ex);
   }
   teardownIMAPPump();
 }
 
 function run_test() {
   async_run_tests(tests);
--- a/mailnews/imap/test/unit/test_cacheParts.js
+++ b/mailnews/imap/test/unit/test_cacheParts.js
@@ -1,17 +1,16 @@
 /*
  * Test bug 629738 - Parts should be cached.
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
 load("../../../resources/logHelper.js");
 var {PromiseTestUtils} = ChromeUtils.import("resource://testing-common/mailnews/PromiseTestUtils.jsm");
 
-var gSavedMsgFile;
-
 var gIMAPService = Cc["@mozilla.org/messenger/messageservice;1?type=imap"]
                        .getService(Ci.nsIMsgMessageService);
 
 var gFileName1 = "image-attach-test";
 var gMsgFile1 = do_get_file("../../../data/" + gFileName1);
 var gMsgId1 = "4A947F73.5030709@example.com";
 
 var gFileName2 = "external-attach-test";
@@ -20,50 +19,49 @@ var gMsgId2 = "876TY.5030709@example.com
 
 var gMsgURL1;
 var gMsgPartURL1;
 var gMsgURL2;
 var gMsgPartURL2;
 var gUidValidity;
 
 // We use this as a display consumer
-var streamListener =
-{
+var streamListener = {
   _data: "",
 
   QueryInterface:
     ChromeUtils.generateQI([Ci.nsIStreamListener, Ci.nsIRequestObserver]),
 
   // nsIRequestObserver
-  onStartRequest: function(aRequest) {
+  onStartRequest(aRequest) {
   },
-  onStopRequest: function(aRequest, aStatusCode) {
+  onStopRequest(aRequest, aStatusCode) {
     Assert.equal(aStatusCode, Cr.NS_OK);
   },
 
   // nsIStreamListener
-  onDataAvailable: function(aRequest, aInputStream, aOffset, aCount) {
+  onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
     let scriptStream = Cc["@mozilla.org/scriptableinputstream;1"]
                          .createInstance(Ci.nsIScriptableInputStream);
 
     scriptStream.init(aInputStream);
 
     scriptStream.read(aCount);
-  }
+  },
 };
 
 var tests = [
   setup,
   displayMessage1,
   displayPart1,
   displayMessage2,
   hackMetadata,
   displayPart2,
   checkCache,
-  teardown
+  teardown,
 ];
 
 async function setup() {
   // No offline download, otherwise nothing is cached.
   Services.prefs.setBoolPref("mail.server.server1.offline_download", false);
   // Make sure our small attachment doesn't automatically get loaded, so
   // give it a tiny threshold.
   // XXX We can't set this pref until the fake server supports body structure.
@@ -91,46 +89,46 @@ async function displayMessage1() {
   // that it reads on its startup.
   gIMAPService = Cc["@mozilla.org/messenger/messageservice;1?type=imap"]
                    .getService(Ci.nsIMsgMessageService);
 
   let db = IMAPPump.inbox.msgDatabase;
   let msg = db.getMsgHdrForMessageID(gMsgId1);
   gUidValidity = msg.folder.QueryInterface(Ci.nsIImapMailFolderSink).uidValidity;
   let listener = new PromiseTestUtils.PromiseUrlListener();
-  let url = new Object;
+  let url = {};
   gIMAPService.DisplayMessage(IMAPPump.inbox.getUriForMsg(msg),
                               streamListener,
                               null,
                               listener,
                               null,
                               url);
   gMsgURL1 = url.value;
   await listener.promise;
 }
 
 async function displayPart1() {
   let db = IMAPPump.inbox.msgDatabase;
   let msg = db.getMsgHdrForMessageID(gMsgId1);
-  let url = new Object;
+  let url = {};
   let listener = new PromiseTestUtils.PromiseUrlListener();
-  gIMAPService.DisplayMessage(IMAPPump.inbox.getUriForMsg(msg)+"?part=1.2&filename=check.gif",
+  gIMAPService.DisplayMessage(IMAPPump.inbox.getUriForMsg(msg) + "?part=1.2&filename=check.gif",
                               streamListener,
                               null,
                               listener,
                               null,
                               url);
   gMsgPartURL1 = url.value;
   await listener.promise;
 }
 
 async function displayMessage2() {
   let db = IMAPPump.inbox.msgDatabase;
   let msg = db.getMsgHdrForMessageID(gMsgId2);
-  let url = new Object;
+  let url = {};
   let listener = new PromiseTestUtils.PromiseUrlListener();
   gIMAPService.DisplayMessage(IMAPPump.inbox.getUriForMsg(msg),
                               streamListener,
                               null,
                               listener,
                               null,
                               url);
   gMsgURL2 = url.value;
@@ -139,37 +137,36 @@ async function displayMessage2() {
 
 function hackMetadata() {
   // The sad story is that the fake server doesn't support body structure, so we
   // always load all messages entirely.
   // Hack the meta data to pretend this isn't the case to force separate caching
   // of the PDF attachment.
   let extension = gUidValidity.toString(16);
 
-  MailServices.imap
-              .cacheStorage
-              .asyncOpenURI(gMsgURL2, extension, Ci.nsICacheStorage.OPEN_NORMALLY,
+  MailServices.imap.cacheStorage.asyncOpenURI(
+    gMsgURL2, extension, Ci.nsICacheStorage.OPEN_NORMALLY,
     {
-      onCacheEntryAvailable: function(cacheEntry, isNew, appCache, status) {
+      onCacheEntryAvailable(cacheEntry, isNew, appCache, status) {
         Assert.equal(status, Cr.NS_OK);
         cacheEntry.setMetaDataElement("ContentModified", "Modified View As Link");
       },
-      onCacheEntryCheck: function(cacheEntry, appCache) {
+      onCacheEntryCheck(cacheEntry, appCache) {
         return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
-      }
+      },
     }
   );
 }
 
 async function displayPart2() {
   let db = IMAPPump.inbox.msgDatabase;
   let msg = db.getMsgHdrForMessageID(gMsgId2);
-  let url = new Object;
+  let url = {};
   let listener = new PromiseTestUtils.PromiseUrlListener();
-  gIMAPService.DisplayMessage(IMAPPump.inbox.getUriForMsg(msg)+"?part=1.2&filename=check.pdf",
+  gIMAPService.DisplayMessage(IMAPPump.inbox.getUriForMsg(msg) + "?part=1.2&filename=check.pdf",
                               streamListener,
                               null,
                               listener,
                               null,
                               url);
   gMsgPartURL2 = url.value;
   await listener.promise;
 }
--- a/mailnews/imap/test/unit/test_chunkLastLF.js
+++ b/mailnews/imap/test/unit/test_chunkLastLF.js
@@ -7,34 +7,34 @@
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * Test content length for the IMAP protocol. This focuses on necko URLs
  * that are run externally.
  */
 
  // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 var gFile = do_get_file("../../../data/bug92111b");
 var gIMAPDaemon, gIMAPServer, gIMAPIncomingServer;
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessageToServer(file, mailbox)
-{
+function addMessageToServer(file, mailbox) {
   let URI = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
   let msg = new imapMessage(URI.spec, mailbox.uidnext++, []);
   // underestimate the actual file size, like some IMAP servers do
   msg.setSize(file.fileSize - 55);
   mailbox.addMessage(msg);
 }
 
-function run_test()
-{
+function run_test() {
   // Disable new mail notifications
   Services.prefs.setBoolPref("mail.biff.play_sound", false);
   Services.prefs.setBoolPref("mail.biff.show_alert", false);
   Services.prefs.setBoolPref("mail.biff.show_tray_icon", false);
   Services.prefs.setBoolPref("mail.biff.animate_dock_icon", false);
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
 
   // Crank down the message chunk size to make test cases easier
@@ -51,18 +51,17 @@ function run_test()
   // The server doesn't support more than one connection
   Services.prefs.setIntPref("mail.server.server1.max_cached_connections", 1);
   // We aren't interested in downloading messages automatically
   Services.prefs.setBoolPref("mail.server.server1.download_on_biff", false);
 
   async_run_tests([verifyContentLength, endTest]);
 }
 
-function* verifyContentLength()
-{
+function* verifyContentLength() {
   dump("adding message to server\n");
   // Add a message to the IMAP server
   addMessageToServer(gFile, gIMAPDaemon.getMailbox("INBOX"));
 
   let imapS = Cc["@mozilla.org/messenger/messageservice;1?type=imap"]
                 .getService(Ci.nsIMsgMessageService);
 
   dump("getting uri\n");
@@ -100,38 +99,37 @@ function* verifyContentLength()
   //                                                       Ci.nsIContentPolicy.TYPE_OTHER);
   // Currently attachments have their content length set to the length of the
   // entire message
   // do_check_eq(attachmentChannel.contentLength, gFile.fileSize);
 
   yield true;
 }
 
-function* endTest()
-{
+function* endTest() {
   gIMAPIncomingServer.closeCachedConnections();
   gIMAPServer.stop();
   let thread = gThreadManager.currentThread;
   while (thread.hasPendingEvents())
     thread.processNextEvent(true);
 
   yield true;
 }
 
 var gStreamListener = {
-  QueryInterface : ChromeUtils.generateQI([Ci.nsIStreamListener]),
-  _stream : null,
-  _data : null,
-  onStartRequest : function (aRequest) {
+  QueryInterface: ChromeUtils.generateQI([Ci.nsIStreamListener]),
+  _stream: null,
+  _data: null,
+  onStartRequest(aRequest) {
     this._data = "";
     this._stream = null;
   },
-  onStopRequest : function (aRequest, aStatusCode) {
+  onStopRequest(aRequest, aStatusCode) {
     async_driver();
   },
-  onDataAvailable : function (aRequest, aInputStream, aOff, aCount) {
+  onDataAvailable(aRequest, aInputStream, aOff, aCount) {
     if (this._stream == null) {
       this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
       this._stream.init(aInputStream);
     }
     this._data += this._stream.read(aCount);
   },
 };
--- a/mailnews/imap/test/unit/test_compactOfflineStore.js
+++ b/mailnews/imap/test/unit/test_compactOfflineStore.js
@@ -2,73 +2,69 @@
 /*
  * Test to ensure that compacting offline stores works correctly with imap folders
  * and returns success.
  */
 
 Services.prefs.setCharPref("mail.serverDefaultStoreContractID",
                            "@mozilla.org/msgstore/berkeleystore;1");
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 load("../../../resources/alertTestUtils.js");
 
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-
 // Globals
 var gRootFolder;
 var gImapInboxOfflineStoreSize;
 
 var gMsgFile1 = do_get_file("../../../data/bugmail10");
 var gMsgFile2 = do_get_file("../../../data/bugmail11");
-var gMsgFile3 = do_get_file("../../../data/draft1");
+// var gMsgFile3 = do_get_file("../../../data/draft1");
 var gMsgFile4 = do_get_file("../../../data/bugmail7");
 var gMsgFile5 = do_get_file("../../../data/bugmail6");
 
 // Copied straight from the example files
 var gMsgId1 = "200806061706.m56H6RWT004933@mrapp54.mozilla.org";
 var gMsgId2 = "200804111417.m3BEHTk4030129@mrapp51.mozilla.org";
-var gMsgId3 = "4849BF7B.2030800@example.com";
+// var gMsgId3 = "4849BF7B.2030800@example.com";
 var gMsgId4 = "bugmail7.m47LtAEf007542@mrapp51.mozilla.org";
 var gMsgId5 = "bugmail6.m47LtAEf007542@mrapp51.mozilla.org";
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox)
-{
+function addMessagesToServer(messages, mailbox) {
   // For every message we have, we need to convert it to a file:/// URI
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     let URI = Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
     // Create the imapMessage and store it on the mailbox.
     mailbox.addMessage(new imapMessage(URI.spec, mailbox.uidnext++, []));
   });
 }
 
-function addGeneratedMessagesToServer(messages, mailbox)
-{
+function addGeneratedMessagesToServer(messages, mailbox) {
   // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     let dataUri = Services.io.newURI("data:text/plain;base64," +
                                      btoa(message.toMessageString()));
     mailbox.addMessage(new imapMessage(dataUri.spec, mailbox.uidnext++, []));
   });
 }
 
 
 function checkOfflineStore(prevOfflineStoreSize) {
   dump("checking offline store\n");
-  let offset = new Object;
-  let size = new Object;
+  let offset = {};
+  let size = {};
   let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
-  if (enumerator)
-  {
-    while (enumerator.hasMoreElements())
-    {
+  if (enumerator) {
+    while (enumerator.hasMoreElements()) {
       let header = enumerator.getNext();
       // this will verify that the message in the offline store
       // starts with "From " - otherwise, it returns an error.
       if (header instanceof Ci.nsIMsgDBHdr &&
          (header.flags & Ci.nsMsgMessageFlags.Offline))
         IMAPPump.inbox.getOfflineFileStream(header.messageKey, offset, size).close();
     }
   }
@@ -142,28 +138,28 @@ var tests = [
     tmpFile.append("nstmp");
     Assert.ok(!tmpFile.exists());
     checkOfflineStore(gImapInboxOfflineStoreSize);
     asyncUrlListener.OnStopRunningUrl(null, 0);
     yield false;
     let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId2);
     Assert.equal(msgHdr.flags & Ci.nsMsgMessageFlags.Offline, 0);
   },
-  teardown
+  teardown,
 ];
 
 function setup() {
   setupIMAPPump();
 
   gRootFolder = IMAPPump.incomingServer.rootFolder;
   // these hacks are required because we've created the inbox before
   // running initial folder discovery, and adding the folder bails
   // out before we set it as verified online, so we bail out, and
   // then remove the INBOX folder since it's not verified.
-  IMAPPump.inbox.hierarchyDelimiter = '/';
+  IMAPPump.inbox.hierarchyDelimiter = "/";
   IMAPPump.inbox.verifiedAsOnlineFolder = true;
 
   let messageGenerator = new MessageGenerator();
   let messages = [];
   for (let i = 0; i < 50; i++)
     messages = messages.concat(messageGenerator.makeMessage());
 
   addGeneratedMessagesToServer(messages, IMAPPump.daemon.getMailbox("INBOX"));
@@ -175,28 +171,25 @@ function setup() {
                        {file: gMsgFile2, messageId: gMsgId2},
                        {file: gMsgFile5, messageId: gMsgId5}],
                       IMAPPump.daemon.getMailbox("INBOX"));
 }
 
 // nsIMsgCopyServiceListener implementation - runs next test when copy
 // is completed.
 var CopyListener = {
-  OnStartCopy: function() {},
-  OnProgress: function(aProgress, aProgressMax) {},
-  SetMessageKey: function(aKey) {
-    let hdr = localAccountUtils.inboxFolder.GetMessageHeader(aKey);
-    gMsgHdrs.push({hdr: hdr, ID: hdr.messageId});
-  },
-  SetMessageId: function(aMessageId) {},
-  OnStopCopy: function(aStatus) {
+  OnStartCopy() {},
+  OnProgress(aProgress, aProgressMax) {},
+  SetMessageKey(aKey) {},
+  SetMessageId(aMessageId) {},
+  OnStopCopy(aStatus) {
     // Check: message successfully copied.
     Assert.equal(aStatus, 0);
     async_driver();
-  }
+  },
 };
 
 function teardown() {
   gRootFolder = null;
   teardownIMAPPump();
 }
 
 function run_test() {
--- a/mailnews/imap/test/unit/test_converterImap.js
+++ b/mailnews/imap/test/unit/test_converterImap.js
@@ -4,34 +4,36 @@
 
 var {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm");
 var {convertMailStoreTo} = ChromeUtils.import("resource:///modules/mailstoreConverter.jsm");
 var {Log} = ChromeUtils.import("resource://gre/modules/Log.jsm");
 
 Services.prefs.setCharPref("mail.serverDefaultStoreContractID",
                            "@mozilla.org/msgstore/berkeleystore;1");
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 load("../../../resources/alertTestUtils.js");
 
 var log = Log.repository.getLogger("MailStoreConverter");
 
 var {FileUtils} = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
 
 // Globals
-var gRootFolder;
-
 var gMsgFile1 = do_get_file("../../../data/bugmail10");
 
 // Copied straight from the example files
 var gMsgId1 = "200806061706.m56H6RWT004933@mrapp54.mozilla.org";
 var gMsgId2 = "200804111417.m3BEHTk4030129@mrapp51.mozilla.org";
-var gMsgId3 = "4849BF7B.2030800@example.com";
+// var gMsgId3 = "4849BF7B.2030800@example.com";
 var gMsgId4 = "bugmail7.m47LtAEf007542@mrapp51.mozilla.org";
 var gMsgId5 = "bugmail6.m47LtAEf007542@mrapp51.mozilla.org";
 
 function checkConversion(aSource, aTarget) {
   let sourceContents = aSource.directoryEntries;
 
   while (sourceContents.hasMoreElements()) {
     let sourceContent = sourceContents.getNext().QueryInterface(Ci.nsIFile);
@@ -50,17 +52,17 @@ function checkConversion(aSource, aTarge
       let cur = FileUtils.File(OS.Path.join(targetFile.path, "cur"));
       Assert.ok(cur.exists());
       let tmp = FileUtils.File(OS.Path.join(targetFile.path, "tmp"));
       Assert.ok(tmp.exists());
       if (targetFile.leafName == "INBOX") {
         let curContents = cur.directoryEntries;
         let curContentsCount = 0;
         while (curContents.hasMoreElements()) {
-          let curContent = curContents.getNext();
+          curContents.getNext();
           curContentsCount += 1;
         }
         Assert.equal(curContentsCount, 8);
       }
     }
   }
 }
 
@@ -85,17 +87,16 @@ function addMessagesToServer(aMessages, 
   aMessages.forEach(function(message) {
     aMailbox.addMessage(new imapMessage(message.spec, aMailbox.uidnext++, []));
   });
 }
 
 function setup() {
   setupIMAPPump();
 
-  gRootFolder = IMAPPump.incomingServer.rootFolder;
   // These hacks are required because we've created the inbox before
   // running initial folder discovery, and adding the folder bails
   // out before we set it as verified online, so we bail out, and
   // then remove the INBOX folder since it's not verified.
   IMAPPump.inbox.hierarchyDelimiter = "/";
   IMAPPump.inbox.verifiedAsOnlineFolder = true;
 
   // Add a couple of messages to the INBOX.
@@ -112,17 +113,16 @@ async function downloadForOffline() {
   let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener();
   IMAPPump.inbox.downloadAllForOffline(promiseUrlListener, null);
   await promiseUrlListener.promise;
 }
 
 function run_test() {
   setup();
   registerCleanupFunction(function() {
-    gRootFolder = null;
     teardownIMAPPump();
   });
 
   run_next_test();
 }
 
 add_task(async function convert() {
   await downloadForOffline();
--- a/mailnews/imap/test/unit/test_copyThenMove.js
+++ b/mailnews/imap/test/unit/test_copyThenMove.js
@@ -1,47 +1,43 @@
 // This file extends test_imapFolderCopy.js to test message
 // moves from a local folder to an IMAP folder.
 //
 // Original Author: Kent James <kent@caspia.com>
 
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 var gEmptyLocal1, gEmptyLocal2;
 var gLastKey;
 var gMessages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
 var gCopyService = MailServices.copy;
 
-var {
-  getFolderProperties,
-  getSpecialFolderString,
-  allAccountsSorted,
-  getMostRecentFolders,
-  folderNameCompare,
-} = ChromeUtils.import("resource:///modules/folderUtils.jsm");
 var {toXPCOMArray} = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 
 var tests = [
   setup,
   function* copyFolder1() {
     dump("gEmpty1 " + gEmptyLocal1.URI + "\n");
-    let folders = new Array;
+    let folders = [];
     folders.push(gEmptyLocal1.QueryInterface(Ci.nsIMsgFolder));
     let array = toXPCOMArray(folders, Ci.nsIMutableArray);
     gCopyService.CopyFolders(array, IMAPPump.inbox, false, CopyListener, null);
     yield false;
   },
   function* copyFolder2() {
     dump("gEmpty2 " + gEmptyLocal2.URI + "\n");
-    let folders = new Array;
+    let folders = [];
     folders.push(gEmptyLocal2);
     let array = toXPCOMArray(folders, Ci.nsIMutableArray);
     gCopyService.CopyFolders(array, IMAPPump.inbox, false, CopyListener, null);
     yield false;
   },
   function* getLocalMessage1() {
     dump("getLocalMessage\n");
     var file = do_get_file("../../../data/bugmail1");
@@ -87,27 +83,25 @@ var tests = [
     Assert.ok(folder2 !== null);
     // folder 1 and 2 should each now have two messages in them.
     Assert.ok(folder1 !== null);
     Assert.equal(folderCount(folder2), 2);
     // The local inbox folder should now be empty, since the second
     // operation was a move.
     Assert.equal(folderCount(localAccountUtils.inboxFolder), 0);
   },
-  teardown
+  teardown,
 ];
 
-function folderCount(folder)
-{
+function folderCount(folder) {
   let enumerator = folder.msgDatabase.EnumerateMessages();
   let count = 0;
-  while (enumerator.hasMoreElements())
-  {
+  while (enumerator.hasMoreElements()) {
     count++;
-    let hdr = enumerator.getNext();
+    enumerator.getNext();
   }
   return count;
 }
 
 function setup() {
   // Turn off autosync_offline_stores because
   // fetching messages is invoked after copying the messages.
   // (i.e. The fetching process will be invoked after OnStopCopy)
@@ -119,37 +113,34 @@ function setup() {
 
   gEmptyLocal1 = localAccountUtils.rootFolder.createLocalSubfolder("empty 1");
   gEmptyLocal2 = localAccountUtils.rootFolder.createLocalSubfolder("empty 2");
 
   // these hacks are required because we've created the inbox before
   // running initial folder discovery, and adding the folder bails
   // out before we set it as verified online, so we bail out, and
   // then remove the INBOX folder since it's not verified.
-  IMAPPump.inbox.hierarchyDelimiter = '/';
+  IMAPPump.inbox.hierarchyDelimiter = "/";
   IMAPPump.inbox.verifiedAsOnlineFolder = true;
 }
 
 // nsIMsgCopyServiceListener implementation - runs next test when copy
 // is completed.
-var CopyListener =
-{
-  OnStartCopy: function() {},
-  OnProgress: function(aProgress, aProgressMax) {},
-  SetMessageKey: function(aKey)
-  {
+var CopyListener = {
+  OnStartCopy() {},
+  OnProgress(aProgress, aProgressMax) {},
+  SetMessageKey(aKey) {
     gLastKey = aKey;
   },
-  SetMessageId: function(aMessageId) {},
-  OnStopCopy: function(aStatus)
-  {
+  SetMessageId(aMessageId) {},
+  OnStopCopy(aStatus) {
     // Check: message successfully copied.
     Assert.equal(aStatus, 0);
     async_driver();
-  }
+  },
 };
 
 asyncUrlListener.callback = function(aUrl, aExitCode) {
   Assert.equal(aExitCode, 0);
 };
 
 function teardown() {
   gMessages.clear();
--- a/mailnews/imap/test/unit/test_customCommandReturnsFetchResponse.js
+++ b/mailnews/imap/test/unit/test_customCommandReturnsFetchResponse.js
@@ -3,144 +3,139 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Test to ensure that imap customCommandResult function works properly
  * Bug 778246
  */
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 // IMAP pump
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 // Globals
 
 // Messages to load must have CRLF line endings, that is Windows style
 var gMessageFileName = "bugmail10"; // message file used as the test message
 var gMessage, gExpectedLength;
 
-var gCustomList = ['Custom1', 'Custom2', 'Custom3'];
+var gCustomList = ["Custom1", "Custom2", "Custom3"];
 
 var gMsgWindow = Cc["@mozilla.org/messenger/msgwindow;1"]
   .createInstance(Ci.nsIMsgWindow);
 
 setupIMAPPump("CUSTOM1");
 
 // Definition of tests
 var tests = [
   loadImapMessage,
   testStoreCustomList,
   testStoreMinusCustomList,
   testStorePlusCustomList,
-  endTest
-]
+  endTest,
+];
 
 // load and update a message in the imap fake server
-function* loadImapMessage()
-{
+function* loadImapMessage() {
   gMessage = new imapMessage(specForFileName(gMessageFileName),
     IMAPPump.mailbox.uidnext++, []);
   gMessage.xCustomList = [];
   IMAPPump.mailbox.addMessage(gMessage);
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
-function* testStoreCustomList()
-{
+function* testStoreCustomList() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   gExpectedLength = gCustomList.length;
   let uri = IMAPPump.inbox.issueCommandOnMsgs("STORE", msgHdr.messageKey +
     " X-CUSTOM-LIST (" + gCustomList.join(" ") + ")", gMsgWindow);
   uri.QueryInterface(Ci.nsIMsgMailNewsUrl);
   uri.RegisterListener(storeCustomListSetListener);
   yield false;
 }
 
 // listens for response from customCommandResult request for X-CUSTOM-LIST
 var storeCustomListSetListener = {
-  OnStartRunningUrl: function (aUrl) {},
+  OnStartRunningUrl(aUrl) {},
 
-  OnStopRunningUrl: function (aUrl, aExitCode) {
+  OnStopRunningUrl(aUrl, aExitCode) {
     aUrl.QueryInterface(Ci.nsIImapUrl);
     Assert.equal(aUrl.customCommandResult,
       "(" + gMessage.xCustomList.join(" ") + ")");
     Assert.equal(gMessage.xCustomList.length, gExpectedLength);
     async_driver();
-  }
+  },
 };
 
-function* testStoreMinusCustomList()
-{
+function* testStoreMinusCustomList() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   gExpectedLength--;
   let uri = IMAPPump.inbox.issueCommandOnMsgs("STORE", msgHdr.messageKey +
     " -X-CUSTOM-LIST (" + gCustomList[0] + ")", gMsgWindow);
   uri.QueryInterface(Ci.nsIMsgMailNewsUrl);
   uri.RegisterListener(storeCustomListRemovedListener);
   yield false;
 }
 
 // listens for response from customCommandResult request for X-CUSTOM-LIST
 var storeCustomListRemovedListener = {
-  OnStartRunningUrl: function (aUrl) {},
+  OnStartRunningUrl(aUrl) {},
 
-  OnStopRunningUrl: function (aUrl, aExitCode) {
+  OnStopRunningUrl(aUrl, aExitCode) {
     aUrl.QueryInterface(Ci.nsIImapUrl);
     Assert.equal(aUrl.customCommandResult,
       "(" + gMessage.xCustomList.join(" ") + ")");
     Assert.equal(gMessage.xCustomList.length, gExpectedLength);
     async_driver();
-  }
+  },
 };
 
-function* testStorePlusCustomList()
-{
+function* testStorePlusCustomList() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   gExpectedLength++;
   let uri = IMAPPump.inbox.issueCommandOnMsgs("STORE", msgHdr.messageKey +
     ' +X-CUSTOM-LIST ("Custom4")', gMsgWindow);
   uri.QueryInterface(Ci.nsIMsgMailNewsUrl);
   uri.RegisterListener(storeCustomListAddedListener);
   yield false;
 }
 
 // listens for response from customCommandResult request for X-CUSTOM-LIST
 var storeCustomListAddedListener = {
-  OnStartRunningUrl: function (aUrl) {},
+  OnStartRunningUrl(aUrl) {},
 
-  OnStopRunningUrl: function (aUrl, aExitCode) {
+  OnStopRunningUrl(aUrl, aExitCode) {
     aUrl.QueryInterface(Ci.nsIImapUrl);
     Assert.equal(aUrl.customCommandResult,
       "(" + gMessage.xCustomList.join(" ") + ")");
     Assert.equal(gMessage.xCustomList.length, gExpectedLength);
     async_driver();
-  }
+  },
 };
 
 
 // Cleanup at end
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
 
-function run_test()
-{
+function run_test() {
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
   async_run_tests(tests);
 }
 
 /*
  * helper functions
  */
 
 // given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
+function specForFileName(aFileName) {
   let file = do_get_file("../../../data/" + aFileName);
   let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
   return msgfileuri.spec;
 }
--- a/mailnews/imap/test/unit/test_dod.js
+++ b/mailnews/imap/test/unit/test_dod.js
@@ -3,53 +3,54 @@
  * 'This part will be downloaded on demand' in message pane content (text) area.
  * To add messages to the test, place the 'markerRe' text used for testing in
  * the offending part that is displaying the problem message.
  * Prepend to the filename 'bodystructure' and save in the database
  * See current test files for examples.
  */
 
  // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var gServer, gIMAPIncomingServer, gIMAPDaemon;
 
 var tests = [
   streamMessages,
-  endTest
+  endTest,
 ];
 
-function run_test()
-{
+function run_test() {
   gIMAPDaemon = new imapDaemon();
   // pref tuning: one connection only, turn off notifications
-  Services.prefs.setIntPref( "mail.server.server1.max_cached_connections", 1);
+  Services.prefs.setIntPref("mail.server.server1.max_cached_connections", 1);
   Services.prefs.setBoolPref("mail.biff.play_sound", false);
   Services.prefs.setBoolPref("mail.biff.show_alert", false);
-  Services.prefs.setBoolPref("mail.biff.show_tray_icon",    false);
+  Services.prefs.setBoolPref("mail.biff.show_tray_icon", false);
   Services.prefs.setBoolPref("mail.biff.animate_dock_icon", false);
 
   // Force bodypart fetching as best as we can.
   // It would be advisable to enable log and check to be sure body[] is not
   // being fetched in lieu of parts. There may be conditions that bypass
   // bodypart fetch.
-  Services.prefs.setBoolPref("mail.inline_attachments",     false);
-  Services.prefs.setIntPref ("browser.cache.disk.capacity",              0);
-  Services.prefs.setIntPref ("mail.imap.mime_parts_on_demand_threshold", 1);
-  Services.prefs.setIntPref ("mailnews.display.disallow_mime_handlers",  0);
-  Services.prefs.setBoolPref("mail.server.default.fetch_by_chunks",  false);
+  Services.prefs.setBoolPref("mail.inline_attachments", false);
+  Services.prefs.setIntPref("browser.cache.disk.capacity", 0);
+  Services.prefs.setIntPref("mail.imap.mime_parts_on_demand_threshold", 1);
+  Services.prefs.setIntPref("mailnews.display.disallow_mime_handlers", 0);
+  Services.prefs.setBoolPref("mail.server.default.fetch_by_chunks", false);
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
 
   gServer = makeServer(gIMAPDaemon, "");
   gIMAPIncomingServer = createLocalIMAPServer(gServer.port);
 
-  //start first test
+  // start first test
   async_run_tests(tests);
 }
 
 function* streamMessages() {
   let inbox = gIMAPDaemon.getMailbox("INBOX");
   let imapS = Cc["@mozilla.org/messenger/messageservice;1?type=imap"]
                 .getService(Ci.nsIMsgMessageService);
   let fileNames = [];
@@ -61,65 +62,64 @@ function* streamMessages() {
     if (msgfileuri.fileName.toLowerCase().startsWith("bodystructure")) {
       inbox.addMessage(new imapMessage(msgfileuri.spec, inbox.uidnext++, []));
       fileNames.push(msgfileuri.fileName);
     }
   }
 
   // loop through the files twice, once for plain and one for html check
   let isPlain = true;
-  for (let cnt = 2 ; cnt > 0 ; cnt--, isPlain = false) {
+  for (let cnt = 2; cnt > 0; cnt--, isPlain = false) {
     // adjust these for 'view body as' setting
     // 0 orig html 3 sanitized 1 plain text
-    Services.prefs.setIntPref ("mailnews.display.html_as", isPlain ? 1 : 0);
+    Services.prefs.setIntPref("mailnews.display.html_as", isPlain ? 1 : 0);
     Services.prefs.setBoolPref("mailnews.display.prefer_plaintext", isPlain);
     let marker;
     if (isPlain)
       marker = "thisplaintextneedstodisplaytopasstest";
     else
       marker = "thishtmltextneedstodisplaytopasstest";
 
-    for (let i = 1; i < inbox.uidnext ; i++) {
+    for (let i = 1; i < inbox.uidnext; i++) {
       let uri = {};
       imapS.GetUrlForUri("imap-message://user@localhost/INBOX#" + i, uri, null);
       let channel = Services.io.newChannelFromURI(uri.value,
                                                   null,
                                                   Services.scriptSecurityManager.getSystemPrincipal(),
                                                   null,
                                                   Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                                   Ci.nsIContentPolicy.TYPE_OTHER);
       channel.asyncOpen(gStreamListener, null);
       yield false;
       let buf = gStreamListener._data;
-      dump("##########\nTesting--->" + fileNames[i-1] +
+      dump("##########\nTesting--->" + fileNames[i - 1] +
            "; 'prefer plain text': " + isPlain + "\n" +
            buf + "\n" +
-           "##########\nTesting--->" + fileNames[i-1] +
+           "##########\nTesting--->" + fileNames[i - 1] +
            "; 'prefer plain text': " + isPlain + "\n");
       try {
         Assert.ok(buf.includes(marker));
-      }
-      catch(e){}
+      } catch (e) {}
     }
   }
   yield true;
 }
 
 var gStreamListener = {
-  QueryInterface : ChromeUtils.generateQI([Ci.nsIStreamListener]),
-  _stream : null,
-  _data : null,
-  onStartRequest : function (aRequest) {
+  QueryInterface: ChromeUtils.generateQI([Ci.nsIStreamListener]),
+  _stream: null,
+  _data: null,
+  onStartRequest(aRequest) {
     this._data = "";
     this._stream = null;
   },
-  onStopRequest : function (aRequest, aStatusCode) {
+  onStopRequest(aRequest, aStatusCode) {
     async_driver();
   },
-  onDataAvailable : function (aRequest, aInputStream, aOff, aCount) {
+  onDataAvailable(aRequest, aInputStream, aOff, aCount) {
     if (this._stream == null) {
       this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
       this._stream.init(aInputStream);
     }
     this._data += this._stream.read(aCount);
   },
 };
 
--- a/mailnews/imap/test/unit/test_dontStatNoSelect.js
+++ b/mailnews/imap/test/unit/test_dontStatNoSelect.js
@@ -1,35 +1,38 @@
 // This file tests that checking folders for new mail with STATUS
 // doesn't try to STAT noselect folders.
 
 var gServer, gImapServer;
-var gIMAPInbox, gIMAPFolder1, gIMAPFolder2;
+var gIMAPInbox;
 var gFolder2Mailbox;
 var gFolder1, gFolder2;
 
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/messageGenerator.js");
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 var tests = [
   checkStatSelect,
   checkStatNoSelect,
-  endTest
+  endTest,
 ];
 
 function run_test() {
   var daemon = new imapDaemon();
-  daemon.createMailbox("folder 1", {subscribed : true});
+  daemon.createMailbox("folder 1", {subscribed: true});
   let folder1Mailbox = daemon.getMailbox("folder 1");
   folder1Mailbox.flags.push("\\Noselect");
-  daemon.createMailbox("folder 2", {subscribed : true});
+  daemon.createMailbox("folder 2", {subscribed: true});
   gFolder2Mailbox = daemon.getMailbox("folder 2");
   addMessageToFolder(gFolder2Mailbox);
   gServer = makeServer(daemon, "");
 
   gImapServer = createLocalIMAPServer(gServer.port);
 
   // Bug 1050840: check a newly created server has the default number of connections
   Assert.equal(gImapServer.maximumConnectionsNumber, 5);
@@ -62,17 +65,17 @@ function run_test() {
   Services.prefs.setBoolPref("mail.biff.animate_dock_icon", false);
 
   let rootFolder = gImapServer.rootFolder;
   gIMAPInbox = rootFolder.getFolderWithFlags(Ci.nsMsgFolderFlags.Inbox);
   gFolder1 = rootFolder.getChildNamed("folder 1");
   gFolder2 = rootFolder.getChildNamed("folder 2");
   gFolder1.setFlag(Ci.nsMsgFolderFlags.CheckNew);
   gFolder2.setFlag(Ci.nsMsgFolderFlags.CheckNew);
-  //start first test
+  // start first test
   async_run_tests(tests);
 }
 
 function* checkStatSelect() {
   // imap fake server's resetTest resets the authentication state - charming.
   // So poke the _test member directly.
   gServer._test = true;
   gIMAPInbox.getNewMessages(null, null);
@@ -112,26 +115,25 @@ function addMessageToFolder(mbox) {
 
   let msgURI =
     Services.io.newURI("data:text/plain;base64," +
                        btoa(messages[0].toMessageString()));
   let message = new imapMessage(msgURI.spec, mbox.uidnext++);
   mbox.addMessage(message);
 }
 
-function* endTest()
-{
+function* endTest() {
   Assert.equal(gFolder2.getNumUnread(false), 2);
   // Clean up the server in preparation
   gServer.resetTest();
   gImapServer.closeCachedConnections();
   gServer.performTest();
   gServer.stop();
   yield true;
 }
 
 var gFolderListener = {
-  OnItemBoolPropertyChanged : function(aItem, aProperty, aOldValue, aNewValue) {
+  OnItemBoolPropertyChanged(aItem, aProperty, aOldValue, aNewValue) {
     // This means that the STAT on "folder 2" has finished.
-    if (aProperty == "NewMessages" && aNewValue == true)
+    if (aProperty == "NewMessages" && aNewValue)
       async_driver();
-  }
+  },
 };
--- a/mailnews/imap/test/unit/test_downloadOffline.js
+++ b/mailnews/imap/test/unit/test_downloadOffline.js
@@ -1,25 +1,27 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Test to ensure that downloadAllForOffline works correctly with imap folders
  * and returns success.
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/messageGenerator.js");
 
 var gFileName = "bug460636";
 var gMsgFile = do_get_file("../../../data/" + gFileName);
 
 var tests = [
   setup,
   downloadAllForOffline,
   verifyDownloaded,
-  teardownIMAPPump
+  teardownIMAPPump,
 ];
 
 async function setup() {
   setupIMAPPump();
 
  /*
    * Ok, prelude done. Read the original message from disk
    * (through a file URI), and add it to the Inbox.
--- a/mailnews/imap/test/unit/test_fetchCustomAttribute.js
+++ b/mailnews/imap/test/unit/test_fetchCustomAttribute.js
@@ -2,16 +2,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Test to ensure that imap fetchCustomMsgAttribute function works properly
  */
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 // IMAP pump
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 // Globals
@@ -27,89 +29,83 @@ var gMsgWindow = Cc["@mozilla.org/messen
 
 setupIMAPPump("CUSTOM1");
 
 // Definition of tests
 var tests = [
   loadImapMessage,
   testFetchCustomValue,
   testFetchCustomList,
-  endTest
-]
+  endTest,
+];
 
 // load and update a message in the imap fake server
-function* loadImapMessage()
-{
+function* loadImapMessage() {
   let message = new imapMessage(specForFileName(gMessage),
                           IMAPPump.mailbox.uidnext++, []);
   message.xCustomValue = gCustomValue;
   message.xCustomList = gCustomList;
   IMAPPump.mailbox.addMessage(message);
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
 // Used to verify that nsIServerResponseParser.msg_fetch() can handle
 // not in a parenthesis group - Bug 750012
-function* testFetchCustomValue()
-{
+function* testFetchCustomValue() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   let uri = IMAPPump.inbox.fetchCustomMsgAttribute("X-CUSTOM-VALUE", msgHdr.messageKey, gMsgWindow);
   uri.QueryInterface(Ci.nsIMsgMailNewsUrl);
   uri.RegisterListener(fetchCustomValueListener);
   yield false;
 }
 
 // listens for resposne from fetchCustomMsgAttribute request for X-CUSTOM-VALUE
 var fetchCustomValueListener = {
-  OnStartRunningUrl: function (aUrl) {},
+  OnStartRunningUrl(aUrl) {},
 
-  OnStopRunningUrl: function (aUrl, aExitCode) {
+  OnStopRunningUrl(aUrl, aExitCode) {
     aUrl.QueryInterface(Ci.nsIImapUrl);
     Assert.equal(aUrl.customAttributeResult, gCustomValue);
     async_driver();
-  }
+  },
 };
 
 // Used to verify that nsIServerResponseParser.msg_fetch() can handle a parenthesis group - Bug 735542
-function* testFetchCustomList()
-{
+function* testFetchCustomList() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   let uri = IMAPPump.inbox.fetchCustomMsgAttribute("X-CUSTOM-LIST", msgHdr.messageKey, gMsgWindow);
   uri.QueryInterface(Ci.nsIMsgMailNewsUrl);
   uri.RegisterListener(fetchCustomListListener);
   yield false;
 }
 
 // listens for response from fetchCustomMsgAttribute request for X-CUSTOM-LIST
 var fetchCustomListListener = {
-  OnStartRunningUrl: function (aUrl) {},
+  OnStartRunningUrl(aUrl) {},
 
-  OnStopRunningUrl: function (aUrl, aExitCode) {
+  OnStopRunningUrl(aUrl, aExitCode) {
     aUrl.QueryInterface(Ci.nsIImapUrl);
     Assert.equal(aUrl.customAttributeResult, "(" + gCustomList.join(" ") + ")");
     async_driver();
-  }
+  },
 };
 
 // Cleanup at end
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
 
-function run_test()
-{
+function run_test() {
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
   async_run_tests(tests);
 }
 
 /*
  * helper functions
  */
 
 // given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
+function specForFileName(aFileName) {
   let file = do_get_file("../../../data/" + aFileName);
   let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
   return msgfileuri.spec;
 }
--- a/mailnews/imap/test/unit/test_filterCustomHeaders.js
+++ b/mailnews/imap/test/unit/test_filterCustomHeaders.js
@@ -3,34 +3,34 @@
  * filters on custom headers.
  * See https://bugzilla.mozilla.org/show_bug.cgi?id=655578
  * for more info.
  *
  * Original author: David Bienvenu <bienvenu@mozilla.com>
  */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 // IMAP pump
 
 setupIMAPPump();
 
 // Definition of tests
 
 var tests = [
   setupTest,
   checkFilterResults,
-  endTest
-]
+  endTest,
+];
 
-function run_test()
-{
-
+function run_test() {
   // Create a test filter.
   let filterList = IMAPPump.incomingServer.getFilterList(null);
   let filter = filterList.createFilter("test list-id");
   let searchTerm = filter.createTerm();
   searchTerm.attrib = Ci.nsMsgSearchAttrib.OtherHeader + 1;
   searchTerm.op = Ci.nsMsgSearchOp.Contains;
   let value = searchTerm.value;
   value.attrib = Ci.nsMsgSearchAttrib.OtherHeader;
--- a/mailnews/imap/test/unit/test_filterNeedsBody.js
+++ b/mailnews/imap/test/unit/test_filterNeedsBody.js
@@ -1,46 +1,46 @@
 /*
  * This file tests the needsBody attribute added to a
  *  custom filter action in bug 555051.
  *
  * Original author: Kent James <kent@caspia.com>
  * adapted from test_imapFilterActions.js
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
 load("../../../resources/logHelper.js");
 
 // Globals
 var gFilter; // a message filter with a subject search
 var gAction; // current message action (reused)
 var gMessage = "draft1"; // message file used as the test message
 
 // Definition of tests
 var tests = [
   setupIMAPPump,
   setup,
   function NeedsBodyTrue() {
     gAction.type = Ci.nsMsgFilterAction.Custom;
-    gAction.customId = 'mailnews@mozilla.org#testOffline';
+    gAction.customId = "mailnews@mozilla.org#testOffline";
     actionTestOffline.needsBody = true;
-    gAction.strValue = 'true';
+    gAction.strValue = "true";
   },
   runFilterAction,
   function NeedsBodyFalse() {
     gAction.type = Ci.nsMsgFilterAction.Custom;
-    gAction.customId = 'mailnews@mozilla.org#testOffline';
+    gAction.customId = "mailnews@mozilla.org#testOffline";
     actionTestOffline.needsBody = false;
-    gAction.strValue = 'false';
+    gAction.strValue = "false";
   },
   runFilterAction,
-  teardownIMAPPump
+  teardownIMAPPump,
 ];
 
 function setup() {
-
   // Create a test filter.
   let filterList = IMAPPump.incomingServer.getFilterList(null);
   gFilter = filterList.createFilter("test offline");
   let searchTerm = gFilter.createTerm();
   searchTerm.matchAll = true;
 
   gFilter.appendTerm(searchTerm);
   gFilter.enabled = true;
@@ -72,36 +72,33 @@ async function runFilterAction() {
 }
 
 function run_test() {
   tests.forEach(x => add_task(x));
   run_next_test();
 }
 
 // custom action to test offline status
-var actionTestOffline =
-{
+var actionTestOffline = {
   id: "mailnews@mozilla.org#testOffline",
   name: "test if offline",
-  apply: function(aMsgHdrs, aActionValue, aListener, aType, aMsgWindow)
-  {
-    for (var i = 0; i < aMsgHdrs.length; i++)
-    {
+  apply(aMsgHdrs, aActionValue, aListener, aType, aMsgWindow) {
+    for (let i = 0; i < aMsgHdrs.length; i++) {
       var msgHdr = aMsgHdrs.queryElementAt(i, Ci.nsIMsgDBHdr);
       let isOffline = msgHdr.flags & Ci.nsMsgMessageFlags.Offline;
-      Assert.equal(!!isOffline, aActionValue == 'true');
+      Assert.equal(!!isOffline, aActionValue == "true");
     }
   },
-  isValidForType: function(type, scope) {return true;},
+  isValidForType(type, scope) { return true; },
 
-  validateActionValue: function(value, folder, type) { return null;},
+  validateActionValue(value, folder, type) { return null; },
 
   allowDuplicates: false,
 
-  needsBody: false // set during test setup
+  needsBody: false, // set during test setup
 };
 
 /*
  * helper functions
  */
 
 // given a test file, return the file uri spec
 function specForFileName(aFileName) {
--- a/mailnews/imap/test/unit/test_folderOfflineFlags.js
+++ b/mailnews/imap/test/unit/test_folderOfflineFlags.js
@@ -5,50 +5,49 @@
 /**
  * Test that the folders that should get flagged for offline use do, and that
  * those that shouldn't don't.
  */
 
 // make SOLO_FILE="test_folderOfflineFlags.js" -C mailnews/imap/test check-one
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/alertTestUtils.js");
 
-// IMAP pump
-
-var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
-
 // Definition of tests
 var tests = [
   setup,
   testGeneralFoldersOffline,
   testTrashNotOffline,
   testJunkNotOffline,
-  teardown
+  teardown,
 ];
 
 /**
  * Setup the mailboxes that will be used for this test.
  */
 function* setup() {
   setupIMAPPump("GMail");
 
   IMAPPump.mailbox.subscribed = true;
   IMAPPump.mailbox.specialUseFlag = "\\Inbox";
-  IMAPPump.daemon.createMailbox("[Gmail]", {flags : ["\\Noselect"], subscribed: true});
-  IMAPPump.daemon.createMailbox("[Gmail]/All Mail", {specialUseFlag : "\\AllMail", subscribed: true});
-  IMAPPump.daemon.createMailbox("[Gmail]/Drafts", {specialUseFlag : "\\Drafts", subscribed: true});
-  IMAPPump.daemon.createMailbox("[Gmail]/Sent", {specialUseFlag : "\\Sent", subscribed: true});
-  IMAPPump.daemon.createMailbox("[Gmail]/Spam", {specialUseFlag : "\\Spam", subscribed: true});
-  IMAPPump.daemon.createMailbox("[Gmail]/Starred", {specialUseFlag : "\\Starred", subscribed: true});
-  IMAPPump.daemon.createMailbox("[Gmail]/Trash", {specialUseFlag : "\\Trash", subscribed: true});
-  IMAPPump.daemon.createMailbox("folder1", {subscribed : true});
-  IMAPPump.daemon.createMailbox("folder2", {subscribed : true});
+  IMAPPump.daemon.createMailbox("[Gmail]", {flags: ["\\Noselect"], subscribed: true});
+  IMAPPump.daemon.createMailbox("[Gmail]/All Mail", {specialUseFlag: "\\AllMail", subscribed: true});
+  IMAPPump.daemon.createMailbox("[Gmail]/Drafts", {specialUseFlag: "\\Drafts", subscribed: true});
+  IMAPPump.daemon.createMailbox("[Gmail]/Sent", {specialUseFlag: "\\Sent", subscribed: true});
+  IMAPPump.daemon.createMailbox("[Gmail]/Spam", {specialUseFlag: "\\Spam", subscribed: true});
+  IMAPPump.daemon.createMailbox("[Gmail]/Starred", {specialUseFlag: "\\Starred", subscribed: true});
+  IMAPPump.daemon.createMailbox("[Gmail]/Trash", {specialUseFlag: "\\Trash", subscribed: true});
+  IMAPPump.daemon.createMailbox("folder1", {subscribed: true});
+  IMAPPump.daemon.createMailbox("folder2", {subscribed: true});
 
   // select the inbox to force folder discovery, etc.
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
 
   yield false;
 }
 
 /**
--- a/mailnews/imap/test/unit/test_gmailAttributes.js
+++ b/mailnews/imap/test/unit/test_gmailAttributes.js
@@ -10,16 +10,18 @@
  *
  * See https://bugzilla.mozilla.org/show_bug.cgi?id=721316
  * for more info.
  *
  * Original Author: Atul Jangra<atuljangra66@gmail.com>
  */
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 // IMAP pump
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 // Messages to load must have CRLF line endings, that is Windows style
@@ -30,79 +32,74 @@ var gXGmThrid = "1266894439832287888";
 var gXGmLabels = '(\\Inbox \\Sent Important "Muy Importante" foo)';
 
 setupIMAPPump("GMail");
 
 IMAPPump.mailbox.specialUseFlag = "\\Inbox";
 IMAPPump.mailbox.subscribed = true;
 
 // need all mail folder to identify this as gmail server.
-IMAPPump.daemon.createMailbox("[Gmail]", {flags : ["\\NoSelect"] });
-IMAPPump.daemon.createMailbox("[Gmail]/All Mail", {subscribed : true,
-                                               specialUseFlag : "\\AllMail"});
+IMAPPump.daemon.createMailbox("[Gmail]", {flags: ["\\NoSelect"] });
+IMAPPump.daemon.createMailbox("[Gmail]/All Mail", {
+  subscribed: true,
+  specialUseFlag: "\\AllMail",
+});
 
 // Definition of tests
 var tests = [
   loadImapMessage,
   testFetchXGmMsgid,
   testFetchXGmThrid,
   testFetchXGmLabels,
-  endTest
-]
+  endTest,
+];
 
 // load and update a message in the imap fake server
-function* loadImapMessage()
-{
+function* loadImapMessage() {
   let message = new imapMessage(specForFileName(gMessage),
                                 IMAPPump.mailbox.uidnext++, []);
   message.xGmMsgid = gXGmMsgid;
   message.xGmThrid = gXGmThrid;
   message.xGmLabels = gXGmLabels;
   IMAPPump.mailbox.addMessage(message);
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
-function testFetchXGmMsgid()
-{
+function testFetchXGmMsgid() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   let val = msgHdr.getStringProperty("X-GM-MSGID");
   Assert.equal(val, gXGmMsgid);
 }
 
-function testFetchXGmThrid()
-{
+function testFetchXGmThrid() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   let val = msgHdr.getStringProperty("X-GM-THRID");
   Assert.equal(val, gXGmThrid);
 }
 
-function testFetchXGmLabels()
-{
+function testFetchXGmLabels() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   let val = msgHdr.getStringProperty("X-GM-LABELS");
    // We need to remove the starting "(" and ending ")" from gXGmLabels while comparing
-  Assert.equal(val, gXGmLabels.substring(1 ,gXGmLabels.length - 1));
+  Assert.equal(val, gXGmLabels.substring(1, gXGmLabels.length - 1));
 }
 
 // Cleanup at end
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
 
-function run_test()
-{
+function run_test() {
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
   async_run_tests(tests);
 }
 
 /*
  * helper functions
  */
 
 // given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
+function specForFileName(aFileName) {
   let file = do_get_file("../../../data/" + aFileName);
   let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
   return msgfileuri.spec;
 }
--- a/mailnews/imap/test/unit/test_gmailOfflineMsgStore.js
+++ b/mailnews/imap/test/unit/test_gmailOfflineMsgStore.js
@@ -12,18 +12,19 @@
  *
  * See https://bugzilla.mozilla.org/show_bug.cgi?id=721316
  * for more info.
  *
  * Original Author: Atul Jangra<atuljangra66@gmail.com>
  */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 
 
 // Messages to load must have CRLF line endings, that is Windows style
 
 var gMessage1 = "bugmail10"; // message file used as the test message for Inbox and fooFolder
@@ -55,37 +56,39 @@ var tests = [
   selectInboxMsg,
   StreamMessageInbox,
   createAndUpdate,
   addFoo,
   updateFoo,
   selectFooMsg,
   StreamMessageFoo,
   crossStreaming,
-  teardown
-]
+  teardown,
+];
 
 function setup() {
   // We aren't interested in downloading messages automatically
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
   Services.prefs.setBoolPref("mail.server.server1.offline_download", true);
   Services.prefs.setBoolPref("mail.biff.alert.show_preview", false);
 
   setupIMAPPump("GMail");
 
   IMAPPump.mailbox.specialUseFlag = "\\Inbox";
   IMAPPump.mailbox.subscribed = true;
 
   // need all mail folder to identify this as gmail server.
-  IMAPPump.daemon.createMailbox("[Gmail]", {flags : ["\\NoSelect"] });
-  IMAPPump.daemon.createMailbox("[Gmail]/All Mail", {subscribed : true,
-                                                 specialUseFlag : "\\AllMail"});
+  IMAPPump.daemon.createMailbox("[Gmail]", {flags: ["\\NoSelect"] });
+  IMAPPump.daemon.createMailbox("[Gmail]/All Mail", {
+    subscribed: true,
+    specialUseFlag: "\\AllMail",
+  });
 
   // Creating the mailbox "foo"
-  IMAPPump.daemon.createMailbox("foo", {subscribed : true});
+  IMAPPump.daemon.createMailbox("foo", {subscribed: true});
   fooBox = IMAPPump.daemon.getMailbox("foo");
 
   // Add message1 to inbox.
   let message = new imapMessage(specForFileName(gMessage1),
                             IMAPPump.mailbox.uidnext++, []);
   message.messageId = gMsgId1;
   message.xGmMsgid = gXGmMsgid1;
   message.xGmThrid = gXGmThrid1;
@@ -99,17 +102,17 @@ function* updateFolder() {
 }
 
 function* selectInboxMsg() {
   // Select mesasage1 from inbox which makes message1 available in offline store.
   let imapService = Cc["@mozilla.org/messenger/messageservice;1?type=imap"]
                         .getService(Ci.nsIMsgMessageService);
   let db = IMAPPump.inbox.msgDatabase;
   let msg1 = db.getMsgHdrForMessageID(gMsgId1);
-  let url = new Object;
+  let url = {};
   imapService.DisplayMessage(IMAPPump.inbox.getUriForMsg(msg1), streamListener,
                              null, asyncUrlListener, null, url);
   yield false;
 }
 
 function* StreamMessageInbox() {
   // Stream message1 from inbox
   let newMsgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
@@ -152,17 +155,17 @@ function* updateFoo() {
   yield false;
 }
 
 function* selectFooMsg() {
   // Select message2 from fooFolder, which makes fooFolder a local folder.
   let imapService = Cc["@mozilla.org/messenger/messageservice;1?type=imap"]
                        .getService(Ci.nsIMsgMessageService);
   let msg1 = fooFolder.msgDatabase.getMsgHdrForMessageID(gMsgId2);
-  let url = new Object;
+  let url = {};
   imapService.DisplayMessage(fooFolder.getUriForMsg(msg1), streamListener,
                              null, asyncUrlListener, null, url);
   yield false;
 }
 
 function* StreamMessageFoo() {
   // Stream message2 from fooFolder
   let newMsgHdr = fooFolder.msgDatabase.getMsgHdrForMessageID(gMsgId2);
@@ -187,17 +190,17 @@ function* crossStreaming() {
   let msgURI = fooFolder.getUriForMsg(msg2);
   let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
   let msgServ = messenger.messageServiceFromURI(msgURI);
   // pass true for aLocalOnly since message should be in offline store of Inbox.
   msgServ.streamMessage(msgURI, gStreamListener, null, null, false, "", true);
   gFooOfflineStoreSizeFinal = fooFolder.filePath.fileSize;
   gImapInboxOfflineStoreSizeFinal = IMAPPump.inbox.filePath.fileSize;
   Assert.equal(gFooOfflineStoreSizeFinal, gFooOfflineStoreSizeInitial);
-  Assert.equal(gImapInboxOfflineStoreSizeFinal,gImapInboxOfflineStoreSizeInitial);
+  Assert.equal(gImapInboxOfflineStoreSizeFinal, gImapInboxOfflineStoreSizeInitial);
   yield false;
 }
 
 function teardown() {
   teardownIMAPPump();
 }
 
 function run_test() {
@@ -208,61 +211,59 @@ function run_test() {
  * helper functions
  */
 
 asyncUrlListener.callback = function(aUrl, aExitCode) {
   Assert.equal(aExitCode, 0);
 };
 
  // We use this as a display consumer
-var streamListener =
-{
+var streamListener = {
   _data: "",
 
   QueryInterface:
     ChromeUtils.generateQI([Ci.nsIStreamListener, Ci.nsIRequestObserver]),
 
   // nsIRequestObserver
-  onStartRequest: function(aRequest) {
+  onStartRequest(aRequest) {
   },
-  onStopRequest: function(aRequest, aStatusCode) {
+  onStopRequest(aRequest, aStatusCode) {
     Assert.equal(aStatusCode, 0);
   },
 
   // nsIStreamListener
-  onDataAvailable: function(aRequest, aInputStream, aOffset, aCount) {
+  onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
     let scriptStream = Cc["@mozilla.org/scriptableinputstream;1"]
-                          .createInstance(Ci.nsIScriptableInputStream);
+                         .createInstance(Ci.nsIScriptableInputStream);
 
     scriptStream.init(aInputStream);
 
     scriptStream.read(aCount);
-  }
+  },
 };
 
 var gStreamListener = {
-  QueryInterface : ChromeUtils.generateQI([Ci.nsIStreamListener]),
-  _stream : null,
-  _data : null,
-  onStartRequest : function (aRequest) {
+  QueryInterface: ChromeUtils.generateQI([Ci.nsIStreamListener]),
+  _stream: null,
+  _data: null,
+  onStartRequest(aRequest) {
     this._data = "";
   },
-  onStopRequest : function (aRequest, aStatusCode) {
+  onStopRequest(aRequest, aStatusCode) {
     async_driver();
     this._stream = null;
   },
-  onDataAvailable : function (aRequest, aInputStream, aOff, aCount) {
+  onDataAvailable(aRequest, aInputStream, aOff, aCount) {
     if (this._stream == null) {
       this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
       this._stream.init(aInputStream);
     }
     this._data += this._stream.read(aCount);
   },
 };
 
 // given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
+function specForFileName(aFileName) {
   let file = do_get_file("../../../data/" + aFileName);
   let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
   return msgfileuri.spec;
 }
 
--- a/mailnews/imap/test/unit/test_imapAttachmentSaves.js
+++ b/mailnews/imap/test/unit/test_imapAttachmentSaves.js
@@ -1,51 +1,53 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Tests imap save and detach attachments.
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 // javascript mime emitter functions
 var mimeMsg = {};
 ChromeUtils.import("resource:///modules/gloda/mimemsg.js", mimeMsg);
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 // IMAP pump
 
-var kAttachFileName = 'bob.txt';
+var kAttachFileName = "bob.txt";
 
 setupIMAPPump();
 
 // Dummy message window so we can say the inbox is open in a window.
 var dummyMsgWindow = Cc["@mozilla.org/messenger/msgwindow;1"]
                        .createInstance(Ci.nsIMsgWindow);
 
 var tests = [
   loadImapMessage,
   startMime,
   startDetach,
   testDetach,
-  endTest
-]
+  endTest,
+];
 
 // load and update a message in the imap fake server
-function* loadImapMessage()
-{
+function* loadImapMessage() {
   let gMessageGenerator = new MessageGenerator();
   // create a synthetic message with attachment
   let smsg = gMessageGenerator.makeMessage({
     attachments: [
-      {filename: kAttachFileName, body: 'I like cheese!'}
+      {filename: kAttachFileName, body: "I like cheese!"},
     ],
   });
 
   let msgURI =
     Services.io.newURI("data:text/plain;base64," +
                        btoa(smsg.toMessageString()));
   let imapInbox = IMAPPump.daemon.getMailbox("INBOX");
   let message = new imapMessage(msgURI.spec, imapInbox.uidnext++, []);
@@ -55,44 +57,41 @@ function* loadImapMessage()
   Assert.equal(1, IMAPPump.inbox.getTotalMessages(false));
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   Assert.ok(msgHdr instanceof Ci.nsIMsgDBHdr);
 
   yield true;
 }
 
 // process the message through mime
-function* startMime()
-{
+function* startMime() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
 
   mimeMsg.MsgHdrToMimeMessage(msgHdr, gCallbackObject, gCallbackObject.callback,
                               true /* allowDownload */);
   yield false;
 }
 
 // detach any found attachments
-function* startDetach()
-{
+function* startDetach() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   let msgURI = msgHdr.folder.generateMessageURI(msgHdr.messageKey);
 
   let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
   let attachment = gCallbackObject.attachments[0];
 
   messenger.detachAttachmentsWOPrompts(do_get_profile(), 1,
                                        [attachment.contentType], [attachment.url],
                                        [attachment.name], [msgURI], null);
   // deletion of original message should kick async_driver.
   yield false;
 }
 
 // test that the detachment was successful
-function* testDetach()
-{
+function* testDetach() {
   // This test seems to fail on Linux without the following delay.
   mailTestUtils.do_timeout_function(200, async_driver);
   yield false;
   // Check that the file attached to the message now exists in the profile
   // directory.
   let checkFile = do_get_profile().clone();
   checkFile.append(kAttachFileName);
   Assert.ok(checkFile.exists());
@@ -103,35 +102,33 @@ function* testDetach()
   // Get the message header - detached copy has UID 2.
   let msgHdr = IMAPPump.inbox.GetMessageHeader(2);
   Assert.ok(msgHdr !== null);
   let messageContent = getContentFromMessage(msgHdr);
   Assert.ok(messageContent.includes("AttachmentDetached"));
 }
 
 // Cleanup
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
 
 function SaveAttachmentCallback() {
   this.attachments = null;
 }
 
 SaveAttachmentCallback.prototype = {
   callback: function saveAttachmentCallback_callback(aMsgHdr, aMimeMessage) {
     this.attachments = aMimeMessage.allAttachments;
     async_driver();
-  }
-}
+  },
+};
 var gCallbackObject = new SaveAttachmentCallback();
 
-function run_test()
-{
+function run_test() {
   // Add folder listeners that will capture async events
   const nsIMFNService = Ci.nsIMsgFolderNotificationService;
   MailServices.mfn.addListener(mfnListener, nsIMFNService.msgsDeleted);
 
   // We need to register the dummyMsgWindow so that when we've finished running
   // the append url, in nsImapMailFolder::OnStopRunningUrl, we'll think the
   // Inbox is open in a folder and update it, which the detach code relies
   // on to finish the detach.
@@ -168,16 +165,14 @@ function getContentFromMessage(aMsgHdr) 
   let sis = Cc["@mozilla.org/scriptableinputstream;1"]
               .createInstance(Ci.nsIScriptableInputStream);
   sis.init(streamListener.inputStream);
   let content = sis.read(MAX_MESSAGE_LENGTH);
   sis.close();
   return content;
 }
 
-var mfnListener =
-{
-  msgsDeleted: function msgsDeleted(aMsgArray)
-  {
+var mfnListener = {
+  msgsDeleted(aMsgArray) {
     dump("msg deleted\n");
     async_driver();
   },
 };
--- a/mailnews/imap/test/unit/test_imapAuthMethods.js
+++ b/mailnews/imap/test/unit/test_imapAuthMethods.js
@@ -7,86 +7,92 @@
  * BUGS:
  * - cleanup after each test doesn't seem to work correctly. Effects:
  *    - one more "lsub" per test, e.g. "capability", "auth...", "lsub", "lsub", "lsub", "list" in the 3. test.,
  *    - root folder check succeeds although login failed
  * - removeIncomingServer(..., true); (cleanup files) fails.
  */
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
 load("../../../resources/alertTestUtils.js");
 
-//const kUsername = "fred";
-//const kPassword = "wilma";
+// const kUsername = "fred";
+// const kPassword = "wilma";
 
 var thisTest;
-var test = null;
 
 var tests = [
-  { title: "Cleartext password, with server only supporting old-style login",
-    clientAuthMethod : Ci.nsMsgAuthMethod.passwordCleartext,
-    serverAuthMethods : [],
-    expectSuccess : true,
-    transaction: [ "capability", "login", "lsub" ] },
-  // Just to make sure we clean up properly - in the test and in TB, e.g. don't cache stuff
-  { title: "Second time Cleartext password, with server only supporting old-style login",
-    clientAuthMethod : Ci.nsMsgAuthMethod.passwordCleartext,
-    serverAuthMethods : [],
-    expectSuccess : true,
-    transaction: [ "capability", "login", "lsub" ] },
- { title: "Cleartext password, with server supporting AUTH PLAIN, LOGIN and CRAM",
-    clientAuthMethod : Ci.nsMsgAuthMethod.passwordCleartext,
-    serverAuthMethods : [ "PLAIN", "LOGIN", "CRAM-MD5" ],
-    expectSuccess : true,
-    transaction: [ "capability", "authenticate PLAIN", "lsub" ] },
-  { title: "Cleartext password, with server supporting only AUTH LOGIN",
-    clientAuthMethod : Ci.nsMsgAuthMethod.passwordCleartext,
-    serverAuthMethods : [ "LOGIN" ],
-    expectSuccess : true,
-    transaction: [ "capability", "authenticate LOGIN", "lsub" ] },
-  { title: "Encrypted password, with server supporting PLAIN and CRAM",
-    clientAuthMethod : Ci.nsMsgAuthMethod.passwordEncrypted,
-    serverAuthMethods : [ "PLAIN", "LOGIN", "CRAM-MD5" ],
-    expectSuccess : true,
-    transaction: [ "capability", "authenticate CRAM-MD5", "lsub" ] },
-  { title: "Encrypted password, with server only supporting AUTH PLAIN and LOGIN (must fail)",
-    clientAuthMethod : Ci.nsMsgAuthMethod.passwordEncrypted,
-    serverAuthMethods : [ "PLAIN", "LOGIN" ],
-    expectSuccess : false,
-    transaction: [ "capability" ] },
-  { title: "Any secure method, with server supporting AUTH PLAIN and CRAM",
-    clientAuthMethod : Ci.nsMsgAuthMethod.secure,
-    serverAuthMethods : [ "PLAIN" , "LOGIN", "CRAM-MD5" ],
-    expectSuccess : true,
-    transaction: [ "capability", "authenticate CRAM-MD5", "lsub" ] },
-  { title: "Any secure method, with server only supporting AUTH PLAIN and LOGIN (must fail)",
-    clientAuthMethod : Ci.nsMsgAuthMethod.secure,
-    serverAuthMethods : [ "PLAIN" ],
-    expectSuccess : false,
-    transaction: [ "capability" ] },
+  {
+    title: "Cleartext password, with server only supporting old-style login",
+    clientAuthMethod: Ci.nsMsgAuthMethod.passwordCleartext,
+    serverAuthMethods: [],
+    expectSuccess: true,
+    transaction: [ "capability", "login", "lsub" ],
+  }, {
+    // Just to make sure we clean up properly - in the test and in TB, e.g. don't cache stuff
+    title: "Second time Cleartext password, with server only supporting old-style login",
+    clientAuthMethod: Ci.nsMsgAuthMethod.passwordCleartext,
+    serverAuthMethods: [],
+    expectSuccess: true,
+    transaction: [ "capability", "login", "lsub" ],
+  }, {
+    title: "Cleartext password, with server supporting AUTH PLAIN, LOGIN and CRAM",
+    clientAuthMethod: Ci.nsMsgAuthMethod.passwordCleartext,
+    serverAuthMethods: [ "PLAIN", "LOGIN", "CRAM-MD5" ],
+    expectSuccess: true,
+    transaction: [ "capability", "authenticate PLAIN", "lsub" ],
+  }, {
+    title: "Cleartext password, with server supporting only AUTH LOGIN",
+    clientAuthMethod: Ci.nsMsgAuthMethod.passwordCleartext,
+    serverAuthMethods: [ "LOGIN" ],
+    expectSuccess: true,
+    transaction: [ "capability", "authenticate LOGIN", "lsub" ],
+  }, {
+    title: "Encrypted password, with server supporting PLAIN and CRAM",
+    clientAuthMethod: Ci.nsMsgAuthMethod.passwordEncrypted,
+    serverAuthMethods: [ "PLAIN", "LOGIN", "CRAM-MD5" ],
+    expectSuccess: true,
+    transaction: [ "capability", "authenticate CRAM-MD5", "lsub" ],
+  }, {
+    title: "Encrypted password, with server only supporting AUTH PLAIN and LOGIN (must fail)",
+    clientAuthMethod: Ci.nsMsgAuthMethod.passwordEncrypted,
+    serverAuthMethods: [ "PLAIN", "LOGIN" ],
+    expectSuccess: false,
+    transaction: [ "capability" ],
+  }, {
+    title: "Any secure method, with server supporting AUTH PLAIN and CRAM",
+    clientAuthMethod: Ci.nsMsgAuthMethod.secure,
+    serverAuthMethods: [ "PLAIN", "LOGIN", "CRAM-MD5" ],
+    expectSuccess: true,
+    transaction: [ "capability", "authenticate CRAM-MD5", "lsub" ],
+  }, {
+    title: "Any secure method, with server only supporting AUTH PLAIN and LOGIN (must fail)",
+    clientAuthMethod: Ci.nsMsgAuthMethod.secure,
+    serverAuthMethods: [ "PLAIN" ],
+    expectSuccess: false,
+    transaction: [ "capability" ],
+  },
 ];
 
 function nextTest() {
   try {
     thisTest = tests.shift();
-    if (!thisTest)
-    {
+    if (!thisTest) {
         endTest();
         return;
     }
     /* doesn't work, hangs on first performTest(...)
     {
       dump("resetTest()\n");
       server.resetTest();
       dump("server.performTest()\n");
       server.performTest();
     }*/
 
-    test = thisTest.title;
     dump("NEXT test: " + thisTest.title + "\n");
 
     // (re)create fake server
     var daemon = new imapDaemon();
     var server = makeServer(daemon, "",
       {kAuthSchemes: thisTest.serverAuthMethods});
     server.setDebugLevel(fsDebugAll);
 
@@ -96,50 +102,49 @@ function nextTest() {
     let msgServer = incomingServer;
     msgServer.QueryInterface(Ci.nsIMsgIncomingServer);
     msgServer.authMethod = thisTest.clientAuthMethod;
 
     // connect
     incomingServer.performExpand(null);
     server.performTest("LSUB");
 
-    dump("should " + (thisTest.expectSuccess ? "":"not ") + "be logged in\n");
+    dump("should " + (thisTest.expectSuccess ? "" : "not ") + "be logged in\n");
     Assert.equal(true, incomingServer instanceof Ci.nsIImapServerSink);
-    //do_check_eq(thisTest.expectSuccess, incomingServer.userAuthenticated); TODO fails second time
-    //var rootFolder = incomingServer.rootFolder;
+    // do_check_eq(thisTest.expectSuccess, incomingServer.userAuthenticated); TODO fails second time
+    // var rootFolder = incomingServer.rootFolder;
     // Client creates fake Inbox, so check other folder
-    //do_check_eq(thisTest.expectSuccess,
+    // do_check_eq(thisTest.expectSuccess,
     //    rootFolder.containsChildNamed("somemailbox")); TODO
     do_check_transaction(server.playTransaction(), thisTest.transaction, false);
 
     do {
       incomingServer.closeCachedConnections();
-    } while (incomingServer.serverBusy)
+    } while (incomingServer.serverBusy);
     incomingServer.shutdown();
     incomingServer.clearAllValues();
     deleteIMAPServer(incomingServer);
     MailServices.accounts.closeCachedConnections();
     MailServices.accounts.shutdownServers();
     MailServices.accounts.UnloadAccounts();
     server.stop();
-
   } catch (e) {
-    //server.stop();
-    //endTest();
+    // server.stop();
+    // endTest();
     do_throw(e);
   }
 
   nextTest();
 }
 
 function deleteIMAPServer(incomingServer) {
   if (!incomingServer)
     return;
   MailServices.accounts.removeIncomingServer(incomingServer, false); // TODO cleanup files = true fails
-  //incomingServer = null;
+  // incomingServer = null;
   MailServices.accounts.removeAccount(MailServices.accounts.defaultAccount);
 }
 
 
 function run_test() {
   do_test_pending();
 
   registerAlertTestUtils();
--- a/mailnews/imap/test/unit/test_imapAutoSync.js
+++ b/mailnews/imap/test/unit/test_imapAutoSync.js
@@ -13,267 +13,257 @@
 
 // We test that checking non-inbox folders for new messages isn't
 // interfering with autoSync's detection of new messages.
 
 // We also test that folders that have messages added to them via move/copy
 // get put in the front of the queue.
 
 // IMAP pump
+/* import-globals-from ../../../test/resources/logHelper.js */
 load("../../../resources/logHelper.js");
 
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/asyncTestUtils.js");
 
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/alertTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 // Globals
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 setupIMAPPump();
 
 var msgFlagOffline = Ci.nsMsgMessageFlags.Offline;
 var nsIAutoSyncMgrListener = Ci.nsIAutoSyncMgrListener;
 
-var gGotAlert;
-
 var gAutoSyncManager = Cc["@mozilla.org/imap/autosyncmgr;1"]
                        .getService(Ci.nsIAutoSyncManager);
 
 // Definition of tests
 var tests = [
   test_createTargetFolder,
   test_checkForNewMessages,
   test_triggerAutoSyncIdle,
   test_moveMessageToTargetFolder,
   test_waitForTargetUpdate,
-  endTest
-]
+  endTest,
+];
 
 var gTargetFolder;
 
-function* test_createTargetFolder()
-{
+function* test_createTargetFolder() {
   gAutoSyncManager.addListener(gAutoSyncListener);
 
   IMAPPump.incomingServer.rootFolder.createSubfolder("targetFolder", null);
   yield false;
   gTargetFolder = IMAPPump.incomingServer.rootFolder.getChildNamed("targetFolder");
   Assert.ok(gTargetFolder instanceof Ci.nsIMsgImapMailFolder);
   // set folder to be checked for new messages when inbox is checked.
   gTargetFolder.setFlag(Ci.nsMsgFolderFlags.CheckNew);
 }
 
-function* test_checkForNewMessages()
-{
+function* test_checkForNewMessages() {
   addMessageToFolder(gTargetFolder);
   // This will update the INBOX and STATUS targetFolder. We only care about
   // the latter.
   IMAPPump.inbox.getNewMessages(null, null);
   IMAPPump.server.performTest("STATUS");
   // Now we'd like to make autosync update folders it knows about, to
   // get the initial autosync out of the way.
   yield true;
 }
 
-function test_triggerAutoSyncIdle()
-{
+function test_triggerAutoSyncIdle() {
   // wait for both folders to get updated.
   gAutoSyncListener._waitingForDiscoveryList.push(IMAPPump.inbox);
   gAutoSyncListener._waitingForDiscoveryList.push(gTargetFolder);
   gAutoSyncListener._waitingForDiscovery = true;
   let observer = gAutoSyncManager.QueryInterface(Ci.nsIObserver);
   observer.observe(null, "mail-startup-done", "");
   observer.observe(null, "mail:appIdle", "idle");
 }
 
 // move the message to a diffent folder
-function* test_moveMessageToTargetFolder()
-{
+function* test_moveMessageToTargetFolder() {
   let observer = gAutoSyncManager.QueryInterface(Ci.nsIObserver);
   observer.observe(null, "mail:appIdle", "back");
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   Assert.ok(msgHdr !== null);
 
   // Now move this message to the target folder.
   let messages = Cc["@mozilla.org/array;1"]
                    .createInstance(Ci.nsIMutableArray);
   messages.appendElement(msgHdr);
   MailServices.copy.CopyMessages(IMAPPump.inbox, messages, gTargetFolder, true,
                                  asyncCopyListener, null, false);
   yield false;
 }
 
-function* test_waitForTargetUpdate()
-{
+function* test_waitForTargetUpdate() {
   // After the copy, now we expect to get notified of the gTargetFolder
   // getting updated, after we simulate going idle.
   gAutoSyncListener._waitingForUpdate = true;
   gAutoSyncListener._waitingForUpdateList.push(gTargetFolder);
   gAutoSyncManager.QueryInterface(Ci.nsIObserver).observe(null, "mail:appIdle",
                                                           "idle");
   // Need two yield here to get results of both onDownloadCompleted and onDiscoveryQProcessed
   yield false;
   yield false;
 }
 
 // Cleanup
-function endTest()
-{
+function endTest() {
   let enumerator = gTargetFolder.messages;
   let numMsgs = 0;
   while (enumerator.hasMoreElements()) {
     numMsgs++;
     Assert.notEqual(enumerator.getNext()
                      .QueryInterface(Ci.nsIMsgDBHdr).flags & msgFlagOffline, 0);
   }
   Assert.equal(2, numMsgs);
   Assert.equal(gAutoSyncListener._waitingForUpdateList.length, 0);
   Assert.ok(!gAutoSyncListener._waitingForDiscovery);
   Assert.ok(!gAutoSyncListener._waitingForUpdate);
   teardownIMAPPump();
 }
 
-function run_test()
-{
+function run_test() {
   // Add folder listeners that will capture async events
   const nsIMFNService = Ci.nsIMsgFolderNotificationService;
   let flags =
         nsIMFNService.folderAdded |
         nsIMFNService.msgsMoveCopyCompleted |
         nsIMFNService.msgAdded;
   MailServices.mfn.addListener(mfnListener, flags);
   addMessageToFolder(IMAPPump.inbox);
 
   async_run_tests(tests);
 }
 
 // listeners for various events to drive the tests.
 
-var mfnListener =
-{
-  msgsMoveCopyCompleted: function (aMove, aSrcMsgs, aDestFolder, aDestMsgs)
-  {
-    dump('msgsMoveCopyCompleted to folder ' + aDestFolder.name + '\n');
+var mfnListener = {
+  msgsMoveCopyCompleted(aMove, aSrcMsgs, aDestFolder, aDestMsgs) {
+    dump("msgsMoveCopyCompleted to folder " + aDestFolder.name + "\n");
   },
-  folderAdded: function folderAdded(aFolder)
-  {
+  folderAdded(aFolder) {
     // we are only using async yield on the target folder add
     if (aFolder.name == "targetFolder")
       async_driver();
   },
 
-  msgAdded: function msgAdded(aMsg)
-  {
+  msgAdded(aMsg) {
   },
 };
 
-var gAutoSyncListener =
-{
-  _inQFolderList : new Array(),
-  _runnning : false,
+var gAutoSyncListener = {
+  _inQFolderList: [],
+  _runnning: false,
   _lastMessage: {},
-  _waitingForUpdateList : new Array(),
-  _waitingForUpdate : false,
-  _waitingForDiscoveryList : new Array(),
-  _waitingForDiscovery : false,
+  _waitingForUpdateList: [],
+  _waitingForUpdate: false,
+  _waitingForDiscoveryList: [],
+  _waitingForDiscovery: false,
 
-  onStateChanged : function(running) {
+  onStateChanged(running) {
     try {
       this._runnning = running;
     } catch (e) {
-      throw(e);
+      throw (e);
     }
   },
 
-  onFolderAddedIntoQ : function(queue, folder) {
+  onFolderAddedIntoQ(queue, folder) {
     try {
-      let queueName = "";
       dump("folder added into Q " + this.qName(queue) + " " + folder.URI + "\n");
       if (folder instanceof Ci.nsIMsgFolder &&
           queue == nsIAutoSyncMgrListener.PriorityQueue) {
+        return;
       }
     } catch (e) {
-      throw(e);
+      throw (e);
     }
   },
-  onFolderRemovedFromQ : function(queue, folder) {
+  onFolderRemovedFromQ(queue, folder) {
     try {
       dump("folder removed from Q " + this.qName(queue) + " " + folder.URI + "\n");
       if (folder instanceof Ci.nsIMsgFolder &&
           queue == nsIAutoSyncMgrListener.PriorityQueue) {
+        return;
       }
     } catch (e) {
-      throw(e);
+      throw (e);
     }
   },
-  onDownloadStarted : function(folder, numOfMessages, totalPending) {
+  onDownloadStarted(folder, numOfMessages, totalPending) {
     try {
       dump("folder download started" + folder.URI + "\n");
     } catch (e) {
-      throw(e);
+      throw (e);
     }
   },
 
-  onDownloadCompleted : function(folder) {
+  onDownloadCompleted(folder) {
     try {
       dump("folder download completed" + folder.URI + "\n");
       if (folder instanceof Ci.nsIMsgFolder) {
         let index = mailTestUtils.non_strict_index_of(this._waitingForUpdateList, folder);
         if (index != -1)
           this._waitingForUpdateList.splice(index, 1);
         if (this._waitingForUpdate && this._waitingForUpdateList.length == 0) {
           dump("got last folder update looking for\n");
           this._waitingForUpdate = false;
           async_driver();
         }
       }
     } catch (e) {
-      throw(e);
+      throw (e);
     }
   },
 
-  onDownloadError : function(folder) {
+  onDownloadError(folder) {
     if (folder instanceof Ci.nsIMsgFolder) {
       dump("OnDownloadError: " + folder.prettyName + "\n");
     }
   },
 
-  onDiscoveryQProcessed : function (folder, numOfHdrsProcessed, leftToProcess) {
+  onDiscoveryQProcessed(folder, numOfHdrsProcessed, leftToProcess) {
     dump("onDiscoveryQProcessed: " + folder.prettyName + "\n");
     let index = mailTestUtils.non_strict_index_of(this._waitingForDiscoveryList, folder);
     if (index != -1)
       this._waitingForDiscoveryList.splice(index, 1);
     if (this._waitingForDiscovery && this._waitingForDiscoveryList.length == 0) {
       dump("got last folder discovery looking for\n");
       this._waitingForDiscovery = false;
       async_driver();
     }
   },
 
-  onAutoSyncInitiated : function (folder) {
+  onAutoSyncInitiated(folder) {
   },
-  qName : function(queueType) {
+  qName(queueType) {
     if (queueType == nsIAutoSyncMgrListener.PriorityQueue)
       return "priorityQ";
     if (queueType == nsIAutoSyncMgrListener.UpdateQueue)
      return "updateQ";
     if (queueType == nsIAutoSyncMgrListener.DiscoveryQueue)
       return "discoveryQ";
     return "";
   },
-}
+};
 
 /*
  * helper functions
  */
 
 // load and update a message in the imap fake server
-function addMessageToFolder(folder)
-{
+function addMessageToFolder(folder) {
   let messages = [];
   let gMessageGenerator = new MessageGenerator();
   messages = messages.concat(gMessageGenerator.makeMessage());
 
   let msgURI =
     Services.io.newURI("data:text/plain;base64," +
                        btoa(messages[0].toMessageString()));
   let imapMailbox =  IMAPPump.daemon.getMailbox(folder.name);
--- a/mailnews/imap/test/unit/test_imapChunks.js
+++ b/mailnews/imap/test/unit/test_imapChunks.js
@@ -8,18 +8,17 @@ var {IOUtils} = ChromeUtils.import("reso
 var gIMAPDaemon, gServer, gIMAPIncomingServer, gSavedMsgFile;
 
 var gIMAPService = Cc["@mozilla.org/messenger/messageservice;1?type=imap"]
                        .getService(Ci.nsIMsgMessageService);
 
 var gFileName = "bug92111";
 var gMsgFile = do_get_file("../../../data/" + gFileName);
 
-function run_test()
-{
+function run_test() {
   /*
    * Set up an IMAP server. The bug is only triggered when nsMsgSaveAsListener
    * is used (i.e., for IMAP and NNTP).
    */
   gIMAPDaemon = new imapDaemon();
   gServer = makeServer(gIMAPDaemon, "");
   gIMAPIncomingServer = createLocalIMAPServer(gServer.port);
 
@@ -56,68 +55,64 @@ function run_test()
    * <profile_dir>/mailtest/ImapMail (where fakeserver puts the IMAP mailbox
    * files). If we pass the test, we'll remove the file afterwards
    * (cf. UrlListener), otherwise it's kept in IMapMD.
    */
   gSavedMsgFile = Services.dirsvc.get("IMapMD", Ci.nsIFile);
   gSavedMsgFile.append(gFileName + ".eml");
 
   do_test_pending();
-  do_timeout(10000, function(){
-      do_throw('SaveMessageToDisk did not complete within 10 seconds' +
-        '(incorrect messageURI?). ABORTING.');
-      }
-    );
+  do_timeout(10000, function() {
+    do_throw("SaveMessageToDisk did not complete within 10 seconds" +
+      "(incorrect messageURI?). ABORTING.");
+    }
+  );
 
   /*
    * From nsIMsgMessageService.idl:
    * void SaveMessageToDisk(in string aMessageURI, in nsIFile aFile,
    *                        in boolean aGenerateDummyEnvelope,
    *                        in nsIUrlListener aUrlListener, out nsIURI aURL,
    *                        in boolean canonicalLineEnding,
    *                        in nsIMsgWindow aMsgWindow);
    * Enforcing canonicalLineEnding (i.e., CRLF) makes sure that the
    * test also runs successfully on platforms not using CRLF by default.
    */
   gIMAPService.SaveMessageToDisk("imap-message://user@localhost/INBOX#"
-                                 + (inbox.uidnext-1), gSavedMsgFile,
+                                 + (inbox.uidnext - 1), gSavedMsgFile,
                                  false, UrlListener, {}, true, null);
 }
 
-function endTest()
-{
+function endTest() {
   gIMAPIncomingServer.closeCachedConnections();
   gServer.stop();
   var thread = gThreadManager.currentThread;
   while (thread.hasPendingEvents())
     thread.processNextEvent(true);
 
   try {
     gSavedMsgFile.remove(false);
-  }
-  catch (ex) {
+  } catch (ex) {
     dump(ex);
     do_throw(ex);
   }
   do_test_finished();
 }
 
-var UrlListener =
-{
-  OnStartRunningUrl: function(url) { },
-  OnStopRunningUrl: function(url, rc)
-  {
+var UrlListener = {
+  OnStartRunningUrl(url) {},
+  OnStopRunningUrl(url, rc) {
     // operation succeeded
     Assert.equal(rc, 0);
 
     // File contents were not modified
     Assert.equal(IOUtils.loadFileToString(gMsgFile),
                  IOUtils.loadFileToString(gSavedMsgFile));
 
     // The file doesn't get closed straight away, but does after a little bit.
     // So wait, and then remove it. We need to test this to ensure we don't
     // indefinitely lock the file.
     do_timeout(1000, endTest);
-  }
+  },
 };
 
 // XXX IRVING we need a separate check somehow to make sure we store the correct
 // content size for chunked messages where the server lied
--- a/mailnews/imap/test/unit/test_imapContentLength.js
+++ b/mailnews/imap/test/unit/test_imapContentLength.js
@@ -6,44 +6,46 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * Test content length for the IMAP protocol. This focuses on necko URLs
  * that are run externally.
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 var gMsgHdr = null;
 
 // Take a multipart message as we're testing attachment URLs as well
 var gFile = do_get_file("../../../data/multipart-complex2");
 
 var tests = [
   setup,
   addMessageToServer,
   verifyContentLength,
-  teardown
+  teardown,
 ];
 
 // Adds some messages directly to a mailbox (eg new mail)
 function* addMessageToServer() {
   let URI = Services.io.newFileURI(gFile).QueryInterface(Ci.nsIFileURL);
   IMAPPump.mailbox.addMessage(new imapMessage(URI.spec, IMAPPump.mailbox.uidnext++, []));
 
   IMAPPump.inbox.updateFolder(null);
   yield false;
 }
 
 var msgFolderListener = {
-  msgAdded: function(aMsgHdr) {
+  msgAdded(aMsgHdr) {
     gMsgHdr = aMsgHdr;
     executeSoon(async_driver);
   },
 };
 
 function setup() {
   setupIMAPPump();
 
--- a/mailnews/imap/test/unit/test_imapCopyTimeout.js
+++ b/mailnews/imap/test/unit/test_imapCopyTimeout.js
@@ -3,72 +3,75 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This tests our handling of server timeouts during online move of
 // an imap message. The move is done as an offline operation and then
 // played back, to copy what the apps do.
 
 Services.prefs.setIntPref("mailnews.tcptimeout", 2);
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/alertTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 // IMAP pump
 
 // Globals
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 setupIMAPPump();
 
 var gGotAlert = false;
 var gGotMsgAdded = false;
 
+/* exported alert */// to alertTestUtils.js
 function alert(aDialogTitle, aText) {
   Assert.ok(aText.startsWith("Connection to server localhost timed out."));
   gGotAlert = true;
   async_driver();
 }
 
 var CopyListener = {
-  OnStartCopy: function() {},
-  OnProgress: function(aProgress, aProgressMax) {},
-  SetMessageKey: function(aMsgKey) {},
-  GetMessageId: function() {},
-  OnStopCopy: function(aStatus) {
+  OnStartCopy() {},
+  OnProgress(aProgress, aProgressMax) {},
+  SetMessageKey(aMsgKey) {},
+  GetMessageId() {},
+  OnStopCopy(aStatus) {
     async_driver();
-  }
+  },
 };
 
 // Definition of tests
 var tests = [
   createTargetFolder,
   loadImapMessage,
   moveMessageToTargetFolder,
   waitForOfflinePlayback,
   updateTargetFolder,
-  endTest
-]
+  endTest,
+];
 
 var gTargetFolder;
-function* createTargetFolder()
-{
+function* createTargetFolder() {
   IMAPPump.daemon.copySleep = 5000;
   IMAPPump.incomingServer.rootFolder.createSubfolder("targetFolder", null);
   yield false;
   gTargetFolder = IMAPPump.incomingServer.rootFolder.getChildNamed("targetFolder");
   Assert.ok(gTargetFolder instanceof Ci.nsIMsgImapMailFolder);
   gTargetFolder.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
 // load and update a message in the imap fake server
-function* loadImapMessage()
-{
+function* loadImapMessage() {
   let messages = [];
   let gMessageGenerator = new MessageGenerator();
   messages = messages.concat(gMessageGenerator.makeMessage());
 
   let msgURI =
     Services.io.newURI("data:text/plain;base64," +
                        btoa(messages[0].toMessageString()));
   let imapInbox = IMAPPump.daemon.getMailbox("INBOX");
@@ -79,83 +82,75 @@ function* loadImapMessage()
   Assert.equal(1, IMAPPump.inbox.getTotalMessages(false));
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   Assert.ok(msgHdr instanceof Ci.nsIMsgDBHdr);
 
   yield true;
 }
 
 // move the message to a diffent folder
-function* moveMessageToTargetFolder()
-{
+function* moveMessageToTargetFolder() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
 
   // Now move this message to the target folder.
   var messages = Cc["@mozilla.org/array;1"]
                    .createInstance(Ci.nsIMutableArray);
   messages.appendElement(msgHdr);
   // This should cause the move to be done as an offline imap operation
   // that's played back immediately.
   MailServices.copy.CopyMessages(IMAPPump.inbox, messages, gTargetFolder, true,
                                  CopyListener, gDummyMsgWindow, true);
   yield false;
 }
 
-function* waitForOfflinePlayback()
-{
+function* waitForOfflinePlayback() {
   // just wait for the alert about timed out connection.
   yield false;
   // then, wait for a second so we don't get our next url aborted.
   do_timeout(1000, async_driver);
   yield false;
 }
 
-function* updateTargetFolder()
-{
+function* updateTargetFolder() {
   gTargetFolder.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
 // Cleanup
-function endTest()
-{
+function endTest() {
   Assert.ok(gGotAlert);
   // Make sure neither source nor target folder have offline events.
   Assert.ok(!IMAPPump.inbox.getFlag(Ci.nsMsgFolderFlags.OfflineEvents));
   Assert.ok(!gTargetFolder.getFlag(Ci.nsMsgFolderFlags.OfflineEvents));
 
   // fake server does the copy, but then times out, so make sure the target
   // folder has only 1 message, not the multiple ones it would have if we
   // retried.
   Assert.equal(gTargetFolder.getTotalMessages(false), 1);
   teardownIMAPPump();
 }
 
 // listeners
 
-var mfnListener =
-{
-  folderAdded: function folderAdded(aFolder)
-  {
+var mfnListener = {
+  folderAdded(aFolder) {
     // we are only using async yield on the target folder add
     if (aFolder.name == "targetFolder")
       async_driver();
   },
 
-  msgAdded: function msgAdded(aMsg)
-  {
+  msgAdded(aMsg) {
     if (!gGotMsgAdded)
       async_driver();
     gGotMsgAdded = true;
   },
 
 };
 
-function run_test()
-{
+function run_test() {
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
   // Add folder listeners that will capture async events
   const nsIMFNService = Ci.nsIMsgFolderNotificationService;
   let flags =
         nsIMFNService.folderAdded |
         nsIMFNService.msgAdded;
   MailServices.mfn.addListener(mfnListener, flags);
   async_run_tests(tests);
--- a/mailnews/imap/test/unit/test_imapFilterActions.js
+++ b/mailnews/imap/test/unit/test_imapFilterActions.js
@@ -4,69 +4,51 @@
  * mail are not tested. The tests check various counts, and the effects
  * on the message database of the filters. Effects on IMAP server
  * flags, if any, are not tested.
  *
  * Original author: Kent James <kent@caspia.com>
  * adapted from test_localToImapFilter.js
  */
 
-var {
-  getFolderProperties,
-  getSpecialFolderString,
-  allAccountsSorted,
-  getMostRecentFolders,
-  folderNameCompare,
-} = ChromeUtils.import("resource:///modules/folderUtils.jsm");
-
-var nsMsgSearchScope = Ci.nsMsgSearchScope;
-var nsMsgSearchAttrib = Ci.nsMsgSearchAttrib;
-var nsMsgSearchOp = Ci.nsMsgSearchOp;
-var Is = nsMsgSearchOp.Is;
-var Contains = nsMsgSearchOp.Contains;
-var Subject = nsMsgSearchAttrib.Subject;
-var Body = nsMsgSearchAttrib.Body;
+var Is = Ci.nsMsgSearchOp.Is;
+var Contains = Ci.nsMsgSearchOp.Contains;
+var Subject = Ci.nsMsgSearchAttrib.Subject;
+var Body = Ci.nsMsgSearchAttrib.Body;
 
 // Globals
 var gSubfolder; // a local message folder used as a target for moves and copies
-var gLastKey; // the last message key
 var gFilter; // a message filter with a subject search
 var gAction; // current message action (reused)
 var gBodyFilter; // a message filter with a body search
 var gInboxListener; // database listener object
-var gContinueListener; // what listener is used to continue the test?
 var gHeader; // the current message db header
-var gChecks; // the function that will be used to check the results of the filter
 var gInboxCount; // the previous number of messages in the Inbox
 var gSubfolderCount; // the previous number of messages in the subfolder
-var gMoveCallbackCount; // the number of callbacks from the move listener
-var gCurTestNum; // the current test number
 var gMessage = "draft1"; // message file used as the test message
 
 // subject of the test message
 var gMessageSubject = "Hello, did you receive my bugmail?";
 
 // a string in the body of the test message
 var gMessageInBody = "an HTML message";
 
 // various object references
-var gCopyService = MailServices.copy;
 var gDbService = Cc["@mozilla.org/msgDatabase/msgDBService;1"]
                              .getService(Ci.nsIMsgDBService);
 
 // Definition of tests. The test function name is the filter action
 // being tested, with "Body" appended to tests that use delayed
 // application of filters due to a body search
-var gTestArray =
-[
+var gTestArray = [
   setupIMAPPump,
-    // optionally set server parameters, here enabling debug messages
-  //function serverParms() {
-  //  IMAPPump.server.setDebugLevel(fsDebugAll);
-  //},
+  // optionally set server parameters, here enabling debug messages
+  // function serverParms() {
+  //   IMAPPump.server.setDebugLevel(fsDebugAll);
+  // },
   setupFilters,
   // The initial tests do not result in new messages added.
   async function MoveToFolder() {
     gAction.type = Ci.nsMsgFilterAction.MoveToFolder;
     gAction.targetFolderUri = gSubfolder.URI;
     gInboxCount = folderCount(IMAPPump.inbox);
     gSubfolderCount = folderCount(gSubfolder);
     await setupTest(gFilter, gAction);
@@ -324,29 +306,27 @@ var gTestArray =
     gSubfolderCount = folderCount(gSubfolder);
     await setupTest(gBodyFilter, gAction);
 
     testCounts(true, 1, 1, 1);
     Assert.equal(gInboxCount + 1, folderCount(IMAPPump.inbox));
     Assert.equal(gSubfolderCount + 1, folderCount(gSubfolder));
   },
   /**/
-  endTest
+  endTest,
 
 ];
 
 function run_test() {
-  //Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
+  // Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
   gTestArray.forEach(x => add_task(x));
   run_next_test();
 }
 
-function setupFilters()
-{
-
+function setupFilters() {
   // Create a non-body filter.
   let filterList = IMAPPump.incomingServer.getFilterList(null);
   gFilter = filterList.createFilter("subject");
   let searchTerm = gFilter.createTerm();
   searchTerm.attrib = Subject;
   searchTerm.op = Is;
   var value = searchTerm.value;
   value.attrib = Subject;
@@ -378,231 +358,204 @@ function setupFilters()
   MailServices.mailSession.AddFolderListener(FolderListener, Ci.nsIFolderListener.event);
   gPreviousUnread = 0;
 
   // When a message body is not downloaded, and then later a filter is
   //   applied that requires a download of message bodies, then the previous
   //   bodies are downloaded - and the message filters are applied twice!
   //   See bug 1116228, but for now workaround by always downloading bodies.
   IMAPPump.incomingServer.downloadBodiesOnGetNewMail = true;
-
 }
 
 /*
  * functions used to support test setup and execution
  */
 
 // basic preparation done for each test
-async function setupTest(aFilter, aAction)
-{
+async function setupTest(aFilter, aAction) {
   let filterList = IMAPPump.incomingServer.getFilterList(null);
   while (filterList.filterCount)
     filterList.removeFilterAt(0);
-  if (aFilter)
-  {
+  if (aFilter) {
     aFilter.clearActionList();
     if (aAction) {
       aFilter.appendAction(aAction);
       filterList.insertFilterAt(0, aFilter);
     }
   }
   if (gInboxListener)
     gDbService.unregisterPendingListener(gInboxListener);
 
   IMAPPump.inbox.clearNewMessages();
 
   gInboxListener = new DBListener();
   gDbService.registerPendingListener(IMAPPump.inbox, gInboxListener);
-  gMoveCallbackCount = 0;
   IMAPPump.mailbox.addMessage(new imapMessage(specForFileName(gMessage),
                           IMAPPump.mailbox.uidnext++, []));
   let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener();
   IMAPPump.inbox.updateFolderWithListener(null, promiseUrlListener);
   await promiseUrlListener.promise;
   await PromiseTestUtils.promiseDelay(200);
 }
 
 // Cleanup, null out everything, close all cached connections and stop the
 // server
-function endTest()
-{
+function endTest() {
   if (gInboxListener)
     gDbService.unregisterPendingListener(gInboxListener);
   gInboxListener = null;
   MailServices.mailSession.RemoveFolderListener(FolderListener);
   teardownIMAPPump();
 }
 
 /*
  * listener objects
  */
 
 // nsIFolderListener implementation
 var FolderListener = {
-  OnItemEvent: function OnItemEvent(aEventFolder, aEvent) {
+  OnItemEvent(aEventFolder, aEvent) {
     dump("received folder event " + aEvent +
          " folder " + aEventFolder.name +
          "\n");
-  }
+  },
 };
 
 // nsIDBChangeListener implementation. Counts of calls are kept, but not
 // currently used in the tests. Current role is to provide a reference
 // to the new message header (plus give some examples of using db listeners
 // in javascript).
-function DBListener()
-{
+function DBListener() {
   this.counts = {};
   let counts = this.counts;
   counts.onHdrFlagsChanged = 0;
   counts.onHdrDeleted = 0;
   counts.onHdrAdded = 0;
   counts.onParentChanged = 0;
   counts.onAnnouncerGoingAway = 0;
   counts.onReadChanged = 0;
   counts.onJunkScoreChanged = 0;
   counts.onHdrPropertyChanged = 0;
   counts.onEvent = 0;
 }
 
-DBListener.prototype =
-{
-  onHdrFlagsChanged:
-    function onHdrFlagsChanged(aHdrChanged, aOldFlags, aNewFlags, aInstigator)
-    {
-      this.counts.onHdrFlagsChanged++;
-    },
+DBListener.prototype = {
+  onHdrFlagsChanged(aHdrChanged, aOldFlags, aNewFlags, aInstigator) {
+    this.counts.onHdrFlagsChanged++;
+  },
+
+  onHdrDeleted(aHdrChanged, aParentKey, Flags, aInstigator) {
+    this.counts.onHdrDeleted++;
+  },
 
-  onHdrDeleted:
-    function onHdrDeleted(aHdrChanged, aParentKey, Flags, aInstigator)
-    {
-      this.counts.onHdrDeleted++;
-    },
+  onHdrAdded(aHdrChanged, aParentKey, aFlags, aInstigator) {
+    this.counts.onHdrAdded++;
+    gHeader = aHdrChanged;
+  },
 
-  onHdrAdded:
-    function onHdrAdded(aHdrChanged, aParentKey, aFlags, aInstigator)
-    {
-      this.counts.onHdrAdded++;
-      gHeader = aHdrChanged;
-    },
-
-  onParentChanged:
-    function onParentChanged(aKeyChanged, oldParent, newParent, aInstigator)
-    {
-      this.counts.onParentChanged++;
-    },
+  onParentChanged(aKeyChanged, oldParent, newParent, aInstigator) {
+    this.counts.onParentChanged++;
+  },
 
-  onAnnouncerGoingAway:
-    function onAnnouncerGoingAway(instigator)
-    {
-      if (gInboxListener)
-        try {
-          IMAPPump.inbox.msgDatabase.RemoveListener(gInboxListener);
-        }
-        catch (e) {dump(" listener not found\n");}
-      this.counts.onAnnouncerGoingAway++;
-    },
-
-  onReadChanged:
-    function onReadChanged(aInstigator)
-    {
-      this.counts.onReadChanged++;
-    },
+  onAnnouncerGoingAway(instigator) {
+    if (gInboxListener) {
+      try {
+        IMAPPump.inbox.msgDatabase.RemoveListener(gInboxListener);
+      } catch (e) {
+        dump(" listener not found\n");
+      }
+    }
+    this.counts.onAnnouncerGoingAway++;
+  },
 
-  onJunkScoreChanged:
-    function onJunkScoreChanged(aInstigator)
-    {
-      this.counts.onJunkScoreChanged++;
-    },
+  onReadChanged(aInstigator) {
+    this.counts.onReadChanged++;
+  },
+
+  onJunkScoreChanged(aInstigator) {
+    this.counts.onJunkScoreChanged++;
+  },
 
-  onHdrPropertyChanged:
-    function onHdrPropertyChanged(aHdrToChange, aPreChange, aStatus, aInstigator)
-    {
-      this.counts.onHdrPropertyChanged++;
-    },
+  onHdrPropertyChanged(aHdrToChange, aPreChange, aStatus, aInstigator) {
+    this.counts.onHdrPropertyChanged++;
+  },
 
-  onEvent:
-    function onEvent(aDB, aEvent)
-    {
-      this.counts.onEvent++;
-    },
-
+  onEvent(aDB, aEvent) {
+    this.counts.onEvent++;
+  },
 };
 
 /*
  * helper functions
  */
 
 // return the number of messages in a folder (and check that the
 // folder counts match the database counts)
-function folderCount(folder)
-{
+function folderCount(folder) {
   // count using the database
   let enumerator = folder.msgDatabase.EnumerateMessages();
   let dbCount = 0;
-  while (enumerator.hasMoreElements())
-  {
+  while (enumerator.hasMoreElements()) {
     dbCount++;
-    let hdr = enumerator.getNext();
+    enumerator.getNext();
   }
 
   // count using the folder
-  let folderCount = folder.getTotalMessages(false);
+  let count = folder.getTotalMessages(false);
 
   // compare the two
-  Assert.equal(dbCount, folderCount);
+  Assert.equal(dbCount, count);
   return dbCount;
 }
 
 // given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
+function specForFileName(aFileName) {
   let file = do_get_file("../../../data/" + aFileName);
   let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
   return msgfileuri.spec;
 }
 
 // shorthand for the inbox message summary database
-function db()
-{
+function db() {
   return IMAPPump.inbox.msgDatabase;
 }
 
 // static variables used in testCounts
 var gPreviousUnread = 0;
 
 // Test various counts.
 //
 //  aHasNew:         folder hasNew flag
 //  aUnreadDelta:    change in unread count for the folder
 //  aFolderNewDelta: change in new count for the folder
 //  aDbNewDelta:     change in new count for the database
 //
-function testCounts(aHasNew, aUnreadDelta, aFolderNewDelta, aDbNewDelta)
-{
+function testCounts(aHasNew, aUnreadDelta, aFolderNewDelta, aDbNewDelta) {
   try {
-  let folderNew = IMAPPump.inbox.getNumNewMessages(false);
-  let hasNew = IMAPPump.inbox.hasNewMessages;
-  let unread = IMAPPump.inbox.getNumUnread(false);
-  let countOut = {};
-  let arrayOut = {};
-  db().getNewList(countOut, arrayOut);
-  let dbNew = countOut.value ? countOut.value : 0;
-  dump(" hasNew: " + hasNew +
-       " unread: " + unread +
-       " folderNew: " + folderNew +
-       " dbNew: " + dbNew +
-       " prevUnread " + gPreviousUnread +
-       "\n");
-  Assert.equal(aHasNew, hasNew);
-  Assert.equal(aUnreadDelta, unread - gPreviousUnread);
-  gPreviousUnread = unread;
-  // This seems to be reset for each folder update.
-  //
-  // This check seems to be failing in SeaMonkey builds, yet I can see no ill
-  // effects of this in the actual program. Fixing this is complex because of
-  // the messiness of new count management (see bug 507638 for a
-  // refactoring proposal, and attachment 398899 on bug 514801 for one possible
-  // fix to this particular test). So I am disabling this.
-  //Assert.equal(aFolderNewDelta, folderNew);
-  Assert.equal(aDbNewDelta, dbNew);
-  } catch (e) {dump(e);}
+    let folderNew = IMAPPump.inbox.getNumNewMessages(false);
+    let hasNew = IMAPPump.inbox.hasNewMessages;
+    let unread = IMAPPump.inbox.getNumUnread(false);
+    let countOut = {};
+    let arrayOut = {};
+    db().getNewList(countOut, arrayOut);
+    let dbNew = countOut.value ? countOut.value : 0;
+    dump(" hasNew: " + hasNew +
+         " unread: " + unread +
+         " folderNew: " + folderNew +
+         " dbNew: " + dbNew +
+         " prevUnread " + gPreviousUnread +
+         "\n");
+    Assert.equal(aHasNew, hasNew);
+    Assert.equal(aUnreadDelta, unread - gPreviousUnread);
+    gPreviousUnread = unread;
+    // This seems to be reset for each folder update.
+    //
+    // This check seems to be failing in SeaMonkey builds, yet I can see no ill
+    // effects of this in the actual program. Fixing this is complex because of
+    // the messiness of new count management (see bug 507638 for a
+    // refactoring proposal, and attachment 398899 on bug 514801 for one possible
+    // fix to this particular test). So I am disabling this.
+    // Assert.equal(aFolderNewDelta, folderNew);
+    Assert.equal(aDbNewDelta, dbNew);
+  } catch (e) {
+    dump(e);
+  }
 }
--- a/mailnews/imap/test/unit/test_imapFilterActionsPostplugin.js
+++ b/mailnews/imap/test/unit/test_imapFilterActionsPostplugin.js
@@ -1,60 +1,41 @@
 /*
  * This file tests imap filter actions post-plugin, which uses nsMsgFilterAfterTheFact
  *
  * Original author: Kent James <kent@caspia.com>
  * adapted from test_imapFilterActions.js
  */
 
-var {
-  getFolderProperties,
-  getSpecialFolderString,
-  allAccountsSorted,
-  getMostRecentFolders,
-  folderNameCompare,
-} = ChromeUtils.import("resource:///modules/folderUtils.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
-var nsMsgSearchScope = Ci.nsMsgSearchScope;
-var nsMsgSearchAttrib = Ci.nsMsgSearchAttrib;
-var nsMsgSearchOp = Ci.nsMsgSearchOp;
-var Is = nsMsgSearchOp.Is;
-var Contains = nsMsgSearchOp.Contains;
-var Subject = nsMsgSearchAttrib.Subject;
-var Body = nsMsgSearchAttrib.Body;
+var Is = Ci.nsMsgSearchOp.Is;
+var Subject = Ci.nsMsgSearchAttrib.Subject;
 
 // Globals
 var gSubfolder; // a local message folder used as a target for moves and copies
-var gLastKey; // the last message key
 var gFilter; // a message filter with a subject search
 var gAction; // current message action (reused)
 var gInboxListener; // database listener object
 var gHeader; // the current message db header
-var gChecks; // the function that will be used to check the results of the filter
 var gInboxCount; // the previous number of messages in the Inbox
 var gSubfolderCount; // the previous number of messages in the subfolder
-var gMoveCallbackCount; // the number of callbacks from the move listener
 var gMessage = "draft1"; // message file used as the test message
 
 // subject of the test message
 var gMessageSubject = "Hello, did you receive my bugmail?";
 
-// a string in the body of the test message
-var gMessageInBody = "an HTML message";
-
 // various object references
 var gDbService = Cc["@mozilla.org/msgDatabase/msgDBService;1"]
                              .getService(Ci.nsIMsgDBService);
 
 // Definition of tests. The test function name is the filter action
 // being tested, with "Body" appended to tests that use delayed
 // application of filters due to a body search
-var gTestArray =
-[
+var gTestArray = [
   setupIMAPPump,
   setupFilters,
   async function DoNothing() {
     gAction.type = Ci.nsMsgFilterAction.StopExecution;
     gInboxCount = folderCount(IMAPPump.inbox);
     await setupTest(gFilter, gAction);
     testCounts(false, 1, 0, 0);
     Assert.equal(gInboxCount + 1, folderCount(IMAPPump.inbox));
@@ -166,34 +147,33 @@ var gTestArray =
     gSubfolderCount = folderCount(gSubfolder);
     await setupTest(gFilter, gAction);
     testCounts(true, 1, 1, 1);
     Assert.equal(gInboxCount + 1, folderCount(IMAPPump.inbox));
     Assert.equal(gSubfolderCount + 1, folderCount(gSubfolder));
   },
   async function Custom() {
     gAction.type = Ci.nsMsgFilterAction.Custom;
-    gAction.customId = 'mailnews@mozilla.org#testOffline';
-    gAction.strValue = 'true';
+    gAction.customId = "mailnews@mozilla.org#testOffline";
+    gAction.strValue = "true";
     actionTestOffline.needsBody = true;
     await setupTest(gFilter, gAction);
     testCounts(true, 1, 1, 1);
   },
   /**/
   endTest,
 ];
 
 function run_test() {
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
   gTestArray.forEach(x => add_task(x));
   run_next_test();
 }
 
-function setupFilters()
-{
+function setupFilters() {
 // Create a non-body filter.
   let filterList = IMAPPump.incomingServer.getFilterList(null);
   gFilter = filterList.createFilter("subject");
   let searchTerm = gFilter.createTerm();
   searchTerm.attrib = Subject;
   searchTerm.op = Is;
   var value = searchTerm.value;
   value.attrib = Subject;
@@ -206,270 +186,229 @@ function setupFilters()
 
   // an action that can be modified by tests
   gAction = gFilter.createAction();
 
   MailServices.filters.addCustomAction(actionTestOffline);
   MailServices.mailSession.AddFolderListener(FolderListener, Ci.nsIFolderListener.event);
   gSubfolder = localAccountUtils.rootFolder.createLocalSubfolder("Subfolder");
   gPreviousUnread = 0;
-  gPreviousDbNew = 0;
 }
 
 /*
  * functions used to support test setup and execution
  */
 
 // basic preparation done for each test
-async function setupTest(aFilter, aAction)
-{
+async function setupTest(aFilter, aAction) {
   let filterList = IMAPPump.incomingServer.getFilterList(null);
   while (filterList.filterCount)
     filterList.removeFilterAt(0);
-  if (aFilter)
-  {
+  if (aFilter) {
     aFilter.clearActionList();
     if (aAction) {
       aFilter.appendAction(aAction);
       filterList.insertFilterAt(0, aFilter);
     }
   }
   if (gInboxListener)
     gDbService.unregisterPendingListener(gInboxListener);
 
   gInboxListener = new DBListener();
   gDbService.registerPendingListener(IMAPPump.inbox, gInboxListener);
-  gMoveCallbackCount = 0;
   IMAPPump.mailbox.addMessage(new imapMessage(specForFileName(gMessage),
                           IMAPPump.mailbox.uidnext++, []));
   let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener();
   IMAPPump.inbox.updateFolderWithListener(null, promiseUrlListener);
   await promiseUrlListener.promise;
   await PromiseTestUtils.promiseDelay(200);
 }
 
 // Cleanup, null out everything, close all cached connections and stop the
 // server
-function endTest()
-{
+function endTest() {
   if (gInboxListener)
     gDbService.unregisterPendingListener(gInboxListener);
   gInboxListener = null;
   MailServices.mailSession.RemoveFolderListener(FolderListener);
   teardownIMAPPump();
 }
 
 /*
  * listener objects
  */
 
 // nsIFolderListener implementation
 var FolderListener = {
-  OnItemEvent: function OnItemEvent(aEventFolder, aEvent) {
+  OnItemEvent(aEventFolder, aEvent) {
     dump("received folder event " + aEvent +
          " folder " + aEventFolder.name +
          "\n");
-  }
+  },
 };
 
 // nsIDBChangeListener implementation. Counts of calls are kept, but not
 // currently used in the tests. Current role is to provide a reference
 // to the new message header (plus give some examples of using db listeners
 // in javascript).
-function DBListener()
-{
+function DBListener() {
   this.counts = {};
   let counts = this.counts;
   counts.onHdrFlagsChanged = 0;
   counts.onHdrDeleted = 0;
   counts.onHdrAdded = 0;
   counts.onParentChanged = 0;
   counts.onAnnouncerGoingAway = 0;
   counts.onReadChanged = 0;
   counts.onJunkScoreChanged = 0;
   counts.onHdrPropertyChanged = 0;
   counts.onEvent = 0;
 }
 
-DBListener.prototype =
-{
-  onHdrFlagsChanged:
-    function onHdrFlagsChanged(aHdrChanged, aOldFlags, aNewFlags, aInstigator)
-    {
-      this.counts.onHdrFlagsChanged++;
-    },
+DBListener.prototype = {
+  onHdrFlagsChanged(aHdrChanged, aOldFlags, aNewFlags, aInstigator) {
+    this.counts.onHdrFlagsChanged++;
+  },
+
+  onHdrDeleted(aHdrChanged, aParentKey, Flags, aInstigator) {
+    this.counts.onHdrDeleted++;
+  },
 
-  onHdrDeleted:
-    function onHdrDeleted(aHdrChanged, aParentKey, Flags, aInstigator)
-    {
-      this.counts.onHdrDeleted++;
-    },
+  onHdrAdded(aHdrChanged, aParentKey, aFlags, aInstigator) {
+    this.counts.onHdrAdded++;
+    gHeader = aHdrChanged;
+  },
 
-  onHdrAdded:
-    function onHdrAdded(aHdrChanged, aParentKey, aFlags, aInstigator)
-    {
-      this.counts.onHdrAdded++;
-      gHeader = aHdrChanged;
-    },
-
-  onParentChanged:
-    function onParentChanged(aKeyChanged, oldParent, newParent, aInstigator)
-    {
-      this.counts.onParentChanged++;
-    },
+  onParentChanged(aKeyChanged, oldParent, newParent, aInstigator) {
+    this.counts.onParentChanged++;
+  },
 
-  onAnnouncerGoingAway:
-    function onAnnouncerGoingAway(instigator)
-    {
-      if (gInboxListener)
-        try {
-          IMAPPump.inbox.msgDatabase.RemoveListener(gInboxListener);
-        }
-        catch (e) {dump(" listener not found\n");}
-      this.counts.onAnnouncerGoingAway++;
-    },
-
-  onReadChanged:
-    function onReadChanged(aInstigator)
-    {
-      this.counts.onReadChanged++;
-    },
+  onAnnouncerGoingAway(instigator) {
+    if (gInboxListener) {
+      try {
+        IMAPPump.inbox.msgDatabase.RemoveListener(gInboxListener);
+      } catch (e) {
+        dump(" listener not found\n");
+      }
+    }
+    this.counts.onAnnouncerGoingAway++;
+  },
 
-  onJunkScoreChanged:
-    function onJunkScoreChanged(aInstigator)
-    {
-      this.counts.onJunkScoreChanged++;
-    },
+  onReadChanged(aInstigator) {
+    this.counts.onReadChanged++;
+  },
+
+  onJunkScoreChanged(aInstigator) {
+    this.counts.onJunkScoreChanged++;
+  },
 
-  onHdrPropertyChanged:
-    function onHdrPropertyChanged(aHdrToChange, aPreChange, aStatus, aInstigator)
-    {
-      this.counts.onHdrPropertyChanged++;
-    },
+  onHdrPropertyChanged(aHdrToChange, aPreChange, aStatus, aInstigator) {
+    this.counts.onHdrPropertyChanged++;
+  },
 
-  onEvent:
-    function onEvent(aDB, aEvent)
-    {
-      this.counts.onEvent++;
-    },
-
+  onEvent(aDB, aEvent) {
+    this.counts.onEvent++;
+  },
 };
 
 /*
  * helper functions
  */
 
 // return the number of messages in a folder (and check that the
 // folder counts match the database counts)
-function folderCount(folder)
-{
+function folderCount(folder) {
   // count using the database
   let enumerator = folder.msgDatabase.EnumerateMessages();
   let dbCount = 0;
-  while (enumerator.hasMoreElements())
-  {
+  while (enumerator.hasMoreElements()) {
     dbCount++;
-    let hdr = enumerator.getNext();
+    enumerator.getNext();
   }
 
   // count using the folder
-  let folderCount = folder.getTotalMessages(false);
+  let count = folder.getTotalMessages(false);
 
   // compare the two
-  Assert.equal(dbCount, folderCount);
+  Assert.equal(dbCount, count);
   return dbCount;
 }
 
 // given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
+function specForFileName(aFileName) {
   let file = do_get_file("../../../data/" + aFileName);
   let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
   return msgfileuri.spec;
 }
 
 // shorthand for the inbox message summary database
-function db()
-{
+function db() {
   return IMAPPump.inbox.msgDatabase;
 }
 
 // static variables used in testCounts
 var gPreviousUnread;
-var gPreviousDbNew;
 
 // Test various counts.
 //
 //  aHasNew:         folder hasNew flag
 //  aUnreadDelta:    change in unread count for the folder
 //  aFolderNewDelta: change in new count for the folder
 //  aDbNewDelta:     change in new count for the database
 //
-function testCounts(aHasNew, aUnreadDelta, aFolderNewDelta, aDbNewDelta)
-{
+function testCounts(aHasNew, aUnreadDelta, aFolderNewDelta, aDbNewDelta) {
   try {
   let folderNew = IMAPPump.inbox.getNumNewMessages(false);
   let hasNew = IMAPPump.inbox.hasNewMessages;
   let unread = IMAPPump.inbox.getNumUnread(false);
   let countOut = {};
   let arrayOut = {};
   db().getNewList(countOut, arrayOut);
   let dbNew = countOut.value ? countOut.value : 0;
   dump(" hasNew: " + hasNew +
        " unread: " + unread +
        " folderNew: " + folderNew +
        " dbNew: " + dbNew +
        " prevUnread " + gPreviousUnread +
        "\n");
-  //Assert.equal(aHasNew, hasNew);
+  // Assert.equal(aHasNew, hasNew);
   Assert.equal(aUnreadDelta, unread - gPreviousUnread);
   gPreviousUnread = unread;
   // This seems to be reset for each folder update.
   //
   // This check seems to be failing in SeaMonkey builds, yet I can see no ill
   // effects of this in the actual program. Fixing this is complex because of
   // the messiness of new count management (see bug 507638 for a
   // refactoring proposal, and attachment 398899 on bug 514801 for one possible
   // fix to this particular test). So I am disabling this.
-  //Assert.equal(aFolderNewDelta, folderNew);
-  //Assert.equal(aDbNewDelta, dbNew - gPreviousDbNew);
-  //gPreviousDbNew = dbNew;
-  } catch (e) {dump(e);}
-}
-
-// print the counts for debugging purposes in this test
-function printListener(listener)
-{
-  print("DBListener counts: ");
-  for (var item in listener.counts) {
-      dump(item + ": " + listener.counts[item] + " ");
+  // Assert.equal(aFolderNewDelta, folderNew);
+  // Assert.equal(aDbNewDelta, dbNew - gPreviousDbNew);
+  // gPreviousDbNew = dbNew;
+  } catch (e) {
+    dump(e);
   }
-  dump("\n");
 }
 
 // custom action to test offline status
-var actionTestOffline =
-{
+var actionTestOffline = {
   id: "mailnews@mozilla.org#testOffline",
   name: "test if offline",
-  apply: function(aMsgHdrs, aActionValue, aListener, aType, aMsgWindow)
-  {
-    for (var i = 0; i < aMsgHdrs.length; i++)
-    {
+  apply(aMsgHdrs, aActionValue, aListener, aType, aMsgWindow) {
+    for (let i = 0; i < aMsgHdrs.length; i++) {
       var msgHdr = aMsgHdrs.queryElementAt(i, Ci.nsIMsgDBHdr);
-      let isOffline = (msgHdr.flags & Ci.nsMsgMessageFlags.Offline) ? true : false;
+      let isOffline = !!((msgHdr.flags & Ci.nsMsgMessageFlags.Offline));
       dump("in actionTestOffline, flags are " + msgHdr.flags +
             " subject is " + msgHdr.subject +
             " isOffline is " + isOffline +
             "\n");
       // XXX TODO: the offline flag is not set here when it should be in postplugin filters
-      //Assert.equal(isOffline, aActionValue == 'true');
+      // Assert.equal(isOffline, aActionValue == 'true');
       Assert.equal(msgHdr.subject, gMessageSubject);
     }
   },
-  isValidForType: function(type, scope) {return true;},
+  isValidForType(type, scope) { return true; },
 
-  validateActionValue: function(value, folder, type) { return null;},
+  validateActionValue(value, folder, type) { return null; },
 
   allowDuplicates: false,
 
-  needsBody: true // set during test setup
+  needsBody: true, // set during test setup
 };
--- a/mailnews/imap/test/unit/test_imapFlagChange.js
+++ b/mailnews/imap/test/unit/test_imapFlagChange.js
@@ -1,14 +1,17 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Test to ensure that imap flag changes made from a different profile/machine
  * are stored in db.
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 var gMessage;
 var gSecondFolder;
 var gSynthMessage;
 
@@ -92,25 +95,25 @@ var tests = [
     IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
     yield false;
   },
   function checkTagCleared() {
     let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gSynthMessage.messageId);
     let keywords = msgHdr.getStringProperty("keywords");
     Assert.ok(!keywords.includes("randomtag"));
   },
-  teardown
+  teardown,
 ];
 
 function* setup() {
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
 
   setupIMAPPump();
 
-  IMAPPump.daemon.createMailbox("secondFolder", {subscribed : true});
+  IMAPPump.daemon.createMailbox("secondFolder", {subscribed: true});
 
   // build up a diverse list of messages
   let messages = [];
   let gMessageGenerator = new MessageGenerator();
   messages = messages.concat(gMessageGenerator.makeMessage());
   gSynthMessage = messages[0];
 
   let msgURI =
--- a/mailnews/imap/test/unit/test_imapFolderCopy.js
+++ b/mailnews/imap/test/unit/test_imapFolderCopy.js
@@ -1,49 +1,45 @@
 // This file tests the folder copying with IMAP. In particular, we're
 // going to test copying local folders to imap servers, but other tests
 // could be added.
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 var gEmptyLocal1, gEmptyLocal2, gEmptyLocal3, gNotEmptyLocal4;
 
-var {
-  getFolderProperties,
-  getSpecialFolderString,
-  allAccountsSorted,
-  getMostRecentFolders,
-  folderNameCompare,
-} = ChromeUtils.import("resource:///modules/folderUtils.jsm");
 var {toXPCOMArray} = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 var tests = [
   setup,
   function* copyFolder1() {
     dump("gEmpty1 " + gEmptyLocal1.URI + "\n");
-    let folders = new Array;
+    let folders = [];
     folders.push(gEmptyLocal1.QueryInterface(Ci.nsIMsgFolder));
     let array = toXPCOMArray(folders, Ci.nsIMutableArray);
     MailServices.copy.CopyFolders(array, IMAPPump.inbox, false, CopyListener, null);
     yield false;
   },
   function* copyFolder2() {
     dump("gEmpty2 " + gEmptyLocal2.URI + "\n");
-    let folders = new Array;
+    let folders = [];
     folders.push(gEmptyLocal2);
     let array = toXPCOMArray(folders, Ci.nsIMutableArray);
     MailServices.copy.CopyFolders(array, IMAPPump.inbox, false, CopyListener, null);
     yield false;
   },
   function* copyFolder3() {
     dump("gEmpty3 " + gEmptyLocal3.URI + "\n");
-    let folders = new Array;
+    let folders = [];
     folders.push(gEmptyLocal3);
     let array = toXPCOMArray(folders, Ci.nsIMutableArray);
     MailServices.copy.CopyFolders(array, IMAPPump.inbox, false, CopyListener, null);
     yield false;
   },
   function verifyFolders() {
     let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
     dump("found folder1\n");
@@ -51,26 +47,26 @@ var tests = [
     dump("found folder2\n");
     let folder3 = IMAPPump.inbox.getChildNamed("empty 3");
     dump("found folder3\n");
     Assert.ok(folder1 !== null);
     Assert.ok(folder2 !== null);
     Assert.ok(folder3 !== null);
   },
   function* moveImapFolder1() {
-    let folders = new Array;
+    let folders = [];
     let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
     let folder2 = IMAPPump.inbox.getChildNamed("empty 2");
     folders.push(folder2.QueryInterface(Ci.nsIMsgFolder));
     let array = toXPCOMArray(folders, Ci.nsIMutableArray);
     MailServices.copy.CopyFolders(array, folder1, true, CopyListener, null);
     yield false;
   },
   function* moveImapFolder2() {
-    let folders = new Array;
+    let folders = [];
     let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
     let folder3 = IMAPPump.inbox.getChildNamed("empty 3");
     folders.push(folder3.QueryInterface(Ci.nsIMsgFolder));
     let array = toXPCOMArray(folders, Ci.nsIMutableArray);
     MailServices.copy.CopyFolders(array, folder1, true, CopyListener, null);
     yield false;
   },
   function verifyImapFolders() {
@@ -80,31 +76,31 @@ var tests = [
     dump("found folder2\n");
     let folder3 = folder1.getChildNamed("empty 3");
     dump("found folder3\n");
     Assert.ok(folder1 !== null);
     Assert.ok(folder2 !== null);
     Assert.ok(folder3 !== null);
   },
   function* testImapFolderCopyFailure() {
-    let folders = new Array;
+    let folders = [];
     folders.push(gNotEmptyLocal4.QueryInterface(Ci.nsIMsgFolder));
     let array = toXPCOMArray(folders, Ci.nsIMutableArray);
     IMAPPump.daemon.commandToFail = "APPEND";
     // we expect NS_MSG_ERROR_IMAP_COMMAND_FAILED;
     CopyListener._expectedStatus = 0x80550021;
     MailServices.copy.CopyFolders(array, IMAPPump.inbox, false, CopyListener, null);
 
     // In failure case OnStopCopy is sent twice, the first one comes from
     // nsMsgCopyService, the second one comes from nsImapFolderCopyState.
     yield false;
 
     yield false;
   },
-  teardown
+  teardown,
 ];
 
 function setup() {
   setupIMAPPump();
 
   gEmptyLocal1 = localAccountUtils.rootFolder.createLocalSubfolder("empty 1");
   gEmptyLocal2 = localAccountUtils.rootFolder.createLocalSubfolder("empty 2");
   gEmptyLocal3 = localAccountUtils.rootFolder.createLocalSubfolder("empty 3");
@@ -114,33 +110,33 @@ function setup() {
   let message = messageGenerator.makeMessage();
   gNotEmptyLocal4.QueryInterface(Ci.nsIMsgLocalMailFolder);
   gNotEmptyLocal4.addMessage(message.toMboxString());
 
   // these hacks are required because we've created the inbox before
   // running initial folder discovery, and adding the folder bails
   // out before we set it as verified online, so we bail out, and
   // then remove the INBOX folder since it's not verified.
-  IMAPPump.inbox.hierarchyDelimiter = '/';
+  IMAPPump.inbox.hierarchyDelimiter = "/";
   IMAPPump.inbox.verifiedAsOnlineFolder = true;
 }
 
 // nsIMsgCopyServiceListener implementation - runs next test when copy
 // is completed.
 var CopyListener = {
-  _expectedStatus : 0,
-  OnStartCopy: function() {},
-  OnProgress: function(aProgress, aProgressMax) {},
-  SetMessageKey: function(aKey) {},
-  SetMessageId: function(aMessageId) {},
-  OnStopCopy: function(aStatus) {
+  _expectedStatus: 0,
+  OnStartCopy() {},
+  OnProgress(aProgress, aProgressMax) {},
+  SetMessageKey(aKey) {},
+  SetMessageId(aMessageId) {},
+  OnStopCopy(aStatus) {
     // Check: message successfully copied.
     Assert.equal(aStatus, this._expectedStatus);
     async_driver();
-  }
+  },
 };
 
 function teardown() {
   teardownIMAPPump();
 }
 
 function run_test() {
   async_run_tests(tests);
--- a/mailnews/imap/test/unit/test_imapHdrChunking.js
+++ b/mailnews/imap/test/unit/test_imapHdrChunking.js
@@ -1,70 +1,70 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Tests imap msg header download chunking
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 // javascript mime emitter functions
 
 // IMAP pump
 
 setupIMAPPump();
 
 // Dummy message window so we can say the inbox is open in a window.
-var dummyMsgWindow =
-{
-  openFolder : IMAPPump.inbox,
+var dummyMsgWindow = {
+  openFolder: IMAPPump.inbox,
   QueryInterface: ChromeUtils.generateQI([Ci.nsIMsgWindow,
-                                          Ci.nsISupportsWeakReference])
+                                          Ci.nsISupportsWeakReference]),
 };
 
 var gFolderListener = {
   _gotNewMailBiff: false,
-  OnItemIntPropertyChanged : function(aItem, aProperty, aOldValue, aNewValue) {
+  OnItemIntPropertyChanged(aItem, aProperty, aOldValue, aNewValue) {
     if (aProperty == "BiffState" &&
         aNewValue == Ci.nsIMsgFolder.nsMsgBiffState_NewMail) {
       this._gotNewMailBiff = true;
       async_driver();
     }
-  }
+  },
 };
 
 var tests = [
   uploadImapMessages,
   testMessageFetched,
   testHdrsDownloaded,
-  endTest
-]
+  endTest,
+];
 
 // upload messages to the imap fake server Inbox
-function* uploadImapMessages()
-{
+function* uploadImapMessages() {
   // make 10 messages
   let messageGenerator = new MessageGenerator();
   let scenarioFactory = new MessageScenarioFactory(messageGenerator);
 
   // build up a list of messages
   let messages = [];
   messages = messages.concat(scenarioFactory.directReply(10));
 
   // Add 10 messages with uids 1-10.
-  let imapInbox = IMAPPump.daemon.getMailbox("INBOX")
+  let imapInbox = IMAPPump.daemon.getMailbox("INBOX");
   // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     let dataUri = Services.io.newURI("data:text/plain;base64," +
                                      btoa(message.toMessageString()));
     imapInbox.addMessage(new imapMessage(dataUri.spec, imapInbox.uidnext++, []));
   });
   // updateFolderWithListener with null for nsIMsgWindow makes biff notify.
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
@@ -85,18 +85,17 @@ function* testHdrsDownloaded() {
   yield true;
 }
 
 // Cleanup
 function endTest() {
   teardownIMAPPump();
 }
 
-function run_test()
-{
+function run_test() {
   // We need to register the dummyMsgWindow so that we'll think the
   // Inbox is open in a folder and fetch headers in chunks.
   MailServices.mailSession.AddMsgWindow(dummyMsgWindow);
   MailServices.mailSession.AddFolderListener(gFolderListener,
                                              Ci.nsIFolderListener.intPropertyChanged);
 
   // Set chunk size to 3, so we'll have to chain 4 requests to get
   // 10 headers.
--- a/mailnews/imap/test/unit/test_imapHdrStreaming.js
+++ b/mailnews/imap/test/unit/test_imapHdrStreaming.js
@@ -1,106 +1,102 @@
 /**
  * This test checks if the imap message service code streams headers correctly.
  * It checks that streaming headers for messages stored for offline use works.
  * It doesn't test streaming messages that haven't been stored for offline use
  * because that's not implemented yet, and it's unclear if anyone will want it.
  */
 
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
+/* import-globals-from ../../../test/resources/messageGenerator.js */
+/* import-globals-from ../../../test/resources/messageModifier.js */
+/* import-globals-from ../../../test/resources/messageInjection.js */
 load("../../../resources/messageGenerator.js");
 load("../../../resources/messageModifier.js");
 load("../../../resources/messageInjection.js");
 
 // IMAP pump
 
 setupIMAPPump();
 
 
 var gMsgFile1 = do_get_file("../../../data/bugmail10");
 var gMsgId1 = "200806061706.m56H6RWT004933@mrapp54.mozilla.org";
 
 // We use this as a display consumer
-var streamListener =
-{
+var streamListener = {
   _data: "",
-  _stream : null,
+  _stream: null,
 
   QueryInterface:
     ChromeUtils.generateQI([Ci.nsIStreamListener, Ci.nsIRequestObserver]),
 
   // nsIRequestObserver
-  onStartRequest: function(aRequest) {
+  onStartRequest(aRequest) {
   },
-  onStopRequest: function(aRequest, aStatusCode) {
+  onStopRequest(aRequest, aStatusCode) {
     Assert.equal(aStatusCode, 0);
     Assert.ok(this._data.includes("Content-Type"));
     async_driver();
   },
 
   // nsIStreamListener
-  onDataAvailable: function(aRequest, aInputStream, aOffset, aCount) {
+  onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
     if (this._stream == null) {
       this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
       this._stream.init(aInputStream);
     }
     this._data += this._stream.read(aCount);
-  }
+  },
 };
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox)
-{
+function addMessagesToServer(messages, mailbox) {
   // For every message we have, we need to convert it to a file:/// URI
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     let URI = Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
     // Create the imapMessage and store it on the mailbox.
     mailbox.addMessage(new imapMessage(URI.spec, mailbox.uidnext++, []));
   });
 }
 
-var incomingServer, server;
 function run_test() {
-
   // Add a couple of messages to the INBOX
   // this is synchronous, afaik
   addMessagesToServer([{file: gMsgFile1, messageId: gMsgId1}],
                         IMAPPump.daemon.getMailbox("INBOX"));
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
   async_run_tests(tests);
  }
 
 var tests = [
   test_updateFolder,
   test_downloadForOffline,
   test_streamHeaders,
-  endTest
-]
+  endTest,
+];
 
 function* test_updateFolder() {
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
 function* test_downloadForOffline() {
   IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
   yield false;
 }
 
-function* test_streamHeaders()
-{
+function* test_streamHeaders() {
   let newMsgHdr = IMAPPump.inbox.GetMessageHeader(1);
   let msgURI = newMsgHdr.folder.getUriForMsg(newMsgHdr);
   let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
   let msgServ = messenger.messageServiceFromURI(msgURI);
-  msgServ.streamHeaders(msgURI, streamListener, asyncUrlListener,true);
+  msgServ.streamHeaders(msgURI, streamListener, asyncUrlListener, true);
   yield false;
 }
 
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
--- a/mailnews/imap/test/unit/test_imapHighWater.js
+++ b/mailnews/imap/test/unit/test_imapHighWater.js
@@ -1,49 +1,49 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Test to ensure that offline imap moves handle extremely high highwater
  * marks.
  */
 
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/alertTestUtils.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 var gIMAPDaemon, gServer, gIMAPIncomingServer;
 
 var gIMAPInbox;
 var gFolder1, gRootFolder;
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox)
-{
+function addMessagesToServer(messages, mailbox) {
   // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     let dataUri = Services.io.newURI("data:text/plain;base64," +
                                       btoa(message.toMessageString()));
     mailbox.addMessage(new imapMessage(dataUri.spec, mailbox.uidnext++, []));
   });
 }
 
-function run_test()
-{
+function run_test() {
   localAccountUtils.loadLocalMailAccount();
 
   /*
    * Set up an IMAP server.
    */
   gIMAPDaemon = new imapDaemon();
   gServer = makeServer(gIMAPDaemon, "");
-  gIMAPDaemon.createMailbox("folder 1", {subscribed : true});
+  gIMAPDaemon.createMailbox("folder 1", {subscribed: true});
   gIMAPIncomingServer = createLocalIMAPServer(gServer.port);
   gIMAPIncomingServer.maximumConnectionsNumber = 1;
 
   // We need an identity so that updateFolder doesn't fail
   let localAccount = MailServices.accounts.createAccount();
   let identity = MailServices.accounts.createIdentity();
   localAccount.addIdentity(identity);
   localAccount.defaultIdentity = identity;
@@ -72,17 +72,17 @@ function* setupFolders() {
   let messageGenerator = new MessageGenerator();
   let scenarioFactory = new MessageScenarioFactory(messageGenerator);
 
   // build up a list of messages
   let messages = [];
   messages = messages.concat(scenarioFactory.directReply(10));
 
   // Add 10 messages with uids 1-10.
-  let imapInbox = gIMAPDaemon.getMailbox("INBOX")
+  let imapInbox = gIMAPDaemon.getMailbox("INBOX");
   addMessagesToServer(messages, imapInbox);
   messages = [];
   messages = messages.concat(messageGenerator.makeMessage());
   // Add a single message to move target folder.
   addMessagesToServer(messages, gIMAPDaemon.getMailbox("folder 1"));
 
   // Get the IMAP inbox...
   gRootFolder = gIMAPIncomingServer.rootFolder;
@@ -98,18 +98,17 @@ function* doMoves() {
   gFolder1 = gRootFolder.getChildNamed("folder 1")
                .QueryInterface(Ci.nsIMsgImapMailFolder);
   gFolder1.updateFolderWithListener(null, UrlListener);
   yield false;
   // get five messages to move from Inbox to folder 1.
   let headers1 = Cc["@mozilla.org/array;1"]
                    .createInstance(Ci.nsIMutableArray);
   let msgEnumerator = gIMAPInbox.msgDatabase.EnumerateMessages();
-  for (let i = 0; i < 5 && msgEnumerator.hasMoreElements(); i++)
-  {
+  for (let i = 0; i < 5 && msgEnumerator.hasMoreElements(); i++) {
     let header = msgEnumerator.getNext();
     if (header instanceof Ci.nsIMsgDBHdr)
       headers1.appendElement(header);
   }
   // this will add dummy headers with keys > 0xffffff80
   MailServices.copy.CopyMessages(gIMAPInbox, headers1, gFolder1, true,
                                  CopyListener, gDummyMsgWindow, true);
   yield false;
@@ -118,18 +117,17 @@ function* doMoves() {
   gFolder1.updateFolderWithListener(gDummyMsgWindow, UrlListener);
   yield false;
   // Check that playing back offline events gets rid of dummy
   // headers, and thus highWater is recalculated.
   Assert.equal(gFolder1.msgDatabase.dBFolderInfo.highWater, 6);
   headers1 = Cc["@mozilla.org/array;1"]
                 .createInstance(Ci.nsIMutableArray);
   msgEnumerator = gIMAPInbox.msgDatabase.EnumerateMessages();
-  for (let i = 0; i < 5 && msgEnumerator.hasMoreElements(); i++)
-  {
+  for (let i = 0; i < 5 && msgEnumerator.hasMoreElements(); i++) {
     let header = msgEnumerator.getNext();
     if (header instanceof Ci.nsIMsgDBHdr)
       headers1.appendElement(header);
   }
   // Check that CopyMessages will handle having a high highwater mark.
   // It will thrown an exception if it can't.
   let msgHdr = gFolder1.msgDatabase.CreateNewHdr(0xfffffffd);
   gFolder1.msgDatabase.AddNewHdrToDB(msgHdr, false);
@@ -139,58 +137,53 @@ function* doMoves() {
   gServer.performTest("UID COPY");
 
   gFolder1.msgDatabase.DeleteHeader(msgHdr, null, true, false);
   gIMAPInbox.updateFolderWithListener(null, UrlListener);
   yield false;
   // this should clear the dummy headers.
   gFolder1.updateFolderWithListener(gDummyMsgWindow, UrlListener);
   yield false;
-  let serverSink = gIMAPIncomingServer.QueryInterface(Ci.nsIImapServerSink);
   Assert.equal(gFolder1.msgDatabase.dBFolderInfo.highWater, 11);
   yield true;
 }
 
-var UrlListener =
-{
-  OnStartRunningUrl: function(url) { },
-  OnStopRunningUrl: function(url, rc)
-  {
+var UrlListener = {
+  OnStartRunningUrl(url) {},
+  OnStopRunningUrl(url, rc) {
     // Check for ok status.
     Assert.equal(rc, 0);
     async_driver();
-  }
+  },
 };
 
 // nsIMsgCopyServiceListener implementation
-var CopyListener =
-{
-  OnStartCopy: function() {},
-  OnProgress: function(aProgress, aProgressMax) {},
-  SetMessageKey: function(aKey){},
-  SetMessageId: function(aMessageId) {},
-  OnStopCopy: function(aStatus){
+var CopyListener = {
+  OnStartCopy() {},
+  OnProgress(aProgress, aProgressMax) {},
+  SetMessageKey(aKey) {},
+  SetMessageId(aMessageId) {},
+  OnStopCopy(aStatus) {
     Assert.equal(aStatus, 0);
     async_driver();
-  }
+  },
 };
 
 // Definition of tests
 var tests = [
   setupFolders,
   doMoves,
-  endTest
-]
+  endTest,
+];
 
 function actually_run_test() {
   async_run_tests(tests);
 }
 
-function* endTest()
-{
+function* endTest() {
   Services.io.offline = true;
   gServer.performTest("LOGOUT");
 //  gIMAPIncomingServer.closeCachedConnections();
   gServer.stop();
   let thread = gThreadManager.currentThread;
   while (thread.hasPendingEvents())
     thread.processNextEvent(true);
   yield true;
--- a/mailnews/imap/test/unit/test_imapID.js
+++ b/mailnews/imap/test/unit/test_imapID.js
@@ -1,39 +1,34 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Test to ensure that we handle the RFC2197 ID command.
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
 load("../../../resources/logHelper.js");
 
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 var {PromiseTestUtils} = ChromeUtils.import("resource://testing-common/mailnews/PromiseTestUtils.jsm");
 
 var kIDResponse = "(\"name\" \"GImap\" \"vendor\" \"Google, Inc.\" \"support-url\" \"http://mail.google.com/support\")";
 
 add_task(async function setup() {
   setupIMAPPump("GMail");
   IMAPPump.daemon.idResponse = kIDResponse;
 
   // update folder to kick start tests.
   let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener();
   IMAPPump.inbox.updateFolderWithListener(null, promiseUrlListener);
   await promiseUrlListener.promise;
 });
 
 add_task(async function updateInbox() {
-  let rootFolder = IMAPPump.incomingServer.rootFolder;
   let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener();
   IMAPPump.inbox.updateFolderWithListener(null, promiseUrlListener);
   await promiseUrlListener.promise;
 });
 
 add_task(function checkIDHandling() {
   Assert.equal(IMAPPump.daemon.clientID, "(\"name\" \"xpcshell\" \"version\" \"1\")");
   Assert.equal(IMAPPump.incomingServer.serverIDPref, kIDResponse);
 });
 
 add_task(teardownIMAPPump);
-
-function run_test() {
-  run_next_test();
-}
--- a/mailnews/imap/test/unit/test_imapMove.js
+++ b/mailnews/imap/test/unit/test_imapMove.js
@@ -2,36 +2,37 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This tests that we use IMAP move if the IMAP server supports it.
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/messageGenerator.js");
 
 var gFolder1;
 
 var tests = [
   setupCUSTOM1,
   startTest,
   doMove,
   testMove,
-  teardownIMAPPump
+  teardownIMAPPump,
 ];
 
 function setupCUSTOM1() {
   setupIMAPPump("CUSTOM1");
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
 }
 
-async function startTest()
-{
+async function startTest() {
   IMAPPump.incomingServer.rootFolder.createSubfolder("folder 1", null);
   await PromiseTestUtils.promiseFolderAdded("folder 1");
 
   addImapMessage();
   let listener = new PromiseTestUtils.PromiseUrlListener();
   IMAPPump.inbox.updateFolderWithListener(null, listener);
   await listener.promise;
 
@@ -59,24 +60,23 @@ async function doMove() {
 async function testMove() {
   Assert.equal(IMAPPump.inbox.getTotalMessages(false), 0);
   let listener = new PromiseTestUtils.PromiseUrlListener();
   gFolder1.updateFolderWithListener(null, listener);
   await listener.promise;
   Assert.equal(gFolder1.getTotalMessages(false), 1);
 
   // maildir should also delete the files.
-  if (IMAPPump.inbox.msgStore.storeType == "maildir")
-  {
+  if (IMAPPump.inbox.msgStore.storeType == "maildir") {
     let curDir = IMAPPump.inbox.filePath.clone();
     curDir.append("cur");
     Assert.ok(curDir.exists());
     Assert.ok(curDir.isDirectory());
     let curEnum = curDir.directoryEntries;
     // the directory should be empty, fails from bug 771643
-    Assert.ok(!curEnum.hasMoreElements())
+    Assert.ok(!curEnum.hasMoreElements());
   }
 }
 
 function run_test() {
   tests.forEach(x => add_task(x));
   run_next_test();
 }
--- a/mailnews/imap/test/unit/test_imapPasswordFailure.js
+++ b/mailnews/imap/test/unit/test_imapPasswordFailure.js
@@ -5,28 +5,30 @@
  *   - Check we get a prompt asking what to do.
  *   - Check retry does what it should do.
  *   - Check cancel does what it should do.
  *   - Re-initiate connection, this time select enter new password, check that
  *     we get a new password prompt and can enter the password.
  */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
+/* import-globals-from ../../../test/resources/passwordStorage.js */
 load("../../../resources/alertTestUtils.js");
 load("../../../resources/passwordStorage.js");
 
 var kUserName = "user";
 var kInvalidPassword = "imaptest";
 var kValidPassword = "password";
 
 var incomingServer, server;
 var attempt = 0;
 
+/* exported confirmEx, promptPasswordPS */// to alertTestUtils.js
 function confirmEx(aDialogTitle, aText, aButtonFlags, aButton0Title,
                    aButton1Title, aButton2Title, aCheckMsg, aCheckState) {
   switch (++attempt) {
     // First attempt, retry.
     case 1:
       dump("\nAttempting retry\n");
       return 0;
     // Second attempt, cancel.
@@ -52,26 +54,26 @@ function promptPasswordPS(aParent, aDial
   if (attempt == 4) {
     aPassword.value = kValidPassword;
     aCheckState.value = true;
     return true;
   }
   return false;
 }
 
-add_task(async function () {
+add_task(async function() {
   do_test_pending();
 
   // Prepare files for passwords (generated by a script in bug 1018624).
-  await setupForPassword("signons-mailnews1.8-imap.json")
+  await setupForPassword("signons-mailnews1.8-imap.json");
 
   registerAlertTestUtils();
 
   let daemon = new imapDaemon();
-  daemon.createMailbox("Subscribed", {subscribed : true});
+  daemon.createMailbox("Subscribed", {subscribed: true});
   server = makeServer(daemon, "", {
     // Make username of server match the singons.txt file
     // (pw there is intentionally invalid)
     kUsername: kUserName,
     kPassword: kValidPassword});
   server.setDebugLevel(fsDebugAll);
 
 
@@ -150,12 +152,8 @@ function endTest() {
   server.stop();
 
   var thread = gThreadManager.currentThread;
   while (thread.hasPendingEvents())
     thread.processNextEvent(true);
 
   do_test_finished();
 }
-
-function run_test() {
-  run_next_test();
-}
--- a/mailnews/imap/test/unit/test_imapProtocols.js
+++ b/mailnews/imap/test/unit/test_imapProtocols.js
@@ -6,28 +6,29 @@
 var defaultProtocolFlags =
   Ci.nsIProtocolHandler.URI_NORELATIVE |
   Ci.nsIProtocolHandler.URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT |
   Ci.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD |
   Ci.nsIProtocolHandler.ALLOWS_PROXY |
   Ci.nsIProtocolHandler.URI_FORBIDS_COOKIE_ACCESS |
   Ci.nsIProtocolHandler.ORIGIN_IS_FULL_SPEC;
 
-var protocols =
-  [ { protocol: "imap",
-      urlSpec: "imap://user@localhost/",
-      defaultPort: Ci.nsIImapUrl.DEFAULT_IMAP_PORT
-    }
-    // XXX Imaps protocol not available via nsIProtocolHandler yet.
-    /*,
-    { protocol: "imaps",
-      urlSpec: "iamps://user@localhost/",
-      defaultPort: Ci.nsIImapUrl.DEFAULT_IMAPS_PORT
-      }*/
-    ];
+var protocols = [
+  {
+    protocol: "imap",
+    urlSpec: "imap://user@localhost/",
+    defaultPort: Ci.nsIImapUrl.DEFAULT_IMAP_PORT,
+  },
+  // XXX Imaps protocol not available via nsIProtocolHandler yet.
+  // {
+  //   protocol: "imaps",
+  //   urlSpec: "iamps://user@localhost/",
+  //   defaultPort: Ci.nsIImapUrl.DEFAULT_IMAPS_PORT,
+  // },
+];
 
 function run_test() {
   // We need a server to match the urlSpecs above.
   createLocalIMAPServer();
 
   for (var part = 0; part < protocols.length; ++part) {
     print("protocol: " + protocols[part].protocol);
 
--- a/mailnews/imap/test/unit/test_imapProxy.js
+++ b/mailnews/imap/test/unit/test_imapProxy.js
@@ -1,28 +1,29 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 // Test that IMAP over a SOCKS proxy works.
 
 var {NetworkTestUtils} = ChromeUtils.import("resource://testing-common/mailnews/NetworkTestUtils.jsm");
 var {PromiseTestUtils} = ChromeUtils.import("resource://testing-common/mailnews/PromiseTestUtils.jsm");
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/messageGenerator.js");
 
 var server, daemon, incomingServer;
 
 const PORT = 143;
 
 add_task(async function setup() {
   // Disable new mail notifications
   Services.prefs.setBoolPref("mail.biff.play_sound", false);
   Services.prefs.setBoolPref("mail.biff.show_alert", false);
   Services.prefs.setBoolPref("mail.biff.show_tray_icon", false);
   Services.prefs.setBoolPref("mail.biff.animate_dock_icon", false);
 
-  let daemon = new imapDaemon();
+  daemon = new imapDaemon();
   server = makeServer(daemon, "");
 
   let messages = [];
   let messageGenerator = new MessageGenerator();
   messages = messages.concat(messageGenerator.makeMessage());
   let dataUri = Services.io.newURI("data:text/plain;base64," +
                                    btoa(messages[0].toMessageString()));
   let imapMsg = new imapMessage(dataUri.spec, daemon.inbox.uidnext++, []);
@@ -56,12 +57,8 @@ add_task(async function downloadEmail() 
   Assert.equal(inboxFolder.getTotalMessages(false), 1);
 });
 
 add_task(async function cleanUp() {
   NetworkTestUtils.shutdownServers();
   incomingServer.closeCachedConnections();
   server.stop();
 });
-
-function run_test() {
-  run_next_test();
-}
--- a/mailnews/imap/test/unit/test_imapRename.js
+++ b/mailnews/imap/test/unit/test_imapRename.js
@@ -2,16 +2,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This tests that renaming non-ASCII name folder works.
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 setupIMAPPump();
 
 var tests = [
   setup,
   test_rename,
@@ -42,23 +44,20 @@ function* test_rename() {
   let folder = rootFolder.getChildNamed("folder \u00e1");
   Assert.ok(folder.msgDatabase.summaryValid);
   Assert.equal("folder &AOE-", folder.filePath.leafName);
   Assert.equal("folder \u00e1", folder.prettyName);
 
   yield true;
 }
 
-var mfnListener =
-{
-  folderAdded: function folderAdded(aFolder)
-  {
+var mfnListener = {
+  folderAdded(aFolder) {
     // we are only using async yield on the target folder add
     if (aFolder.name == "folder 1")
       async_driver();
   },
 };
 
-function run_test()
-{
+function run_test() {
   async_run_tests(tests);
 }
 
--- a/mailnews/imap/test/unit/test_imapSearch.js
+++ b/mailnews/imap/test/unit/test_imapSearch.js
@@ -3,24 +3,26 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Tests traditional (non-gloda) search on IMAP folders.
  * Derived from a combination of test_imapPump.js and test_search.js
  * Original author: Kent James <kent@caspia.com>
  */
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 // headers we will store in db
 // set value of headers we want parsed into the db
 Services.prefs.setCharPref("mailnews.customDBHeaders",
                            "x-spam-status oneliner twoliner threeliner nospace withspace");
-dump('set mailnews.customDBHeaders to ' + Services.prefs.getCharPref("mailnews.customDBHeaders") + '\n');
+dump("set mailnews.customDBHeaders to " + Services.prefs.getCharPref("mailnews.customDBHeaders") + "\n");
 
 // set customHeaders, which post-bug 363238 should get added to the db. Note that all headers but the last
 //  seem to end in colon.
 Services.prefs.setCharPref("mailnews.customHeaders",
                            "x-uidl: x-bugzilla-watch-reason: x-bugzilla-component: received: x-spam-checker-version");
 
 // IMAP pump
 
@@ -30,285 +32,297 @@ Services.prefs.setCharPref("mailnews.cus
 var gMessage = "bugmail12"; // message file used as the test message
 
 setupIMAPPump();
 
 // Definition of tests
 var tests = [
   loadImapMessage,
   testSearch,
-  endTest
-]
+  endTest,
+];
 
 /*
 /*
  * Testing of general mail search features.
  *
  * This tests some search attributes not tested by other specific tests,
  * e.g., test_searchTag.js or test_searchJunk.js
  */
+/* import-globals-from ../../../test/resources/searchTestUtils.js */
 load("../../../resources/searchTestUtils.js");
 
-var nsMsgSearchScope = Ci.nsMsgSearchScope;
-var nsMsgSearchAttrib = Ci.nsMsgSearchAttrib;
-var nsMsgSearchOp = Ci.nsMsgSearchOp;
-
-var Isnt = nsMsgSearchOp.Isnt;
-var Is = nsMsgSearchOp.Is;
-var IsEmpty = nsMsgSearchOp.IsEmpty;
-var IsntEmpty = nsMsgSearchOp.IsntEmpty;
-var Contains = nsMsgSearchOp.Contains;
-var DoesntContain = nsMsgSearchOp.DoesntContain;
-var BeginsWith = nsMsgSearchOp.BeginsWith;
-var EndsWith = nsMsgSearchOp.EndsWith;
-var IsBefore = nsMsgSearchOp.IsBefore; // control entry not enabled
+var Isnt = Ci.nsMsgSearchOp.Isnt;
+var Is = Ci.nsMsgSearchOp.Is;
+var Contains = Ci.nsMsgSearchOp.Contains;
+var BeginsWith = Ci.nsMsgSearchOp.BeginsWith;
+var EndsWith = Ci.nsMsgSearchOp.EndsWith;
 
-var offlineMail = nsMsgSearchScope.offlineMail;
-var onlineMail = nsMsgSearchScope.onlineMail;
-var offlineMailFilter = nsMsgSearchScope.offlineMailFilter;
-var onlineMailFilter = nsMsgSearchScope.onlineMailFilter;
-var news = nsMsgSearchScope.news; // control entry not enabled
+var OtherHeader = Ci.nsMsgSearchAttrib.OtherHeader;
+var From = Ci.nsMsgSearchAttrib.Sender;
+var Subject = Ci.nsMsgSearchAttrib.Subject;
 
-var OtherHeader = nsMsgSearchAttrib.OtherHeader;
-var From = nsMsgSearchAttrib.Sender;
-var Subject = nsMsgSearchAttrib.Subject;
-
-var searchTests =
-[
+var searchTests = [
   // test the To: header
-  { testString: "PrimaryEmail1@test.invalid",
+  {
+    testString: "PrimaryEmail1@test.invalid",
     testAttribute: From,
     op: Is,
-    count: 1 },
-  { testString: "PrimaryEmail1@test.invalid",
+    count: 1,
+  }, {
+    testString: "PrimaryEmail1@test.invalid",
     testAttribute: From,
     op: Isnt,
-    count: 0 },
-  { testString: "PrimaryEmail",
+    count: 0,
+  }, {
+    testString: "PrimaryEmail",
     testAttribute: From,
     op: BeginsWith,
-    count: 1 },
-  { testString: "invalid",
+    count: 1,
+  }, {
+    testString: "invalid",
     testAttribute: From,
     op: BeginsWith,
-    count: 0 },
-  { testString: "invalid",
+    count: 0,
+  }, {
+    testString: "invalid",
+    testAttribute: From,
+    op: EndsWith,
+    count: 1,
+  }, {
+    testString: "Primary",
     testAttribute: From,
     op: EndsWith,
-    count: 1},
-  { testString: "Primary",
-    testAttribute: From,
-    op: EndsWith,
-    count: 0},
-  { testString: "QAContact",
+    count: 0,
+  }, {
+    testString: "QAContact",
+    testAttribute: OtherHeader,
+    op: BeginsWith,
+    count: 1,
+  }, {
+    testString: "filters",
     testAttribute: OtherHeader,
     op: BeginsWith,
-    count: 1},
-  { testString: "filters",
-    testAttribute: OtherHeader,
-    op: BeginsWith,
-    count: 0},
-  { testString: "mail.bugs",
+    count: 0,
+  }, {
+    testString: "mail.bugs",
     testAttribute: OtherHeader,
     op: EndsWith,
-    count: 1},
-  { testString: "QAContact",
+    count: 1,
+  }, {
+    testString: "QAContact",
     testAttribute: OtherHeader,
     op: EndsWith,
-    count: 0},
-  { testString: "QAcontact filters@mail.bugs",
+    count: 0,
+  }, {
+    testString: "QAcontact filters@mail.bugs",
     testAttribute: OtherHeader,
     op: Is,
-    count: 1},
-  { testString: "filters@mail.bugs",
+    count: 1,
+  }, {
+    testString: "filters@mail.bugs",
     testAttribute: OtherHeader,
     op: Is,
-    count: 0},
-  { testString: "QAcontact filters@mail.bugs",
+    count: 0,
+  }, {
+    testString: "QAcontact filters@mail.bugs",
     testAttribute: OtherHeader,
     op: Isnt,
-    count: 0},
-  { testString: "QAcontact",
+    count: 0,
+  }, {
+    testString: "QAcontact",
     testAttribute: OtherHeader,
     op: Isnt,
-    count: 1},
-  { testString: "filters",
+    count: 1,
+  }, {
+    testString: "filters",
     testAttribute: OtherHeader,
     op: Contains,
-    count: 1},
-  { testString: "foobar",
+    count: 1,
+  }, {
+    testString: "foobar",
     testAttribute: OtherHeader,
     op: Contains,
-    count: 0},
-
+    count: 0,
+  },
   // test accumulation of received header
-  // only in first received
-  { testString: "caspiaco",
+  {
+    // only in first received
+    testString: "caspiaco",
     testAttribute: OtherHeader,
     op: Contains,
     customHeader: "Received",
-    count: 1},
-  // only in second
-  { testString: "webapp01.sj.mozilla.com",
+    count: 1,
+  }, {
+    // only in second
+    testString: "webapp01.sj.mozilla.com",
     testAttribute: OtherHeader,
     op: Contains,
     customHeader: "received",
-    count: 1},
-  // in neither
-  { testString: "not there",
+    count: 1,
+  }, {
+    // in neither
+    testString: "not there",
     testAttribute: OtherHeader,
     op: Contains,
     customHeader: "received",
-    count: 0},
-
+    count: 0,
+  },
   // test multiple line arbitrary headers
-  // in the first line
-  { testString: "SpamAssassin 3.2.3",
+  {
+    // in the first line
+    testString: "SpamAssassin 3.2.3",
     testAttribute: OtherHeader,
     op: Contains,
     customHeader: "X-Spam-Checker-Version",
-    count: 1},
-  // in the second line
-  { testString: "host29.example.com",
+    count: 1,
+  }, {
+    // in the second line
+    testString: "host29.example.com",
+    testAttribute: OtherHeader,
+    op: Contains,
+    customHeader: "X-Spam-Checker-Version",
+    count: 1,
+  }, {
+    // spans two lines with space
+    testString: "on host29.example.com",
     testAttribute: OtherHeader,
     op: Contains,
     customHeader: "X-Spam-Checker-Version",
-    count: 1},
-  // spans two lines with space
-   { testString: "on host29.example.com",
-     testAttribute: OtherHeader,
-     op: Contains,
-     customHeader: "X-Spam-Checker-Version",
-     count: 1},
-
+    count: 1,
+  },
   // subject spanning several lines
-  // on the first line
-   { testString: "A filter will",
-     testAttribute: Subject,
-     op: Contains,
-     count: 1},
-   { testString: "I do not exist",
-     testAttribute: Subject,
-     op: Contains,
-     count: 0},
-  // on the second line
-   { testString: "this message",
-     testAttribute: Subject,
-     op: Contains,
-     count: 1},
-  // spanning second and third line
-   { testString: "over many",
-     testAttribute: Subject,
-     op: Contains,
-     count: 1},
-
+  {
+    // on the first line
+    testString: "A filter will",
+    testAttribute: Subject,
+    op: Contains,
+    count: 1,
+  }, {
+    testString: "I do not exist",
+    testAttribute: Subject,
+    op: Contains,
+    count: 0,
+  }, {
+    // on the second line
+    testString: "this message",
+    testAttribute: Subject,
+    op: Contains,
+    count: 1,
+  }, {
+    // spanning second and third line
+    testString: "over many",
+    testAttribute: Subject,
+    op: Contains,
+    count: 1,
+  },
   // tests of custom headers db values
-    { testString: "a one line header",
-      dbHeader: "oneliner"},
-    { testString: "a two line header",
-      dbHeader: "twoliner"},
-    { testString: "a three line header with lotsa space and tabs",
-      dbHeader: "threeliner"},
-    { testString: "I have no space",
-      dbHeader: "nospace"},
-    { testString: "too much space",
-      dbHeader: "withspace"},
-
+  {
+    testString: "a one line header",
+    dbHeader: "oneliner",
+  }, {
+    testString: "a two line header",
+    dbHeader: "twoliner",
+  }, {
+    testString: "a three line header with lotsa space and tabs",
+    dbHeader: "threeliner",
+  }, {
+    testString: "I have no space",
+    dbHeader: "nospace",
+  }, {
+    testString: "too much space",
+    dbHeader: "withspace",
+  },
   // tests of custom db headers in a search
-    { testString: "one line",
-      testAttribute: OtherHeader,
-      op: Contains,
-      customHeader: "oneliner",
-      count: 1},
-    { testString: "two line header",
-      testAttribute: OtherHeader,
-      op: Contains,
-      customHeader: "twoliner",
-      count: 1},
-    { testString: "three line header with lotsa",
-      testAttribute: OtherHeader,
-      op: Contains,
-      customHeader: "threeliner",
-      count: 1},
-    { testString: "I have no space",
-      testAttribute: OtherHeader,
-      op: Contains,
-      customHeader: "nospace",
-      count: 1},
-    { testString: "too much space",
-      testAttribute: OtherHeader,
-      op: Contains,
-      customHeader: "withspace",
-      count: 1}
+  {
+    testString: "one line",
+    testAttribute: OtherHeader,
+    op: Contains,
+    customHeader: "oneliner",
+    count: 1,
+  }, {
+    testString: "two line header",
+    testAttribute: OtherHeader,
+    op: Contains,
+    customHeader: "twoliner",
+    count: 1,
+  }, {
+    testString: "three line header with lotsa",
+    testAttribute: OtherHeader,
+    op: Contains,
+    customHeader: "threeliner",
+    count: 1,
+  }, {
+    testString: "I have no space",
+    testAttribute: OtherHeader,
+    op: Contains,
+    customHeader: "nospace",
+    count: 1,
+  }, {
+    testString: "too much space",
+    testAttribute: OtherHeader,
+    op: Contains,
+    customHeader: "withspace",
+    count: 1,
+  },
 ];
 
 // load and update a message in the imap fake server
-function* loadImapMessage()
-{
+function* loadImapMessage() {
   IMAPPump.mailbox.addMessage(new imapMessage(specForFileName(gMessage),
                           IMAPPump.mailbox.uidnext++, []));
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 
   Assert.equal(1, IMAPPump.inbox.getTotalMessages(false));
   yield true;
 }
 
 // process each test from queue, calls itself upon completion of each search
-var testObject;
-function* testSearch()
-{
-  while (searchTests.length)
-  {
+function* testSearch() {
+  while (searchTests.length) {
     let test = searchTests.shift();
-    if (test.dbHeader)
-    {
+    if (test.dbHeader) {
       //  test of a custom db header
       dump("testing dbHeader " + test.dbHeader + "\n");
       let customValue = mailTestUtils.firstMsgHdr(IMAPPump.inbox)
                                      .getProperty(test.dbHeader);
       Assert.equal(customValue, test.testString);
-    }
-    else
-    {
+    } else {
       dump("testing for string '" + test.testString + "'\n");
-      testObject = new TestSearch(IMAPPump.inbox,
-                           test.testString,
-                           test.testAttribute,
-                           test.op,
-                           test.count,
-                           async_driver,
-                           null,
-                           test.customHeader ? test.customHeader : "X-Bugzilla-Watch-Reason");
+      new TestSearch(IMAPPump.inbox,
+                     test.testString,
+                     test.testAttribute,
+                     test.op,
+                     test.count,
+                     async_driver,
+                     null,
+                     test.customHeader ? test.customHeader : "X-Bugzilla-Watch-Reason");
       yield false;
     }
   }
-  testObject = null;
   yield true;
 }
 
 // Cleanup at end
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
 
-function run_test()
-{
+function run_test() {
   // don't use offline store
   IMAPPump.inbox.clearFlag(Ci.nsMsgFolderFlags.Offline);
 
   async_run_tests(tests);
 }
 
 /*
  * helper function
  */
 
 // given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
+function specForFileName(aFileName) {
   let file = do_get_file("../../../data/" + aFileName);
   let msgfileuri = Services.io.newFileURI(file)
                               .QueryInterface(Ci.nsIFileURL);
   return msgfileuri.spec;
 }
 
--- a/mailnews/imap/test/unit/test_imapStatusCloseDBs.js
+++ b/mailnews/imap/test/unit/test_imapStatusCloseDBs.js
@@ -1,29 +1,31 @@
 // This file tests that checking folders for new mail with STATUS
 // doesn't leave db's open.
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 var gFolder1, gFolder2;
 
 var tests = [
   setup,
   check,
-  teardown
+  teardown,
 ];
 
 function* setup() {
   Services.prefs.setBoolPref("mail.check_all_imap_folders_for_new", true);
 
   setupIMAPPump();
 
-  IMAPPump.daemon.createMailbox("folder 1", {subscribed : true});
-  IMAPPump.daemon.createMailbox("folder 2", {subscribed : true});
+  IMAPPump.daemon.createMailbox("folder 1", {subscribed: true});
+  IMAPPump.daemon.createMailbox("folder 2", {subscribed: true});
 
   IMAPPump.server.performTest("SUBSCRIBE");
 
   let rootFolder = IMAPPump.incomingServer.rootFolder;
   gFolder1 = rootFolder.getChildNamed("folder 1");
   gFolder2 = rootFolder.getChildNamed("folder 2");
 
   IMAPPump.inbox.getNewMessages(null, null);
--- a/mailnews/imap/test/unit/test_imapStoreMsgOffline.js
+++ b/mailnews/imap/test/unit/test_imapStoreMsgOffline.js
@@ -3,71 +3,70 @@
  * offline stores correctly, when we fetch the message for display.
  * It checks:
  *   - Normal messages, no attachments.
  *   - Message with inline attachment (e.g., image)
  *   - Message with non-inline attachment (e.g., .doc file)
  *   - Message with mix of attachment types.
  */
 
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
+/* import-globals-from ../../../test/resources/messageGenerator.js */
+/* import-globals-from ../../../test/resources/messageModifier.js */
+/* import-globals-from ../../../test/resources/messageInjection.js */
 load("../../../resources/messageGenerator.js");
 load("../../../resources/messageModifier.js");
 load("../../../resources/messageInjection.js");
 
 var gMessageGenerator = new MessageGenerator();
-var gScenarioFactory = new MessageScenarioFactory(gMessageGenerator);
 
 var gMsgFile1 = do_get_file("../../../data/bugmail10");
 var gMsgId1 = "200806061706.m56H6RWT004933@mrapp54.mozilla.org";
 var gMsgFile2 = do_get_file("../../../data/image-attach-test");
 var gMsgId2 = "4A947F73.5030709@example.com";
 var gMsgFile3 = do_get_file("../../../data/external-attach-test");
 var gMsgId3 = "876TY.5030709@example.com";
 
 var gFirstNewMsg;
 var gFirstMsgSize;
 var gImapInboxOfflineStoreSize;
 
 // We use this as a display consumer
-var streamListener =
-{
+var streamListener = {
   _data: "",
 
   QueryInterface:
     ChromeUtils.generateQI([Ci.nsIStreamListener, Ci.nsIRequestObserver]),
 
   // nsIRequestObserver
-  onStartRequest: function(aRequest) {
+  onStartRequest(aRequest) {
   },
-  onStopRequest: function(aRequest, aStatusCode) {
+  onStopRequest(aRequest, aStatusCode) {
     Assert.equal(aStatusCode, 0);
   },
 
   // nsIStreamListener
-  onDataAvailable: function(aRequest, aInputStream, aOffset, aCount) {
+  onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
     let scriptStream = Cc["@mozilla.org/scriptableinputstream;1"]
                          .createInstance(Ci.nsIScriptableInputStream);
 
     scriptStream.init(aInputStream);
 
     scriptStream.read(aCount);
-  }
+  },
 };
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox)
-{
+function addMessagesToServer(messages, mailbox) {
   // For every message we have, we need to convert it to a file:/// URI
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     let URI = Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
     // Create the imapMessage and store it on the mailbox.
     mailbox.addMessage(new imapMessage(URI.spec, mailbox.uidnext++, []));
   });
 }
 
 function setup() {
   // We aren't interested in downloading messages automatically
@@ -80,17 +79,17 @@ function setup() {
   // Services.prefs.setIntPref("mail.imap.mime_parts_on_demand_threshold", 3000);
 
   setupIMAPPump();
 
   // these hacks are required because we've created the inbox before
   // running initial folder discovery, and adding the folder bails
   // out before we set it as verified online, so we bail out, and
   // then remove the INBOX folder since it's not verified.
-  IMAPPump.inbox.hierarchyDelimiter = '/';
+  IMAPPump.inbox.hierarchyDelimiter = "/";
   IMAPPump.inbox.verifiedAsOnlineFolder = true;
 
 
   // Add a couple of messages to the INBOX
   // this is synchronous, afaik
   addMessagesToServer([{file: gMsgFile1, messageId: gMsgId1},
                        {file: gMsgFile2, messageId: gMsgId2},
                        {file: gMsgFile3, messageId: gMsgId3},
@@ -109,125 +108,122 @@ var tests = [
   function* selectFirstMsg() {
     // We postpone creating the imap service until after we've set the prefs
     // that it reads on its startup.
     gIMAPService = Cc["@mozilla.org/messenger/messageservice;1?type=imap"]
                      .getService(Ci.nsIMsgMessageService);
 
     let db = IMAPPump.inbox.msgDatabase;
     let msg1 = db.getMsgHdrForMessageID(gMsgId1);
-    let url = new Object;
+    let url = {};
     gIMAPService.DisplayMessage(IMAPPump.inbox.getUriForMsg(msg1),
                                             streamListener,
                                             null,
                                             asyncUrlListener,
                                             null,
                                             url);
     yield false;
   },
   function* select2ndMsg() {
     let msg1 = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
     Assert.notEqual(msg1.flags & Ci.nsMsgMessageFlags.Offline, 0);
     let db = IMAPPump.inbox.msgDatabase;
     let msg2 = db.getMsgHdrForMessageID(gMsgId2);
-    let url = new Object;
+    let url = {};
     gIMAPService.DisplayMessage(IMAPPump.inbox.getUriForMsg(msg2),
                                             streamListener,
                                             null,
                                             asyncUrlListener,
                                             null,
                                             url);
     yield false;
   },
   function* select3rdMsg() {
     let msg2 = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId2);
     Assert.notEqual(msg2.flags & Ci.nsMsgMessageFlags.Offline, 0);
     let db = IMAPPump.inbox.msgDatabase;
     let msg3 = db.getMsgHdrForMessageID(gMsgId3);
-    let url = new Object;
+    let url = {};
     gIMAPService.DisplayMessage(IMAPPump.inbox.getUriForMsg(msg3),
                                             streamListener,
                                             null,
                                             asyncUrlListener,
                                             null,
                                             url);
     yield false;
   },
   function verify3rdMsg() {
-    let msg3 = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId3);
+    // let msg3 =
+    IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId3);
     // can't turn this on because our fake server doesn't support body structure.
-//    do_check_eq(msg3.flags & Ci.nsMsgMessageFlags.Offline, 0);
+    // do_check_eq(msg3.flags & Ci.nsMsgMessageFlags.Offline, 0);
   },
   function* addNewMsgs() {
-    let mbox = IMAPPump.daemon.getMailbox("INBOX")
+    let mbox = IMAPPump.daemon.getMailbox("INBOX");
     // make a couple of messages
     let messages = [];
     let bodyString = "";
     for (let i = 0; i < 100; i++)
       bodyString += "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n";
 
-    let gMessageGenerator = new MessageGenerator();
+    gMessageGenerator = new MessageGenerator();
     messages = messages.concat(gMessageGenerator.makeMessage({body: {body: bodyString, contentType: "text/plain"}}));
 
     gFirstNewMsg = mbox.uidnext;
     // need to account for x-mozilla-status, status2, and envelope.
     gFirstMsgSize = messages[0].toMessageString().length + 102;
 
-    messages.forEach(function (message)
-    {
+    messages.forEach(function(message) {
       let dataUri = Services.io.newURI("data:text/plain;base64," +
                                        btoa(message.toMessageString()));
       mbox.addMessage(new imapMessage(dataUri.spec, mbox.uidnext++, []));
     });
     IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
     yield false;
   },
-  function* testQueuedOfflineDownload()
-  {
+  function* testQueuedOfflineDownload() {
     // Make sure that streaming the same message and then trying to download
     // it for offline use doesn't end up in it getting added to the offline
     // store twice.
     gImapInboxOfflineStoreSize = IMAPPump.inbox.filePath.fileSize + gFirstMsgSize;
     let newMsgHdr = IMAPPump.inbox.GetMessageHeader(gFirstNewMsg);
     let msgURI = newMsgHdr.folder.getUriForMsg(newMsgHdr);
     let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
     let msgServ = messenger.messageServiceFromURI(msgURI);
     msgServ.streamMessage(msgURI, gStreamListener, null, null, false, "", false);
     yield false;
   },
-  function* firstStreamFinished()
-  {
+  function* firstStreamFinished() {
     // nsIMsgFolder.DownloadMessagesForOffline does not take a listener, so
     // we invoke nsIImapService.downloadMessagesForOffline directly with a
     // listener.
     MailServices.imap.downloadMessagesForOffline(gFirstNewMsg,
                                                  IMAPPump.inbox,
                                                  asyncUrlListener,
                                                  null);
     yield false;
   },
-  function checkOfflineStoreSize()
-  {
+  function checkOfflineStoreSize() {
     dump("checking offline store size\n");
     Assert.ok(IMAPPump.inbox.filePath.fileSize <= gImapInboxOfflineStoreSize);
   },
-  teardown
-]
+  teardown,
+];
 
 var gStreamListener = {
-  QueryInterface : ChromeUtils.generateQI([Ci.nsIStreamListener]),
-  _stream : null,
-  _data : null,
-  onStartRequest : function (aRequest) {
+  QueryInterface: ChromeUtils.generateQI([Ci.nsIStreamListener]),
+  _stream: null,
+  _data: null,
+  onStartRequest(aRequest) {
     this._data = "";
   },
-  onStopRequest : function (aRequest, aStatusCode) {
+  onStopRequest(aRequest, aStatusCode) {
     async_driver();
   },
-  onDataAvailable : function (aRequest, aInputStream, aOff, aCount) {
+  onDataAvailable(aRequest, aInputStream, aOff, aCount) {
     if (this._stream == null) {
       this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
       this._stream.init(aInputStream);
     }
     this._data += this._stream.read(aCount);
   },
 };
 
--- a/mailnews/imap/test/unit/test_imapUndo.js
+++ b/mailnews/imap/test/unit/test_imapUndo.js
@@ -2,64 +2,62 @@
 // There are three main cases:
 // 1. Normal undo
 // 2. Undo after the source folder has been compacted.
 // 2.1 Same, but the server doesn't support COPYUID (GMail case)
 //
 // Original Author: David Bienvenu <bienvenu@nventure.com>
 
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 var gRootFolder;
-var gLastKey;
 var gMessages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
-var gCopyService = MailServices.copy;
 var gMsgWindow;
 
 var gMsgFile1 = do_get_file("../../../data/bugmail10");
 var gMsgFile2 = do_get_file("../../../data/bugmail11");
-var gMsgFile3 = do_get_file("../../../data/draft1");
+// var gMsgFile3 = do_get_file("../../../data/draft1");
 var gMsgFile4 = do_get_file("../../../data/bugmail7");
 var gMsgFile5 = do_get_file("../../../data/bugmail6");
 
 // Copied straight from the example files
 var gMsgId1 = "200806061706.m56H6RWT004933@mrapp54.mozilla.org";
 var gMsgId2 = "200804111417.m3BEHTk4030129@mrapp51.mozilla.org";
-var gMsgId3 = "4849BF7B.2030800@example.com";
+// var gMsgId3 = "4849BF7B.2030800@example.com";
 var gMsgId4 = "bugmail7.m47LtAEf007542@mrapp51.mozilla.org";
 var gMsgId5 = "bugmail6.m47LtAEf007542@mrapp51.mozilla.org";
 
 
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox)
-{
+function addMessagesToServer(messages, mailbox) {
   // For every message we have, we need to convert it to a file:/// URI
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     let URI = Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
     // Create the imapMessage and store it on the mailbox.
     mailbox.addMessage(new imapMessage(URI.spec, mailbox.uidnext++, []));
   });
 }
 
 function alertListener() {}
 
 alertListener.prototype = {
-  reset: function () {
+  reset() {
   },
 
-  onAlert: function (aMessage, aMsgWindow) {
+  onAlert(aMessage, aMsgWindow) {
     dump("got alert " + aMessage + "\n");
-    do_throw ('TEST FAILED ' + aMessage);
-  }
+    do_throw("TEST FAILED " + aMessage);
+  },
 };
 
 var tests = [
   setup,
   function* updateFolder() {
     IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
     yield false;
   },
@@ -90,17 +88,17 @@ var tests = [
     IMAPPump.inbox.updateFolderWithListener(gMsgWindow, asyncUrlListener);
     yield false;
   },
   function verifyFolders() {
     let msgRestored = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
     Assert.ok(msgRestored !== null);
     Assert.equal(IMAPPump.inbox.msgDatabase.dBFolderInfo.numMessages, 4);
   },
-  teardown
+  teardown,
 ];
 
 function setup() {
   setupIMAPPump();
 
   var listener1 = new alertListener();
 
   MailServices.mailSession.addUserFeedbackListener(listener1);
@@ -111,17 +109,17 @@ function setup() {
   gMsgWindow = Cc["@mozilla.org/messenger/msgwindow;1"]
                   .createInstance(Ci.nsIMsgWindow);
 
   gRootFolder = IMAPPump.incomingServer.rootFolder;
   // these hacks are required because we've created the inbox before
   // running initial folder discovery, and adding the folder bails
   // out before we set it as verified online, so we bail out, and
   // then remove the INBOX folder since it's not verified.
-  IMAPPump.inbox.hierarchyDelimiter = '/';
+  IMAPPump.inbox.hierarchyDelimiter = "/";
   IMAPPump.inbox.verifiedAsOnlineFolder = true;
 
 
   // Add a couple of messages to the INBOX
   // this is synchronous, afaik
   addMessagesToServer([{file: gMsgFile1, messageId: gMsgId1},
                        {file: gMsgFile4, messageId: gMsgId4},
                        {file: gMsgFile5, messageId: gMsgId5},
--- a/mailnews/imap/test/unit/test_imapUrls.js
+++ b/mailnews/imap/test/unit/test_imapUrls.js
@@ -9,18 +9,17 @@
 // IMAP pump
 
 setupIMAPPump();
 
 /*
  * Test parsing of imap uri's with very large UID's.
  */
 
-function run_test()
-{
+function run_test() {
   let imapS = Cc["@mozilla.org/messenger/messageservice;1?type=imap"]
                 .getService(Ci.nsIMsgMessageService);
   let uri = {};
   imapS.GetUrlForUri("imap-message://user@localhost/INBOX#4294967168", uri, null);
   Assert.equal(uri.value.spec, "imap://user@localhost:" + IMAPPump.server.port +
       "/fetch%3EUID%3E%5EINBOX%3E4294967168");
   teardownIMAPPump();
 }
--- a/mailnews/imap/test/unit/test_largeOfflineStore.js
+++ b/mailnews/imap/test/unit/test_largeOfflineStore.js
@@ -1,45 +1,47 @@
 /* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Test to ensure that downloadAllForOffline works correctly for large imap
  * stores, i.e., over 4 GiB.
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 Services.prefs.setCharPref("mail.serverDefaultStoreContractID",
                            "@mozilla.org/msgstore/berkeleystore;1");
 
 var gOfflineStoreSize;
 
 var tests = [
   setup,
   check_result,
-  teardown
+  teardown,
 ];
 
 function run_test() {
   setupIMAPPump();
 
   // Figure out the name of the IMAP inbox
   let inboxFile = IMAPPump.incomingServer.rootMsgFolder.filePath;
   inboxFile.append("INBOX");
   if (!inboxFile.exists())
     inboxFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0644", 8));
 
   let neededFreeSpace = 0x200000000;
   // On Windows, check whether the drive is NTFS. If it is, mark the file as
   // sparse. If it isn't, then bail out now, because in all probability it is
   // FAT32, which doesn't support file sizes greater than 4 GB.
   if ("@mozilla.org/windows-registry-key;1" in Cc &&
-      mailTestUtils.get_file_system(inboxFile) != "NTFS")
-  {
+      mailTestUtils.get_file_system(inboxFile) != "NTFS") {
     dump("On Windows, this test only works on NTFS volumes.\n");
     teardown();
     return;
   }
 
   let isFileSparse = mailTestUtils.mark_file_region_sparse(inboxFile, 0, 0x10000000f);
   let freeDiskSpace = inboxFile.diskSpaceAvailable;
   info("Free disk space = " + mailTestUtils.toMiBString(freeDiskSpace));
@@ -114,17 +116,17 @@ function* check_result() {
     // Verify that each message has been downloaded and looks OK.
     if (!(header instanceof Ci.nsIMsgDBHdr &&
           (header.flags & Ci.nsMsgMessageFlags.Offline)))
       do_throw("Message not downloaded for offline use");
 
     IMAPPump.inbox.getOfflineFileStream(header.messageKey, offset, size).close();
     info("Msg hdr offset = " + offset.value);
   }
-};
+}
 
 function teardown() {
   // Free up disk space - if you want to look at the file after running
   // this test, comment out this line.
   if (IMAPPump.inbox)
     IMAPPump.inbox.filePath.remove(false);
 
   teardownIMAPPump();
--- a/mailnews/imap/test/unit/test_listClosesDB.js
+++ b/mailnews/imap/test/unit/test_listClosesDB.js
@@ -1,37 +1,40 @@
 // This file tests that listing folders on startup because we're not using
 // subscription doesn't leave db's open.
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 var gSub3;
 
 var tests = [
   setup,
   updateInbox,
   checkCachedDBForFolder,
-  teardown
+  teardown,
 ];
 
 function* setup() {
   setupIMAPPump();
 
-  IMAPPump.daemon.createMailbox("folder1", {subscribed : true});
-  IMAPPump.daemon.createMailbox("folder1/sub1", "", {subscribed : true});
-  IMAPPump.daemon.createMailbox("folder1/sub1/sub2", "", {subscribed : true});
-  IMAPPump.daemon.createMailbox("folder1/sub1/sub2/sub3", "", {subscribed : true});
+  IMAPPump.daemon.createMailbox("folder1", {subscribed: true});
+  IMAPPump.daemon.createMailbox("folder1/sub1", "", {subscribed: true});
+  IMAPPump.daemon.createMailbox("folder1/sub1/sub2", "", {subscribed: true});
+  IMAPPump.daemon.createMailbox("folder1/sub1/sub2/sub3", "", {subscribed: true});
 
   IMAPPump.incomingServer.usingSubscription = false;
 
   let rootFolder = IMAPPump.incomingServer.rootFolder.QueryInterface(Ci.nsIMsgImapMailFolder);
-  rootFolder.hierarchyDelimiter = '/';
-  IMAPPump.inbox.hierarchyDelimiter = '/';
+  rootFolder.hierarchyDelimiter = "/";
+  IMAPPump.inbox.hierarchyDelimiter = "/";
   rootFolder.addSubfolder("folder1");
   rootFolder.addSubfolder("folder1/sub1");
   rootFolder.addSubfolder("folder1/sub1/sub2");
   gSub3 = rootFolder.addSubfolder("folder1/sub1/sub2/sub3");
   IMAPPump.server.performTest("LIST");
 
   do_timeout(1000, async_driver);
   yield false;
--- a/mailnews/imap/test/unit/test_listSubscribed.js
+++ b/mailnews/imap/test/unit/test_listSubscribed.js
@@ -8,16 +8,19 @@
 /* References:
  * RFC 5258 - http://tools.ietf.org/html/rfc5258
  * Bug 495318
  * Bug 816028
  * http://bugzilla.zimbra.com/show_bug.cgi?id=78794
  */
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/alertTestUtils.js");
 
 // IMAP pump
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
@@ -27,73 +30,71 @@ var {Services} = ChromeUtils.import("res
 // it also has a bug that causes a server crash in certain setups
 setupIMAPPump("Zimbra");
 
 // Definition of tests
 var tests = [
   setupMailboxes,
   testListSubscribed,
   testZimbraServerVersions,
-  endTest
-]
+  endTest,
+];
 
 // setup the mailboxes that will be used for this test
-function* setupMailboxes()
-{
+function* setupMailboxes() {
   IMAPPump.mailbox.subscribed = true;
-  IMAPPump.daemon.createMailbox("folder1", {subscribed : true, flags : ["\\Noselect"]});
-  IMAPPump.daemon.createMailbox("folder1/folder11", {subscribed : true, flags : ["\\Noinferiors"]});
-  IMAPPump.daemon.createMailbox("folder2", {subscribed : true, nonExistent : true});
+  IMAPPump.daemon.createMailbox("folder1", {subscribed: true, flags: ["\\Noselect"]});
+  IMAPPump.daemon.createMailbox("folder1/folder11", {subscribed: true, flags: ["\\Noinferiors"]});
+  IMAPPump.daemon.createMailbox("folder2", {subscribed: true, nonExistent: true});
   IMAPPump.daemon.createMailbox("folder3", {});
 
   // select the inbox to force folder discovery, etc.
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
 // tests that LIST (SUBSCRIBED) returns the proper response
-function* testListSubscribed()
-{
+function* testListSubscribed() {
   // check that we have \Noselect and \Noinferiors flags - these would not have
   // been returned if we had used LSUB instead of LIST(SUBSCRIBED)
   let rootFolder = IMAPPump.incomingServer.rootFolder;
   let folder1 = rootFolder.getChildNamed("folder1");
   Assert.ok(folder1.getFlag(Ci.nsMsgFolderFlags.ImapNoselect));
   Assert.ok(!folder1.getFlag(Ci.nsMsgFolderFlags.ImapNoinferiors));
 
   // make sure the above test was not a fluke
   let folder11 = folder1.getChildNamed("folder11");
   Assert.ok(!folder11.getFlag(Ci.nsMsgFolderFlags.ImapNoselect));
   Assert.ok(folder11.getFlag(Ci.nsMsgFolderFlags.ImapNoinferiors));
 
   // test that \NonExistent implies \Noselect
-  let folder2 = rootFolder.getChildNamed("folder2");
+  rootFolder.getChildNamed("folder2");
   Assert.ok(folder1.getFlag(Ci.nsMsgFolderFlags.ImapNoselect));
 
   // should not get a folder3 since it is not subscribed
   let folder3;
   try {
     folder3 = rootFolder.getChildNamed("folder3");
   } catch (ex) {}
-  //do_check_false(folder1.getFlag(Ci.nsMsgFolderFlags.Subscribed));
+  // do_check_false(folder1.getFlag(Ci.nsMsgFolderFlags.Subscribed));
   Assert.equal(null, folder3);
 
   yield true;
 }
 
 function* testZimbraServerVersions() {
   // older versions of Zimbra can crash if we send LIST (SUBSCRIBED) so we want
   // to make sure that we are checking for versions
 
-  let testValues = [ { version : '6.3.1_GA_2790', expectedResult : false },
-                     { version : '7.2.2_GA_2790', expectedResult : false },
-                     { version : '7.2.3_GA_2790', expectedResult : true },
-                     { version : '8.0.2_GA_2790', expectedResult : false },
-                     { version : '8.0.3_GA_2790', expectedResult : true },
-                     { version : '9.0.0_GA_2790', expectedResult : true } ];
+  let testValues = [ { version: "6.3.1_GA_2790", expectedResult: false },
+                     { version: "7.2.2_GA_2790", expectedResult: false },
+                     { version: "7.2.3_GA_2790", expectedResult: true },
+                     { version: "8.0.2_GA_2790", expectedResult: false },
+                     { version: "8.0.3_GA_2790", expectedResult: true },
+                     { version: "9.0.0_GA_2790", expectedResult: true } ];
 
   for (let i = 0; i < testValues.length; i++) {
     IMAPPump.daemon.idResponse = '("NAME" "Zimbra" ' +
                              '"VERSION" "' + testValues[i].version + '" ' +
                              '"RELEASE" "20120815212257" ' +
                              '"USER" "user@domain.com" ' +
                              '"SERVER" "14b63305-d002-4f1b-bcd9-23d402d4ef40")';
     IMAPPump.incomingServer.closeCachedConnections();
@@ -105,38 +106,16 @@ function* testZimbraServerVersions() {
     let rootFolder = IMAPPump.incomingServer.rootFolder;
     let folder1 = rootFolder.getChildNamed("folder1");
     Assert.equal(folder1.getFlag(Ci.nsMsgFolderFlags.ImapNoselect),
                  testValues[i].expectedResult);
   }
 }
 
 // Cleanup at end
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
 
-function run_test()
-{
+function run_test() {
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
   async_run_tests(tests);
 }
-
-/*
- * helper functions
- */
-
-// given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
-  let file = do_get_file("../../../data/" + aFileName);
-  let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
-  return msgfileuri.spec;
-}
-
-function recursiveDeleteMailboxes(aMailbox)
-{
-  for (var child of aMailbox.allChildren) {
-    recursiveDeleteMailboxes(child);
-  }
-  IMAPPump.daemon.deleteMailbox(aMailbox);
-}
--- a/mailnews/imap/test/unit/test_localToImapFilter.js
+++ b/mailnews/imap/test/unit/test_localToImapFilter.js
@@ -2,36 +2,30 @@
  * This file tests copies of multiple messages using filters
  * from incoming POP3, with filter actions copying and moving
  * messages to IMAP folders. This test is adapted from
  * test_imapFolderCopy.js
  *
  * Original author: Kent James <kent@caspia.com>
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/POP3pump.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/POP3pump.js");
 
-var {
-  getFolderProperties,
-  getSpecialFolderString,
-  allAccountsSorted,
-  getMostRecentFolders,
-  folderNameCompare,
-} = ChromeUtils.import("resource:///modules/folderUtils.jsm");
 var {fixIterator, toXPCOMArray} = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
-var gIMAPTrashFolder;
 var gEmptyLocal1, gEmptyLocal2;
-var gLastKey;
 var gMessages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
 var gFiles = ["../../../data/bugmail1",
-                "../../../data/draft1"];
+              "../../../data/draft1"];
 
 var tests = [
   setup,
   function* copyFolder1() {
     dump("gEmpty1 " + gEmptyLocal1.URI + "\n");
     let folders = [];
     folders.push(gEmptyLocal1.QueryInterface(Ci.nsIMsgFolder));
     let array = toXPCOMArray(folders, Ci.nsIMutableArray);
@@ -89,79 +83,72 @@ var tests = [
     Assert.ok(folder2 !== null);
     // folder 1 and 2 should each now have 2 messages in them.
     Assert.equal(folderCount(folder1), 2);
     Assert.equal(folderCount(folder2), 2);
     // the local inbox folder should now be empty, since the second
     // operation was a move
     Assert.equal(folderCount(localAccountUtils.inboxFolder), 0);
   },
-  teardown
+  teardown,
 ];
 
-function folderCount(folder)
-{
+function folderCount(folder) {
   let enumerator = folder.msgDatabase.EnumerateMessages();
   let count = 0;
+  // eslint-disable-next-line no-unused-vars
   for (let hdr of fixIterator(enumerator, Ci.nsIMsgDBHdr)) {
     count++;
   }
   return count;
 }
 
 function setup() {
   setupIMAPPump();
   gEmptyLocal1 = localAccountUtils.rootFolder.createLocalSubfolder("empty 1");
   gEmptyLocal2 = localAccountUtils.rootFolder.createLocalSubfolder("empty 2");
 
   // these hacks are required because we've created the inbox before
   // running initial folder discovery, and adding the folder bails
   // out before we set it as verified online, so we bail out, and
   // then remove the INBOX folder since it's not verified.
-  IMAPPump.inbox.hierarchyDelimiter = '/';
+  IMAPPump.inbox.hierarchyDelimiter = "/";
   IMAPPump.inbox.verifiedAsOnlineFolder = true;
 }
 
 // nsIMsgCopyServiceListener implementation - runs next test when copy
 // is completed.
-var CopyListener =
-{
-  OnStartCopy: function OnStartCopy() {},
-  OnProgress: function OnProgress(aProgress, aProgressMax) {},
-  SetMessageKey: function SetMessageKey(aKey)
-  {
-    gLastKey = aKey;
-  },
-  SetMessageId: function SetMessageId(aMessageId) {},
-  OnStopCopy: function OnStopCopy(aStatus)
-  {
+var CopyListener = {
+  OnStartCopy() {},
+  OnProgress(aProgress, aProgressMax) {},
+  SetMessageKey(aKey) {},
+  SetMessageId(aMessageId) {},
+  OnStopCopy(aStatus) {
     // Check: message successfully copied.
     Assert.equal(aStatus, 0);
     async_driver();
-  }
+  },
 };
 
 asyncUrlListener.callback = function(aUrl, aExitCode) {
   Assert.equal(aExitCode, 0);
 };
 
 function listMessages(folder) {
   let enumerator = folder.msgDatabase.EnumerateMessages();
   var msgCount = 0;
   dump("listing messages for " + folder.prettyName + "\n");
-  for (let hdr of fixIterator(enumerator, Ci.nsIMsgDBHdr))
-  {
+  for (let hdr of fixIterator(enumerator, Ci.nsIMsgDBHdr)) {
     msgCount++;
     dump(msgCount + ": " + hdr.subject + "\n");
   }
 }
 
 function teardown() {
   gMessages.clear();
-  gIMAPTrashFolder = null;
   gEmptyLocal1 = null;
   gEmptyLocal2 = null;
   gPOP3Pump = null;
   teardownIMAPPump();
 }
 
 function run_test() {
   async_run_tests(tests);
--- a/mailnews/imap/test/unit/test_localToImapFilterQuarantine.js
+++ b/mailnews/imap/test/unit/test_localToImapFilterQuarantine.js
@@ -10,19 +10,22 @@
  *
  */
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 Services.prefs.setCharPref("mail.serverDefaultStoreContractID",
                            "@mozilla.org/msgstore/berkeleystore;1");
 
+/* import-globals-from ../../../test/resources/POP3pump.js */
 load("../../../resources/POP3pump.js");
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 // IMAP pump
 
 setupIMAPPump();
 
 var gFinishedRunningURL = -1;
@@ -31,28 +34,27 @@ var gSubfolder;
 // tests
 
 var quarantineTests = [
   createSubfolder,
   getLocalMessages,
   updateSubfolderAndTest,
   get2Messages,
   updateSubfolderAndTest2,
-  endTest
+  endTest,
 ];
 
-function* createSubfolder()
-{
+function* createSubfolder() {
   IMAPPump.incomingServer.rootFolder.createSubfolder("subfolder", null);
-  dl('wait for folderAdded notification');
+  dl("wait for folderAdded notification");
   yield false;
   gSubfolder = IMAPPump.incomingServer.rootFolder.getChildNamed("subfolder");
   Assert.ok(gSubfolder instanceof Ci.nsIMsgImapMailFolder);
   gSubfolder.updateFolderWithListener(null, urlListener);
-  dl('wait for OnStopRunningURL');
+  dl("wait for OnStopRunningURL");
   yield false;
 }
 
 function* getLocalMessages() {
   // setup copy then move mail filters on the inbox
   let filterList = gPOP3Pump.fakeServer.getFilterList(null);
   let filter = filterList.createFilter("copyThenMoveAll");
   let searchTerm = filter.createTerm();
@@ -61,174 +63,168 @@ function* getLocalMessages() {
   let copyAction = filter.createAction();
   copyAction.type = Ci.nsMsgFilterAction.CopyToFolder;
   copyAction.targetFolderUri = gSubfolder.URI;
   filter.appendAction(copyAction);
   filter.enabled = true;
   filterList.insertFilterAt(0, filter);
 
   gPOP3Pump.files = ["../../../data/bugmail1"];
-  gPOP3Pump.onDone = function() {dump('POP3Pump done\n');async_driver();};
+  gPOP3Pump.onDone = function() {
+    dump("POP3Pump done\n");
+    async_driver();
+  };
   gPOP3Pump.run();
-  dl('waiting for POP3Pump done');
+  dl("waiting for POP3Pump done");
   yield false;
 }
 
 function checkResult() {
   if (gFinishedRunningURL == 1) {
     async_driver();
     gFinishedRunningURL = -1;
-    return;
-  }
-  else if (gFinishedRunningURL == 0) {
+  } else if (gFinishedRunningURL == 0) {
     gSubfolder.updateFolderWithListener(null, urlListener);
     do_timeout(100, checkResult);
-    return;
   }
   // Else just ignore it.
 }
 
 function* updateSubfolderAndTest() {
   // The previous function does an append, which may take a bit of time to
   // complete. Unfortunately updateFolderWithListener succeeds successfully
   // if there is a url running, but doesn't tell us that is the case. So we
   // have to run updateFolderWithListener several times to actually find out
   // when we are done.
   gFinishedRunningURL = 0;
   gSubfolder.updateFolderWithListener(null, urlListener);
-  dl('wait for OnStopRunningURL');
+  dl("wait for OnStopRunningURL");
   do_timeout(100, checkResult);
   yield false;
 
   // kill some time
   do_timeout(200, async_driver);
   yield false;
 
   // test
   listMessages(gSubfolder);
   listMessages(localAccountUtils.inboxFolder);
   Assert.equal(folderCount(gSubfolder), 1);
   Assert.equal(folderCount(localAccountUtils.inboxFolder), 1);
 }
 
-function* get2Messages()
-{
+function* get2Messages() {
   gPOP3Pump.files = ["../../../data/bugmail10",
                      "../../../data/draft1"];
-  gPOP3Pump.onDone = function() {dump('POP3Pump done\n');async_driver();};
+  gPOP3Pump.onDone = function() {
+    dump("POP3Pump done\n");
+    async_driver();
+  };
   gPOP3Pump.run();
-  dl('waiting for POP3Pump done');
+  dl("waiting for POP3Pump done");
   yield false;
 }
 
 function* updateSubfolderAndTest2() {
   // The previous function does an append, which may take a bit of time to
   // complete. Unfortunately updateFolderWithListener succeeds successfully
   // if there is a url running, but doesn't tell us that is the case. So we
   // have to run updateFolderWithListener several times to actually find out
   // when we are done.
   gFinishedRunningURL = 0;
   gSubfolder.updateFolderWithListener(null, urlListener);
-  dl('wait for OnStopRunningURL');
+  dl("wait for OnStopRunningURL");
   do_timeout(1000, checkResult);
   yield false;
 
   // kill some time
   do_timeout(1000, async_driver);
   yield false;
 
-  //test
+  // test
   listMessages(gSubfolder);
   listMessages(localAccountUtils.inboxFolder);
   Assert.equal(folderCount(gSubfolder), 3);
   Assert.equal(folderCount(localAccountUtils.inboxFolder), 3);
 }
 
-function endTest()
-{
+function endTest() {
   // Cleanup, null out everything, close all cached connections and stop the
   // server
   dl("Exiting mail tests");
   gPOP3Pump = null;
   teardownIMAPPump();
 }
 
 // listeners
 
-var mfnListener =
-{
-  folderAdded: function folderAdded(aFolder)
-  {
-    dl('folderAdded <' + aFolder.name + '>');
+var mfnListener = {
+  folderAdded(aFolder) {
+    dl("folderAdded <" + aFolder.name + ">");
     // we are only using async yield on the Subfolder add
     if (aFolder.name == "subfolder")
       async_driver();
   },
 
-  msgAdded: function msgAdded(aMsg)
-  {
-    dl('msgAdded to folder <' + aMsg.folder.name + '> subject <' + aMsg.subject + '>');
+  msgAdded(aMsg) {
+    dl("msgAdded to folder <" + aMsg.folder.name + "> subject <" + aMsg.subject + ">");
   },
 
 };
 
 var urlListener = {
-  OnStartRunningUrl: function _OnStartRunningUrl(aUrl) {
-    dl('OnStartRunningUrl');
+  OnStartRunningUrl(aUrl) {
+    dl("OnStartRunningUrl");
   },
-  OnStopRunningUrl: function _OnStopRunningUrl(aUrl, aExitCode) {
-    dl('OnStopRunningUrl');
+  OnStopRunningUrl(aUrl, aExitCode) {
+    dl("OnStopRunningUrl");
     gFinishedRunningURL = 1;
     checkResult();
-  }
+  },
 };
 
 // main test startup
 
-function run_test()
-{
+function run_test() {
   // quarantine messages
   Services.prefs.setBoolPref("mailnews.downloadToTempFile", true);
 
   // Add folder listeners that will capture async events
   const nsIMFNService = Ci.nsIMsgFolderNotificationService;
   let flags =
         nsIMFNService.folderAdded |
         nsIMFNService.msgAdded;
   MailServices.mfn.addListener(mfnListener, flags);
 
-  //start first test
+  // start first test
   async_run_tests(quarantineTests);
 }
 
 // helper functions
 
 // count of messages in a folder, using the database
-function folderCount(folder)
-{
+function folderCount(folder) {
   let enumerator = folder.msgDatabase.EnumerateMessages();
   let count = 0;
-  while (enumerator.hasMoreElements())
-  {
+  while (enumerator.hasMoreElements()) {
     count++;
-    let hdr = enumerator.getNext();
+    enumerator.getNext();
   }
   return count;
 }
 
 // display of message subjects in a folder
 function listMessages(folder) {
   let enumerator = folder.msgDatabase.EnumerateMessages();
   var msgCount = 0;
   dl("listing messages for " + folder.prettyName);
-  while(enumerator.hasMoreElements())
-  {
+  while (enumerator.hasMoreElements()) {
     msgCount++;
     let hdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
     dl(msgCount + ": " + hdr.subject);
   }
 }
 
 // shorthand output of a line of text
 function dl(text) {
-  dump(text + '\n');
+  dump(text + "\n");
 }
 
--- a/mailnews/imap/test/unit/test_lsub.js
+++ b/mailnews/imap/test/unit/test_lsub.js
@@ -3,16 +3,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Test that listing subscribed mailboxes uses LIST (SUBSCRIBED) instead of LSUB
 // for servers that have LIST-EXTENDED capability
 // see: bug 495318
 // see: RFC 5258 - http://tools.ietf.org/html/rfc5258
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/alertTestUtils.js");
 
 // IMAP pump
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
@@ -20,86 +23,62 @@ var {Services} = ChromeUtils.import("res
 
 
 setupIMAPPump();
 
 // Definition of tests
 var tests = [
   setupMailboxes,
   testLsub,
-  endTest
-]
+  endTest,
+];
 
 // setup the mailboxes that will be used for this test
-function* setupMailboxes()
-{
+function* setupMailboxes() {
   IMAPPump.mailbox.subscribed = true;
-  IMAPPump.daemon.createMailbox("folder1", {subscribed : true, flags : ["\\Noselect"]});
-  IMAPPump.daemon.createMailbox("folder1/folder11", {subscribed : true, flags : ["\\Noinferiors"]});
-  IMAPPump.daemon.createMailbox("folder2", {subscribed : true, nonExistent : true});
+  IMAPPump.daemon.createMailbox("folder1", {subscribed: true, flags: ["\\Noselect"]});
+  IMAPPump.daemon.createMailbox("folder1/folder11", {subscribed: true, flags: ["\\Noinferiors"]});
+  IMAPPump.daemon.createMailbox("folder2", {subscribed: true, nonExistent: true});
   IMAPPump.daemon.createMailbox("folder3", {});
 
   // select the inbox to force folder discovery, etc.
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
 // tests that LSUB returns the proper response
-function* testLsub()
-{
+function* testLsub() {
   // check that we have \Noselect and \Noinferiors flags - these would not have
   // been returned if we had used LSUB instead of LIST(SUBSCRIBED)
   let rootFolder = IMAPPump.incomingServer.rootFolder;
   let folder1 = rootFolder.getChildNamed("folder1");
   Assert.ok(folder1.getFlag(Ci.nsMsgFolderFlags.ImapNoselect));
   Assert.ok(!folder1.getFlag(Ci.nsMsgFolderFlags.ImapNoinferiors));
 
   // make sure the above test was not a fluke
   let folder11 = folder1.getChildNamed("folder11");
   Assert.ok(!folder11.getFlag(Ci.nsMsgFolderFlags.ImapNoselect));
   Assert.ok(folder11.getFlag(Ci.nsMsgFolderFlags.ImapNoinferiors));
 
   // test that \NonExistent implies \Noselect
-  let folder2 = rootFolder.getChildNamed("folder2");
+  rootFolder.getChildNamed("folder2");
   Assert.ok(folder1.getFlag(Ci.nsMsgFolderFlags.ImapNoselect));
 
   // should not get a folder3 since it is not subscribed
   let folder3;
   try {
     folder3 = rootFolder.getChildNamed("folder3");
   } catch (ex) {}
-  //do_check_false(folder1.getFlag(Ci.nsMsgFolderFlags.Subscribed));
+  // do_check_false(folder1.getFlag(Ci.nsMsgFolderFlags.Subscribed));
   Assert.equal(null, folder3);
 
   yield true;
 }
 
 // Cleanup at end
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
 
-function run_test()
-{
+function run_test() {
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
   async_run_tests(tests);
 }
-
-/*
- * helper functions
- */
-
-// given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
-  let file = do_get_file("../../../data/" + aFileName);
-  let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
-  return msgfileuri.spec;
-}
-
-function recursiveDeleteMailboxes(aMailbox)
-{
-  for (var child of aMailbox.allChildren) {
-    recursiveDeleteMailboxes(child);
-  }
-  IMAPPump.daemon.deleteMailbox(aMailbox);
-}
--- a/mailnews/imap/test/unit/test_mailboxes.js
+++ b/mailnews/imap/test/unit/test_mailboxes.js
@@ -1,28 +1,31 @@
 /**
  * Tests basic mailbox handling of IMAP, like discovery, rename and empty folder.
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 // The following folder names are not pure ASCII and will be MUTF-7 encoded.
 const folderName1 = "I18N box\u00E1"; // I18N boxá
 const folderName2 = "test \u00E4";    // test ä
 
 function* setup() {
   setupIMAPPump();
 
-  IMAPPump.daemon.createMailbox(folderName1, {subscribed : true});
+  IMAPPump.daemon.createMailbox(folderName1, {subscribed: true});
   IMAPPump.daemon.createMailbox("Unsubscribed box");
   // Create an all upper case trash folder name to make sure
   // we handle special folder names case-insensitively.
-  IMAPPump.daemon.createMailbox("TRASH", {subscribed : true});
+  IMAPPump.daemon.createMailbox("TRASH", {subscribed: true});
 
   // Get the server list...
   IMAPPump.server.performTest("LIST");
 
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
@@ -57,23 +60,22 @@ var tests = [
     let newChild = rootFolder.getChildNamed(folderName2).
                    QueryInterface(Ci.nsIMsgImapMailFolder);
     newChild.updateFolderWithListener(null, asyncUrlListener);
     yield false;
   },
   function checkEmptyFolder() {
     try {
     let serverSink = IMAPPump.server.QueryInterface(Ci.nsIImapServerSink);
-      serverSink.possibleImapMailbox("/", '/', 0);
-    }
-    catch (ex) {
+      serverSink.possibleImapMailbox("/", "/", 0);
+    } catch (ex) {
       // we expect this to fail, but not crash or assert.
     }
   },
-  teardown
+  teardown,
 ];
 
 function teardown() {
   teardownIMAPPump();
 }
 
 function run_test() {
   async_run_tests(tests);
--- a/mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
+++ b/mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
@@ -10,23 +10,24 @@
 * Test suite for nsIMsgFolderListener events due to IMAP operations
 *
 * Currently tested
 * - Adding new folders
 * - Copying messages from files to mailboxes
 * - Adding new messages directly to mailboxes
 */
 
+/* import-globals-from ../../../test/resources/msgFolderListenerSetup.js */
 load("../../../resources/msgFolderListenerSetup.js");
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 // Globals
 var gRootFolder;
-var gIMAPInbox, gIMAPFolder2, gIMAPFolder3, gIMAPTrashFolder;
+var gIMAPInbox, gIMAPFolder2, gIMAPFolder3;
 var gIMAPDaemon, gServer, gIMAPIncomingServer;
 var gMsgFile1 = do_get_file("../../../data/bugmail10");
 var gMsgFile2 = do_get_file("../../../data/bugmail11");
 var gMsgFile3 = do_get_file("../../../data/draft1");
 var gMsgFile4 = do_get_file("../../../data/bugmail7");
 var gMsgFile5 = do_get_file("../../../data/bugmail6");
 
 // Copied straight from the example files
@@ -34,30 +35,28 @@ var gMsgId1 = "200806061706.m56H6RWT0049
 var gMsgId2 = "200804111417.m3BEHTk4030129@mrapp51.mozilla.org";
 var gMsgId3 = "4849BF7B.2030800@example.com";
 var gMsgId4 = "bugmail7.m47LtAEf007542@mrapp51.mozilla.org";
 var gMsgId5 = "bugmail6.m47LtAEf007542@mrapp51.mozilla.org";
 var gMsgWindow = Cc["@mozilla.org/messenger/msgwindow;1"]
                   .createInstance(Ci.nsIMsgWindow);
 
 
-function addFolder(parent, folderName, storeIn)
-{
+function addFolder(parent, folderName, storeIn) {
   gExpectedEvents = [[MailServices.mfn.folderAdded, parent, folderName, storeIn]];
   // No copy listener notification for this
   gCurrStatus |= kStatus.onStopCopyDone;
   parent.createSubfolder(folderName, null);
   gCurrStatus |= kStatus.functionCallDone;
   gServer.performTest("LIST");
   if (gCurrStatus == kStatus.everythingDone)
     resetStatusAndProceed();
 }
 
-function copyFileMessage(file, messageId, destFolder)
-{
+function copyFileMessage(file, messageId, destFolder) {
   copyListener.mFolderStoredIn = destFolder;
 
   // This *needs* to be a draft (fourth parameter), as for non-UIDPLUS servers,
   // nsImapProtocol::UploadMessageFromFile is hardcoded not to send a copy
   // listener notification. The same function also asks for the message id from
   // the copy listener, without which it will *not* send the notification.
 
   // ...but wait, nsImapProtocol.cpp requires SEARCH afterwards to retrieve the
@@ -74,36 +73,33 @@ function copyFileMessage(file, messageId
   gServer.performTest("APPEND");
   // Allow some time for the append operation to complete, so update folder
   // every second
   gFolderBeingUpdated = destFolder;
   doUpdateFolder(gTest);
 }
 
 var gFolderBeingUpdated = null;
-function doUpdateFolder(test)
-{
+function doUpdateFolder(test) {
   // In case we've moved on to the next test, exit
   if (gTest > test)
     return;
 
   gFolderBeingUpdated.updateFolder(null);
 
   if (gCurrStatus == kStatus.everythingDone)
     resetStatusAndProceed();
   else
-    do_timeout(1000, function(){doUpdateFolder(test);});
+    do_timeout(1000, function() { doUpdateFolder(test); });
 }
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox, localFolder)
-{
+function addMessagesToServer(messages, mailbox, localFolder) {
   // For every message we have, we need to convert it to a file:/// URI
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     let URI = Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
     // Create the imapMessage and store it on the mailbox.
     mailbox.addMessage(new imapMessage(URI.spec, mailbox.uidnext++, []));
     // We can't get the headers again, so just pass on the message id
     gExpectedEvents.push([MailServices.mfn.msgAdded, {expectedMessageId: message.messageId}]);
   });
   gExpectedEvents.push([MailServices.mfn.msgsClassified,
                         messages.map(hdr => hdr.messageId),
@@ -111,28 +107,25 @@ function addMessagesToServer(messages, m
 
   // No copy listener notification for this
   gCurrStatus |= kStatus.functionCallDone | kStatus.onStopCopyDone;
 
   gFolderBeingUpdated = localFolder;
   doUpdateFolder(gTest);
 }
 
-function copyMessages(messages, isMove, srcFolder, destFolder)
-{
+function copyMessages(messages, isMove, srcFolder, destFolder) {
   let array = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     array.appendElement(message);
   });
   gExpectedEvents = [[MailServices.mfn.msgsMoveCopyCompleted, isMove, messages, destFolder, true]];
   // We'll also get the msgAdded events when we go and update the destination
   // folder
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     // We can't use the headers directly, because the notifications we'll
     // receive are for message headers in the destination folder
     gExpectedEvents.push([MailServices.mfn.msgKeyChanged,
                           {expectedMessageId: message.messageId}]);
     gExpectedEvents.push([MailServices.mfn.msgAdded,
                           {expectedMessageId: message.messageId}]);
   });
   gExpectedEvents.push([MailServices.mfn.msgsClassified,
@@ -144,59 +137,59 @@ function copyMessages(messages, isMove, 
   gServer.performTest("COPY");
 
   gFolderBeingUpdated = destFolder;
   doUpdateFolder(gTest);
   if (gCurrStatus == kStatus.everythingDone)
     resetStatusAndProceed();
 }
 
-var gTestArray =
-[
+var gTestArray = [
   // Adding folders
   // Create another folder to move and copy messages around, and force initialization.
   function testAddFolder1() {
     addFolder(gRootFolder, "folder2", function(folder) { gIMAPFolder2 = folder; });
    },
   function testAddFolder2() {
     addFolder(gRootFolder, "folder3", function(folder) { gIMAPFolder3 = folder; });
   },
 
   // Adding messages to folders
-  function testCopyFileMessage1()
-  {
+  function testCopyFileMessage1() {
     // Make sure the offline flag is not set for any of the folders
-    [gIMAPInbox, gIMAPFolder2, gIMAPFolder3].forEach(function (folder)
-    {
+    [gIMAPInbox, gIMAPFolder2, gIMAPFolder3].forEach(function(folder) {
       folder.clearFlag(Ci.nsMsgFolderFlags.Offline);
     });
-    copyFileMessage(gMsgFile1, gMsgId1, gIMAPInbox)
+    copyFileMessage(gMsgFile1, gMsgId1, gIMAPInbox);
   },
-  function testCopyFileMessage2() { copyFileMessage(gMsgFile2, gMsgId2, gIMAPInbox) },
+  function testCopyFileMessage2() {
+    copyFileMessage(gMsgFile2, gMsgId2, gIMAPInbox);
+  },
 
   // Add message straight to the server, so that we get a message added
   // notification on the next folder update
   function testNewMessageArrival1() {
     addMessagesToServer([{file: gMsgFile3, messageId: gMsgId3}],
-                        gIMAPDaemon.getMailbox("INBOX"), gIMAPInbox)
+                        gIMAPDaemon.getMailbox("INBOX"), gIMAPInbox);
   },
 
   // Add another couple of messages, this time to another folder on the server
   function testNewMessageArrival2() {
     addMessagesToServer([{file: gMsgFile4, messageId: gMsgId4},
                          {file: gMsgFile5, messageId: gMsgId5}],
                         gIMAPDaemon.getMailbox("INBOX"), gIMAPInbox);
   },
 
   // Moving/copying messages (this doesn't work right now)
-  function testCopyMessages1() { copyMessages([gMsgHdrs[0].hdr, gMsgHdrs[1].hdr], false, gIMAPInbox, gIMAPFolder3) }
+  function testCopyMessages1() {
+    copyMessages([gMsgHdrs[0].hdr, gMsgHdrs[1].hdr], false, gIMAPInbox, gIMAPFolder3);
+  },
 ];
 
-function run_test()
-{
+function run_test() {
   // This is before any of the actual tests, so...
   gTest = 0;
 
   gIMAPDaemon = new imapDaemon();
   gServer = makeServer(gIMAPDaemon, "");
 
   gIMAPIncomingServer = createLocalIMAPServer(gServer.port);
 
@@ -233,59 +226,53 @@ function run_test()
 
   // Get the server list...
   gIMAPIncomingServer.performExpand(null);
 
   // We get these notifications on initial discovery
   gRootFolder = gIMAPIncomingServer.rootFolder;
   gIMAPInbox = gRootFolder.getChildNamed("Inbox");
   gExpectedEvents = [[MailServices.mfn.folderAdded, gRootFolder, "Trash",
-                      function(folder) { gIMAPTrashFolder = folder; } ]];
+                      function(folder) {}]];
   gCurrStatus |= kStatus.onStopCopyDone | kStatus.functionCallDone;
 
   gServer.performTest("SUBSCRIBE");
 
   // "Master" do_test_pending(), paired with a do_test_finished() at the end of
   // all the operations.
   do_test_pending();
 }
 
-function doTest(test)
-{
+function doTest(test) { // eslint-disable-line no-unused-vars
   dump("Doing test " + test + "\n");
-  if (test <= gTestArray.length)
-  {
-    let testFn = gTestArray[test-1];
+  if (test <= gTestArray.length) {
+    let testFn = gTestArray[test - 1];
 
     // Set a limit of ten seconds; if the notifications haven't arrived by then there's a problem.
-    do_timeout(10000, function(){
+    do_timeout(10000, function() {
         if (gTest == test)
           do_throw("Notifications not received in 10000 ms for operation " + testFn.name +
             ", current status is " + gCurrStatus);
         }
       );
     testFn();
-  }
-  else
-  {
+  } else {
     MailServices.mfn.removeListener(gMFListener);
     // Cleanup, null out everything, close all cached connections and stop the
     // server
     gRootFolder = null;
     gIMAPInbox.msgDatabase = null;
     gIMAPInbox = null;
     gIMAPFolder2 = null;
     gIMAPFolder3 = null;
-    gIMAPTrashFolder = null;
     do_timeout(1000, endTest);
   }
 }
 
-function endTest()
-{
+function endTest() {
   gIMAPIncomingServer.closeCachedConnections();
   gServer.performTest();
   gServer.stop();
   let thread = gThreadManager.currentThread;
   while (thread.hasPendingEvents())
     thread.processNextEvent(true);
 
   do_test_finished(); // for the one in run_test()
--- a/mailnews/imap/test/unit/test_offlineCopy.js
+++ b/mailnews/imap/test/unit/test_offlineCopy.js
@@ -6,38 +6,36 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /**
  * This test checks pseudo-offline message copies (which is triggered
  * by allowUndo == true in CopyMessages).
  */
 
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 var {PromiseTestUtils} = ChromeUtils.import("resource://testing-common/mailnews/PromiseTestUtils.jsm");
 
+/* import-globals-from ../../../test/resources/logHelper.js */
 load("../../../resources/logHelper.js");
 
 var gMsgFile1 = do_get_file("../../../data/bugmail10");
 var gMsgId1 = "200806061706.m56H6RWT004933@mrapp54.mozilla.org";
 var gMsgFile2 = do_get_file("../../../data/image-attach-test");
 var gMsgId2 = "4A947F73.5030709@example.com";
 var gMsgFile3 = do_get_file("../../../data/SpamAssassinYes");
 var gMsg3Id = "bugmail7.m47LtAEf007543@mrapp51.mozilla.org";
 var gMsgFile4 = do_get_file("../../../data/bug460636");
 var gMsg4Id = "foo.12345@example";
 
 var gFolder1;
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox)
-{
+function addMessagesToServer(messages, mailbox) {
   // For every message we have, we need to convert it to a file:/// URI
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     let URI = Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
     // Create the imapMessage and store it on the mailbox.
     mailbox.addMessage(new imapMessage(URI.spec, mailbox.uidnext++, []));
   });
 }
 
 var tests = [
   async function setup() {
@@ -56,17 +54,17 @@ var tests = [
 
     gFolder1 = IMAPPump.incomingServer.rootFolder.getChildNamed("folder 1");
     Assert.ok(gFolder1 instanceof Ci.nsIMsgFolder);
 
     // these hacks are required because we've created the inbox before
     // running initial folder discovery, and adding the folder bails
     // out before we set it as verified online, so we bail out, and
     // then remove the INBOX folder since it's not verified.
-    IMAPPump.inbox.hierarchyDelimiter = '/';
+    IMAPPump.inbox.hierarchyDelimiter = "/";
     IMAPPump.inbox.verifiedAsOnlineFolder = true;
 
     // Add messages to the INBOX
     // this is synchronous, afaik
     addMessagesToServer([{file: gMsgFile1, messageId: gMsgId1},
                          {file: gMsgFile2, messageId: gMsgId2},
                         ],
                         IMAPPump.daemon.getMailbox("INBOX"));
@@ -96,26 +94,25 @@ var tests = [
     IMAPPump.inbox.updateFolderWithListener(null, promiseUrlListener);
     await promiseUrlListener.promise;
 
     let db = IMAPPump.inbox.msgDatabase;
 
     // test the headers in the inbox
     let enumerator = db.EnumerateMessages();
     let count = 0;
-    while (enumerator.hasMoreElements())
-    {
+    while (enumerator.hasMoreElements()) {
       count++;
       var message = enumerator.getNext();
       message instanceof Ci.nsIMsgDBHdr;
-      dump('message <'+ message.subject +
-           '> storeToken: <' + message.getStringProperty("storeToken") +
-           '> offset: <' + message.messageOffset +
-           '> id: <' + message.messageId +
-           '>\n');
+      dump("message <" + message.subject +
+           "> storeToken: <" + message.getStringProperty("storeToken") +
+           "> offset: <" + message.messageOffset +
+           "> id: <" + message.messageId +
+           ">\n");
       // This fails for file copies in bug 790912. Without  this, messages that
       //  are copied are not visible in pre-pluggableStores versions of TB (pre TB 12)
       if (IMAPPump.inbox.msgStore.storeType == "mbox")
         Assert.equal(message.messageOffset, parseInt(message.getStringProperty("storeToken")));
     }
     Assert.equal(count, 4);
   },
   function copyMessagesToSubfolder() {
@@ -146,44 +143,42 @@ var tests = [
     messages.appendElement(msg4);
     MailServices.copy.CopyMessages(IMAPPump.inbox, messages, gFolder1, false,
                                    null, null, true);
 
     // test the db headers in folder1
     db = gFolder1.msgDatabase;
     let enumerator = db.EnumerateMessages();
     let count = 0;
-    while (enumerator.hasMoreElements())
-    {
+    while (enumerator.hasMoreElements()) {
       count++;
       var message = enumerator.getNext();
       message instanceof Ci.nsIMsgDBHdr;
-      dump('message <'+ message.subject +
-           '> storeToken: <' + message.getStringProperty("storeToken") +
-           '> offset: <' + message.messageOffset +
-           '> id: <' + message.messageId +
-           '>\n');
+      dump("message <" + message.subject +
+           "> storeToken: <" + message.getStringProperty("storeToken") +
+           "> offset: <" + message.messageOffset +
+           "> id: <" + message.messageId +
+           ">\n");
       if (gFolder1.msgStore.storeType == "mbox")
         Assert.equal(message.messageOffset, parseInt(message.getStringProperty("storeToken")));
     }
     Assert.equal(count, 3);
   },
   async function test_headers() {
     let msgIds = [gMsgId1, gMsg3Id, gMsg4Id];
-    for (let msgId of msgIds)
-    {
-      let newMsgHdr= gFolder1.msgDatabase.getMsgHdrForMessageID(msgId);
+    for (let msgId of msgIds) {
+      let newMsgHdr = gFolder1.msgDatabase.getMsgHdrForMessageID(msgId);
       Assert.ok(newMsgHdr.flags & Ci.nsMsgMessageFlags.Offline);
       let msgURI = newMsgHdr.folder.getUriForMsg(newMsgHdr);
       let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
       let msgServ = messenger.messageServiceFromURI(msgURI);
       let promiseStreamListener = new PromiseTestUtils.PromiseStreamListener();
       msgServ.streamHeaders(msgURI, promiseStreamListener, null, true);
       let data = await promiseStreamListener.promise;
-      dump('\nheaders for messageId ' + msgId + '\n' + data + '\n\n');
+      dump("\nheaders for messageId " + msgId + "\n" + data + "\n\n");
       Assert.ok(data.includes(msgId));
     }
   },
   function moveMessagesToSubfolder() {
     let db = IMAPPump.inbox.msgDatabase;
     let enumerator = db.EnumerateMessages();
     Assert.ok(enumerator.hasMoreElements());
     let messages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
@@ -193,26 +188,25 @@ var tests = [
     MailServices.copy.CopyMessages(IMAPPump.inbox, messages, gFolder1, true,
                                    null, null, true);
 
     // the inbox should now be empty
     enumerator = db.EnumerateMessages();
     Assert.ok(!enumerator.hasMoreElements());
 
     // maildir should also delete the files.
-    if (IMAPPump.inbox.msgStore.storeType == "maildir")
-    {
+    if (IMAPPump.inbox.msgStore.storeType == "maildir") {
       let curDir = IMAPPump.inbox.filePath.clone();
       curDir.append("cur");
       Assert.ok(curDir.exists());
       Assert.ok(curDir.isDirectory());
       let curEnum = curDir.directoryEntries;
       // the directory should be empty, fails from bug 771643
-      Assert.ok(!curEnum.hasMoreElements())
+      Assert.ok(!curEnum.hasMoreElements());
     }
   },
-  teardownIMAPPump
+  teardownIMAPPump,
 ];
 
 function run_test() {
   tests.forEach(x => add_task(x));
   run_next_test();
 }
--- a/mailnews/imap/test/unit/test_offlineDraftDataloss.js
+++ b/mailnews/imap/test/unit/test_offlineDraftDataloss.js
@@ -4,16 +4,18 @@
 
 /**
  * This file tests that a message saved as draft in an IMAP folder in offline
  * mode is not lost when going back online
  * See Bug 805626
  */
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 // IMAP pump
 
@@ -22,49 +24,46 @@ setupIMAPPump();
 // Definition of tests
 
 var tests = [
   createDraftsFolder,
   goOffline,
   saveDraft,
   goOnline,
   checkResult,
-  endTest
+  endTest,
 ];
 
 var gDraftsFolder;
 
-function* createDraftsFolder()
-{
+function* createDraftsFolder() {
   IMAPPump.incomingServer.rootFolder.createSubfolder("Drafts", null);
   yield false;
   gDraftsFolder = IMAPPump.incomingServer.rootFolder.getChildNamed("Drafts");
   Assert.ok(gDraftsFolder instanceof Ci.nsIMsgImapMailFolder);
   gDraftsFolder.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
-function* goOffline()
-{
+function* goOffline() {
   // Don't prompt about offline download when going offline
   Services.prefs.setIntPref("offline.download.download_messages", 2);
 
   IMAPPump.incomingServer.closeCachedConnections();
   let thread = gThreadManager.currentThread;
   while (thread.hasPendingEvents())
     thread.processNextEvent(true);
 
   do_timeout(2000, async_driver);
   yield false;
 
   IMAPPump.server.stop();
   Services.io.offline = true;
 }
 
-function* saveDraft()
-{
+function* saveDraft() {
   let msgCompose = Cc["@mozilla.org/messengercompose/compose;1"]
                      .createInstance(Ci.nsIMsgCompose);
   let fields = Cc["@mozilla.org/messengercompose/composefields;1"]
                  .createInstance(Ci.nsIMsgCompFields);
   let params = Cc["@mozilla.org/messengercompose/composeparams;1"]
                  .createInstance(Ci.nsIMsgComposeParams);
   params.composeFields = fields;
   msgCompose.initialize(params);
@@ -78,108 +77,98 @@ function* saveDraft()
   progress.registerListener(progressListener);
   msgCompose.SendMsg(Ci.nsIMsgSend.nsMsgSaveAsDraft, identity, "", null,
                      progress);
   yield false;
   // verify that message is not on the server yet
   Assert.equal(IMAPPump.daemon.getMailbox("Drafts")._messages.length, 0);
 }
 
-function* goOnline()
-{
+function* goOnline() {
   let offlineManager = Cc["@mozilla.org/messenger/offline-manager;1"]
                        .getService(Ci.nsIMsgOfflineManager);
   IMAPPump.daemon.closing = false;
   Services.io.offline = false;
 
   IMAPPump.server.start();
   offlineManager.inProgress = true;
   offlineManager.goOnline(false, true, null);
-  let waitForNotInProgress = function () {
+  let waitForNotInProgress = function() {
     if (offlineManager.inProgress)
       do_timeout(250, waitForNotInProgress);
     else
       async_driver();
-  }
+  };
   waitForNotInProgress();
   yield false;
 }
 
-function* checkResult()
-{
+function* checkResult() {
   // verify that message is now on the server
   Assert.equal(IMAPPump.daemon.getMailbox("Drafts")._messages.length, 1);
   yield true;
 }
 
-function* endTest()
-{
+function* endTest() {
   teardownIMAPPump();
   yield true;
 }
 
-function run_test()
-{
+function run_test() {
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
-  let server = IMAPPump.incomingServer;
 
   // Add folder listeners that will capture async events
   const nsIMFNService = Ci.nsIMsgFolderNotificationService;
 
   let flags =
         nsIMFNService.msgsMoveCopyCompleted |
         nsIMFNService.folderAdded |
         nsIMFNService.msgAdded;
   MailServices.mfn.addListener(mfnListener, flags);
 
-  //start first test
+  // start first test
   async_run_tests(tests);
 }
 
-var mfnListener =
-{
-  msgsMoveCopyCompleted: function (aMove, aSrcMsgs, aDestFolder, aDestMsgs)
-  {
-    dl('msgsMoveCopyCompleted to folder ' + aDestFolder.name);
+var mfnListener = {
+  msgsMoveCopyCompleted(aMove, aSrcMsgs, aDestFolder, aDestMsgs) {
+    dl("msgsMoveCopyCompleted to folder " + aDestFolder.name);
   },
 
-  folderAdded: function (aFolder)
-  {
-    dl('folderAdded <' + aFolder.name + '>');
+  folderAdded(aFolder) {
+    dl("folderAdded <" + aFolder.name + ">");
     // we are only using async add on the Junk folder
     if (aFolder.name == "Drafts")
       async_driver();
   },
 
-  msgAdded: function msgAdded(aMsg)
-  {
-    dl('msgAdded with subject <' + aMsg.subject + '>');
-  }
+  msgAdded(aMsg) {
+    dl("msgAdded with subject <" + aMsg.subject + ">");
+  },
 };
 
 var progressListener = {
-  onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
-    if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP){
-      dl('onStateChange');
+  onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
+    if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
+      dl("onStateChange");
       async_driver();
     }
   },
 
-  onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress,
-                             aMaxSelfProgress, aCurTotalProgress,
-                             aMaxTotalProgress) {},
-  onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) {},
-  onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) {},
-  onSecurityChange: function(aWebProgress, aRequest, state) {},
-  onContentBlockingEvent: function(aWebProgress, aRequest, aEvent) {},
+  onProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress,
+                   aCurTotalProgress, aMaxTotalProgress) {},
+  onLocationChange(aWebProgress, aRequest, aLocation, aFlags) {},
+  onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {},
+  onSecurityChange(aWebProgress, aRequest, state) {},
+  onContentBlockingEvent(aWebProgress, aRequest, aEvent) {},
 
   QueryInterface: ChromeUtils.generateQI(["nsIWebProgressListener",
                                           "nsISupportsWeakReference"]),
 };
 
 /*
  * helper functions
  */
 
 // quick shorthand for output of a line of text.
 function dl(text) {
-  dump(text + '\n');
+  dump(text + "\n");
 }
--- a/mailnews/imap/test/unit/test_offlinePlayback.js
+++ b/mailnews/imap/test/unit/test_offlinePlayback.js
@@ -2,16 +2,17 @@
 /*
  * Test to ensure that changes made while offline are played back when we
  * go back online.
  */
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 var {PromiseTestUtils} = ChromeUtils.import("resource://testing-common/mailnews/PromiseTestUtils.jsm");
 
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/messageGenerator.js");
 
 var gSecondFolder, gThirdFolder;
 var gSynthMessage1, gSynthMessage2;
 // the message id of bugmail10
 var gMsgId1 = "200806061706.m56H6RWT004933@mrapp54.mozilla.org";
 var gOfflineManager;
 
@@ -21,19 +22,19 @@ var tests = [
     var {fsDebugAll} = ChromeUtils.import("resource://testing-common/mailnews/maild.js");
     IMAPPump.server.setDebugLevel(fsDebugAll);
   },
   setup,
 
   function prepareToGoOffline() {
     let rootFolder = IMAPPump.incomingServer.rootFolder;
     gSecondFolder = rootFolder.getChildNamed("secondFolder")
-                      .QueryInterface(Ci.nsIMsgImapMailFolder);
-    gThirdFolder =  rootFolder.getChildNamed("thirdFolder")
-                      .QueryInterface(Ci.nsIMsgImapMailFolder);
+                              .QueryInterface(Ci.nsIMsgImapMailFolder);
+    gThirdFolder = rootFolder.getChildNamed("thirdFolder")
+                             .QueryInterface(Ci.nsIMsgImapMailFolder);
     IMAPPump.incomingServer.closeCachedConnections();
   },
   async function doOfflineOps() {
     IMAPPump.server.stop();
     Services.io.offline = true;
 
     // Flag the two messages, and then copy them to different folders. Since
     // we're offline, these operations are synchronous.
@@ -89,42 +90,41 @@ var tests = [
   function checkDone() {
     let msgHdr1 = gSecondFolder.msgDatabase.getMsgHdrForMessageID(gSynthMessage1.messageId);
     let msgHdr2 = gThirdFolder.msgDatabase.getMsgHdrForMessageID(gSynthMessage2.messageId);
     let msgHdr3 = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
     Assert.notEqual(msgHdr1, null);
     Assert.notEqual(msgHdr2, null);
     Assert.notEqual(msgHdr3, null);
   },
-  teardownIMAPPump
+  teardownIMAPPump,
 ];
 
 async function setup() {
-
   /*
    * Set up an IMAP server.
    */
-  IMAPPump.daemon.createMailbox("secondFolder", {subscribed : true});
-  IMAPPump.daemon.createMailbox("thirdFolder", {subscribed : true});
+  IMAPPump.daemon.createMailbox("secondFolder", {subscribed: true});
+  IMAPPump.daemon.createMailbox("thirdFolder", {subscribed: true});
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
   // Don't prompt about offline download when going offline
   Services.prefs.setIntPref("offline.download.download_messages", 2);
 
   // make a couple of messages
   let messages = [];
   let gMessageGenerator = new MessageGenerator();
   messages = messages.concat(gMessageGenerator.makeMessage());
   messages = messages.concat(gMessageGenerator.makeMessage());
   gSynthMessage1 = messages[0];
   gSynthMessage2 = messages[1];
 
   let msgURI =
     Services.io.newURI("data:text/plain;base64," +
                        btoa(messages[0].toMessageString()));
-  let imapInbox =  IMAPPump.daemon.getMailbox("INBOX")
+  let imapInbox = IMAPPump.daemon.getMailbox("INBOX");
   let message = new imapMessage(msgURI.spec, imapInbox.uidnext++, ["\\Seen"]);
   imapInbox.addMessage(message);
   msgURI =
     Services.io.newURI("data:text/plain;base64," +
                        btoa(messages[1].toMessageString()));
   message = new imapMessage(msgURI.spec, imapInbox.uidnext++, ["\\Seen"]);
   imapInbox.addMessage(message);
 
--- a/mailnews/imap/test/unit/test_offlineStoreLocking.js
+++ b/mailnews/imap/test/unit/test_offlineStoreLocking.js
@@ -1,68 +1,47 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Test to ensure that code that writes to the imap offline store deals
  * with offline store locking correctly.
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 load("../../../resources/alertTestUtils.js");
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-
 
 // Globals
 var gIMAPTrashFolder, gMsgImapInboxFolder;
 var gGotAlert = false;
 var gMovedMsgId;
 
+/* exported alert */// to alertTestUtils.js
 function alert(aDialogTitle, aText) {
 //  do_check_true(aText.startsWith("Connection to server Mail for  timed out."));
   gGotAlert = true;
 }
 
-function addGeneratedMessagesToServer(messages, mailbox)
-{
+function addGeneratedMessagesToServer(messages, mailbox) {
   // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
-  {
+  messages.forEach(function(message) {
     let dataUri = Services.io.newURI("data:text/plain;base64," +
                                      btoa(message.toMessageString()));
     mailbox.addMessage(new imapMessage(dataUri.spec, mailbox.uidnext++, []));
   });
 }
 
 var gStreamedHdr = null;
 
-function checkOfflineStore(prevOfflineStoreSize) {
-  dump("checking offline store\n");
-  let offset = new Object;
-  let size = new Object;
-  let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
-  if (enumerator)
-  {
-    while (enumerator.hasMoreElements())
-    {
-      let header = enumerator.getNext();
-      // this will verify that the message in the offline store
-      // starts with "From " - otherwise, it returns an error.
-      if (header instanceof Ci.nsIMsgDBHdr &&
-         (header.flags & Ci.nsMsgMessageFlags.Offline))
-        IMAPPump.inbox.getOfflineFileStream(header.messageKey, offset, size).close();
-    }
-  }
-  // check that the offline store shrunk by at least 100 bytes.
-  // (exact calculation might be fragile).
-  Assert.ok(prevOfflineStoreSize > IMAPPump.inbox.filePath.fileSize + 100);
-}
-
 var tests = [
   setup,
   function* downloadForOffline() {
     // ...and download for offline use.
     dump("Downloading for offline use\n");
     IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
     yield false;
   },
@@ -125,93 +104,91 @@ var tests = [
   },
   function testOfflineBodyCopy() {
     // In order to check that offline copy of messages doesn't try to copy
     // the body if the offline store is locked, we're going to go offline.
     // Thunderbird itself does move/copies pseudo-offline, but that's too
     // hard to test because of the half-second delay.
     IMAPPump.server.stop();
     Services.io.offline = true;
-    let trashHdr;
     let enumerator = gIMAPTrashFolder.msgDatabase.EnumerateMessages();
     let msgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
     gMovedMsgId = msgHdr.messageId;
     let array = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
     array.appendElement(msgHdr);
     IMAPPump.inbox.compact(asyncUrlListener, gDummyMsgWindow);
     MailServices.copy.CopyMessages(gIMAPTrashFolder, array, IMAPPump.inbox, true,
                                    CopyListener, null, true);
   },
   function* verifyNoOfflineMsg() {
     try {
-    let movedMsg = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMovedMsgId);
-    Assert.equal(false, movedMsg.flags & Ci.nsMsgMessageFlags.Offline);
-    } catch (ex) {dump(ex);}
+      let movedMsg = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMovedMsgId);
+      Assert.equal(false, movedMsg.flags & Ci.nsMsgMessageFlags.Offline);
+    } catch (ex) {
+      dump(ex);
+    }
     yield false;
     yield false;
   },
-  teardown
+  teardown,
 ];
 
 function run_test() {
   async_run_tests(tests);
 }
 
 function setup() {
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
 
   setupIMAPPump();
 
   gMsgImapInboxFolder = IMAPPump.inbox.QueryInterface(Ci.nsIMsgImapMailFolder);
   // these hacks are required because we've created the inbox before
   // running initial folder discovery, and adding the folder bails
   // out before we set it as verified online, so we bail out, and
   // then remove the INBOX folder since it's not verified.
-  gMsgImapInboxFolder.hierarchyDelimiter = '/';
+  gMsgImapInboxFolder.hierarchyDelimiter = "/";
   gMsgImapInboxFolder.verifiedAsOnlineFolder = true;
 
   let messageGenerator = new MessageGenerator();
   let messages = [];
   let bodyString = "";
   for (let i = 0; i < 100; i++)
     bodyString += "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n";
 
   for (let i = 0; i < 50; i++)
     messages = messages.concat(messageGenerator.makeMessage({body: {body: bodyString, contentType: "text/plain"}}));
 
   addGeneratedMessagesToServer(messages, IMAPPump.daemon.getMailbox("INBOX"));
 }
 
 // nsIMsgCopyServiceListener implementation - runs next test when copy
 // is completed.
-var CopyListener =
-{
-  OnStartCopy: function() {},
-  OnProgress: function(aProgress, aProgressMax) {},
-  SetMessageKey: function(aKey)
-  {
-    let hdr = localAccountUtils.inboxFolder.GetMessageHeader(aKey);
-    gMsgHdrs.push({hdr: hdr, ID: hdr.messageId});
-  },
-  SetMessageId: function(aMessageId) {},
-  OnStopCopy: function(aStatus)
-  {
+var CopyListener = {
+  OnStartCopy() {},
+  OnProgress(aProgress, aProgressMax) {},
+  SetMessageKey(aKey) {},
+  SetMessageId(aMessageId) {},
+  OnStopCopy(aStatus) {
     // Check: message successfully copied.
     Assert.equal(aStatus, 0);
     async_driver();
-  }
+  },
 };
 
 function teardown() {
+  Assert.ok(gGotAlert);
   gMsgImapInboxFolder = null;
   gIMAPTrashFolder = null;
 
   // IMAPPump.server has already stopped, we do not need to IMAPPump.server.stop().
   IMAPPump.inbox = null;
   try {
     IMAPPump.incomingServer.closeCachedConnections();
     let serverSink = IMAPPump.incomingServer.QueryInterface(Ci.nsIImapServerSink);
     serverSink.abortQueuedUrls();
-  } catch (ex) {dump(ex);}
+  } catch (ex) {
+    dump(ex);
+  }
   let thread = gThreadManager.currentThread;
   while (thread.hasPendingEvents())
     thread.processNextEvent(true);
 }
--- a/mailnews/imap/test/unit/test_partsOnDemand.js
+++ b/mailnews/imap/test/unit/test_partsOnDemand.js
@@ -4,16 +4,19 @@
 
 /*
  * Tests that you can stream a message without the attachments. Tests the
  * MsgHdrToMimeMessage API that exposes this.
  */
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 Services.prefs.setIntPref("mail.imap.mime_parts_on_demand_threshold", 1000);
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 // javascript mime emitter functions
 var mimeMsg = {};
 ChromeUtils.import("resource:///modules/gloda/mimemsg.js", mimeMsg);
 
@@ -25,36 +28,33 @@ setupIMAPPump();
 
 var tests = [
   setPrefs,
   loadImapMessage,
   startMime,
   testAllInlineMessage,
   updateCounts,
   testNotRead,
-  endTest
-]
+  endTest,
+];
 
 // make sure we are in the optimal conditions!
 function* setPrefs() {
   Services.prefs.setIntPref("mail.imap.mime_parts_on_demand_threshold", 20);
   Services.prefs.setBoolPref("mail.imap.mime_parts_on_demand", true);
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
   Services.prefs.setBoolPref("mail.server.server1.offline_download", false);
   Services.prefs.setBoolPref("mail.server.server1.download_on_biff", false);
   Services.prefs.setIntPref("browser.cache.disk.capacity", 0);
 
   yield true;
 }
 
 // load and update a message in the imap fake server
-function* loadImapMessage()
-{
-  let gMessageGenerator = new MessageGenerator();
-
+function* loadImapMessage() {
   let file = do_get_file("../../../data/bodystructuretest1");
   let msgURI = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
 
   let imapInbox = IMAPPump.daemon.getMailbox("INBOX");
   let message = new imapMessage(msgURI.spec, imapInbox.uidnext++, []);
   IMAPPump.mailbox.addMessage(message);
   // add a second message with no external parts. We want to make
   // sure that streaming this message doesn't mark it read, even
@@ -68,65 +68,58 @@ function* loadImapMessage()
 
   Assert.equal(2, IMAPPump.inbox.getTotalMessages(false));
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   Assert.ok(msgHdr instanceof Ci.nsIMsgDBHdr);
   yield true;
 }
 
 // process the message through mime
-function* startMime()
-{
+function* startMime() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
 
-  mimeMsg.MsgHdrToMimeMessage(msgHdr, this, function (aMsgHdr, aMimeMessage) {
+  mimeMsg.MsgHdrToMimeMessage(msgHdr, this, function(aMsgHdr, aMimeMessage) {
     let url = aMimeMessage.allUserAttachments[0].url;
     // A URL containing this string indicates that the attachment will be
     // downloaded on demand.
     Assert.ok(url.includes("/;section="));
     async_driver();
   }, true /* allowDownload */, { partsOnDemand: true, examineEncryptedParts: true });
   yield false;
 }
 
 // test that we don't mark all inline messages as read.
-function* testAllInlineMessage()
-{
+function* testAllInlineMessage() {
   let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
 
-  if (enumerator.hasMoreElements())
-  {
+  if (enumerator.hasMoreElements()) {
     gSecondMsg = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
-    mimeMsg.MsgHdrToMimeMessage(gSecondMsg, this, function (aMsgHdr, aMimeMessage) {
+    mimeMsg.MsgHdrToMimeMessage(gSecondMsg, this, function(aMsgHdr, aMimeMessage) {
       async_driver();
     }, true /* allowDownload */, { partsOnDemand: true });
     yield false;
   }
 }
 
-function* updateCounts()
-{
+function* updateCounts() {
   // select the trash, then the inbox again, to force an update of the
   // read state of messages.
   let trash = IMAPPump.incomingServer.rootFolder.getChildNamed("Trash");
   Assert.ok(trash instanceof Ci.nsIMsgImapMailFolder);
   trash.updateFolderWithListener(null, asyncUrlListener);
   yield false;
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
-function* testNotRead()
-{
+function* testNotRead() {
   Assert.equal(2, IMAPPump.inbox.getNumUnread(false));
   yield true;
 }
 
 // Cleanup
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
 
-function run_test()
-{
+function run_test() {
   async_run_tests(tests);
 }
--- a/mailnews/imap/test/unit/test_preserveDataOnMove.js
+++ b/mailnews/imap/test/unit/test_preserveDataOnMove.js
@@ -1,16 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This tests that arbitrary message header properties are preserved
 //  during online move of an imap message.
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 // IMAP pump
 
 // Globals
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
@@ -19,52 +21,49 @@ var gMessage = "bugmail10"; // message f
 setupIMAPPump();
 
 // Definition of tests
 var tests = [
   createSubfolder,
   loadImapMessage,
   moveMessageToSubfolder,
   testPropertyOnMove,
-  endTest
-]
+  endTest,
+];
 
 var gSubfolder;
-function* createSubfolder()
-{
+function* createSubfolder() {
   IMAPPump.incomingServer.rootFolder.createSubfolder("Subfolder", null);
-  dl('wait for folderAdded notification');
+  dl("wait for folderAdded notification");
   yield false;
   gSubfolder = IMAPPump.incomingServer.rootFolder.getChildNamed("Subfolder");
   Assert.ok(gSubfolder instanceof Ci.nsIMsgImapMailFolder);
   gSubfolder.updateFolderWithListener(null, asyncUrlListener);
-  dl('wait for OnStopRunningURL');
+  dl("wait for OnStopRunningURL");
   yield false;
 }
 
 // load and update a message in the imap fake server
-function* loadImapMessage()
-{
+function* loadImapMessage() {
   IMAPPump.mailbox.addMessage(new imapMessage(specForFileName(gMessage),
                           IMAPPump.mailbox.uidnext++, []));
   IMAPPump.inbox.updateFolder(null);
-  dl('wait for msgAdded notification');
+  dl("wait for msgAdded notification");
   yield false;
   Assert.equal(1, IMAPPump.inbox.getTotalMessages(false));
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   Assert.ok(msgHdr instanceof Ci.nsIMsgDBHdr);
 
   // set an arbitrary property
   msgHdr.setStringProperty("testprop", "somevalue");
   yield true;
 }
 
 // move the message to a subfolder
-function* moveMessageToSubfolder()
-{
+function* moveMessageToSubfolder() {
   let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
 
   // Now move this message to the subfolder.
   var messages = Cc["@mozilla.org/array;1"]
                    .createInstance(Ci.nsIMutableArray);
   messages.appendElement(msgHdr);
   /*
   void CopyMessages(in nsIMsgFolder srcFolder,
@@ -73,78 +72,71 @@ function* moveMessageToSubfolder()
                     in boolean isMove,
                     in nsIMsgCopyServiceListener listener,
                     in nsIMsgWindow msgWindow,
                     in boolean allowUndo);
   */
 
   MailServices.copy.CopyMessages(IMAPPump.inbox, messages, gSubfolder, true,
                                  asyncCopyListener, null, false);
-  dl('wait for OnStopCopy');
+  dl("wait for OnStopCopy");
   yield false;
 }
 
-function* testPropertyOnMove()
-{
+function* testPropertyOnMove() {
   gSubfolder.updateFolderWithListener(null, asyncUrlListener);
-  dl('wait for msgAdded');
+  dl("wait for msgAdded");
   yield false; // wait for msgAdded notification
-  dl('wait for OnStopRunningURL');
+  dl("wait for OnStopRunningURL");
   yield false; // wait for OnStopRunningUrl
   let msgHdr = mailTestUtils.firstMsgHdr(gSubfolder);
   Assert.equal(msgHdr.getStringProperty("testprop"), "somevalue");
   yield true;
 }
 
 // Cleanup
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
 
 // listeners
 
-var mfnListener =
-{
-  folderAdded: function folderAdded(aFolder)
-  {
-    dl('folderAdded <' + aFolder.name + '>');
+var mfnListener = {
+  folderAdded(aFolder) {
+    dl("folderAdded <" + aFolder.name + ">");
     // we are only using async yield on the Subfolder add
     if (aFolder.name == "Subfolder")
       async_driver();
   },
 
-  msgAdded: function msgAdded(aMsg)
-  {
-    dl('msgAdded with subject <' + aMsg.subject + '>')
+  msgAdded(aMsg) {
+    dl("msgAdded with subject <" + aMsg.subject + ">");
     async_driver();
   },
 
 };
 
-function run_test()
-{
+function run_test() {
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
   // Add folder listeners that will capture async events
   const nsIMFNService = Ci.nsIMsgFolderNotificationService;
   let flags =
         nsIMFNService.folderAdded |
         nsIMFNService.msgAdded;
   MailServices.mfn.addListener(mfnListener, flags);
   async_run_tests(tests);
 }
 
 /*
  * helper functions
  */
 
 // given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
+function specForFileName(aFileName) {
   let file = do_get_file("../../../data/" + aFileName);
   let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
   return msgfileuri.spec;
 }
 
 // shorthand output of a line of text
 function dl(text) {
-  dump(text + '\n');
+  dump(text + "\n");
 }
--- a/mailnews/imap/test/unit/test_saveImapDraft.js
+++ b/mailnews/imap/test/unit/test_saveImapDraft.js
@@ -3,16 +3,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * This file tests that a message saved as draft in an IMAP folder is correctly
  * marked as unread.
  */
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 // IMAP pump
 
@@ -20,34 +22,32 @@ setupIMAPPump();
 
 // Definition of tests
 
 var tests = [
   createDraftsFolder,
   saveDraft,
   updateDrafts,
   checkResult,
-  endTest
+  endTest,
 ];
 
 var gDraftsFolder;
-function* createDraftsFolder()
-{
+function* createDraftsFolder() {
   IMAPPump.incomingServer.rootFolder.createSubfolder("Drafts", null);
-  dl('wait for folderAdded');
+  dl("wait for folderAdded");
   yield false;
   gDraftsFolder = IMAPPump.incomingServer.rootFolder.getChildNamed("Drafts");
   Assert.ok(gDraftsFolder instanceof Ci.nsIMsgImapMailFolder);
   gDraftsFolder.updateFolderWithListener(null, asyncUrlListener);
-  dl('wait for OnStopRunningURL');
+  dl("wait for OnStopRunningURL");
   yield false;
 }
 
-function* saveDraft()
-{
+function* saveDraft() {
   var msgCompose = Cc["@mozilla.org/messengercompose/compose;1"]
                      .createInstance(Ci.nsIMsgCompose);
   var fields = Cc["@mozilla.org/messengercompose/composefields;1"]
                  .createInstance(Ci.nsIMsgCompFields);
   var params = Cc["@mozilla.org/messengercompose/composeparams;1"]
                  .createInstance(Ci.nsIMsgComposeParams);
   params.composeFields = fields;
   msgCompose.initialize(params);
@@ -59,94 +59,86 @@ function* saveDraft()
   var progress = Cc["@mozilla.org/messenger/progress;1"]
                    .createInstance(Ci.nsIMsgProgress);
   progress.registerListener(progressListener);
   msgCompose.SendMsg(Ci.nsIMsgSend.nsMsgSaveAsDraft, identity, "", null,
                      progress);
   yield false;
 }
 
-function* updateDrafts()
-{
+function* updateDrafts() {
   dump("updating drafts\n");
   gDraftsFolder.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
-function* checkResult()
-{
+function* checkResult() {
   dump("checking result\n");
   Assert.equal(gDraftsFolder.getTotalMessages(false), 1);
   Assert.equal(gDraftsFolder.getNumUnread(false), 1);
   yield true;
 }
 
-function* endTest()
-{
+function* endTest() {
   teardownIMAPPump();
   yield true;
 }
 
-function run_test()
-{
+function run_test() {
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
-  let server = IMAPPump.incomingServer;
 
   // Add folder listeners that will capture async events
   const nsIMFNService = Ci.nsIMsgFolderNotificationService;
 
   let flags =
         nsIMFNService.msgsMoveCopyCompleted |
         nsIMFNService.folderAdded |
         nsIMFNService.msgAdded;
   MailServices.mfn.addListener(mfnListener, flags);
 
-  //start first test
+  // start first test
   async_run_tests(tests);
 }
 
-var mfnListener =
-{
-  msgsMoveCopyCompleted: function (aMove, aSrcMsgs, aDestFolder, aDestMsgs)
-  {
-    dl('msgsMoveCopyCompleted to folder ' + aDestFolder.name);
+var mfnListener = {
+  msgsMoveCopyCompleted(aMove, aSrcMsgs, aDestFolder, aDestMsgs) {
+    dl("msgsMoveCopyCompleted to folder " + aDestFolder.name);
   },
 
-  folderAdded: function (aFolder)
-  {
-    dl('folderAdded <' + aFolder.name + '>');
+  folderAdded(aFolder) {
+    dl("folderAdded <" + aFolder.name + ">");
     // we are only using async add on the Junk folder
     if (aFolder.name == "Drafts")
       async_driver();
   },
 
-  msgAdded: function msgAdded(aMsg)
-  {
-    dl('msgAdded with subject <' + aMsg.subject + '>');
-  }
+  msgAdded(aMsg) {
+    dl("msgAdded with subject <" + aMsg.subject + ">");
+  },
 };
 
 var progressListener = {
-  onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
-    if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP){
-      dl('onStateChange');
+  onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
+    if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
+      dl("onStateChange");
       async_driver();
     }
   },
 
-  onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {},
-  onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) {},
-  onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) {},
-  onSecurityChange: function(aWebProgress, aRequest, state) {},
-  onContentBlockingEvent: function(aWebProgress, aRequest, aEvent) {},
+  onProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress,
+                   aCurTotalProgress, aMaxTotalProgress) {},
+  onLocationChange(aWebProgress, aRequest, aLocation, aFlags) {},
+  onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {},
+  onSecurityChange(aWebProgress, aRequest, state) {},
+  onContentBlockingEvent(aWebProgress, aRequest, aEvent) {},
 
   QueryInterface: ChromeUtils.generateQI(["nsIWebProgressListener",
                                           "nsISupportsWeakReference"]),
 };
 
 /*
  * helper functions
  */
 
 // quick shorthand for output of a line of text.
 function dl(text) {
-  dump(text + '\n');
+  dump(text + "\n");
 }
--- a/mailnews/imap/test/unit/test_saveTemplate.js
+++ b/mailnews/imap/test/unit/test_saveTemplate.js
@@ -6,69 +6,70 @@
  * Tests imap save of message as a template, and test initial save right after
  * creation of folder.
  */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 var {MailUtils} = ChromeUtils.import("resource:///modules/MailUtils.jsm");
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 // IMAP pump
 
 setupIMAPPump();
 
 var tests = [
   loadImapMessage,
   saveAsTemplate,
-  endTest
-]
+  endTest,
+];
 
 // load and update a message in the imap fake server
-function* loadImapMessage()
-{
+function* loadImapMessage() {
   let gMessageGenerator = new MessageGenerator();
   // create a synthetic message with attachment
   let smsg = gMessageGenerator.makeMessage();
 
   let msgURI =
     Services.io.newURI("data:text/plain;base64," +
                         btoa(smsg.toMessageString()));
-  let imapInbox =  IMAPPump.daemon.getMailbox("INBOX")
+  let imapInbox = IMAPPump.daemon.getMailbox("INBOX");
   let message = new imapMessage(msgURI.spec, imapInbox.uidnext++, []);
   IMAPPump.mailbox.addMessage(message);
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
   MailServices.mfn.addListener(mfnListener, MailServices.mfn.msgAdded);
   yield true;
 }
 
 // Cleanup
-function* endTest()
-{
+function* endTest() {
   teardownIMAPPump();
   yield true;
 }
 
 function saveAsUrlListener(aUri, aIdentity) {
   this.uri = aUri;
   this.identity = aIdentity;
 }
 
 saveAsUrlListener.prototype = {
-  OnStartRunningUrl: function(aUrl) {
+  OnStartRunningUrl(aUrl) {
   },
-  OnStopRunningUrl: function(aUrl, aExitCode) {
+  OnStopRunningUrl(aUrl, aExitCode) {
     let messenger = Cc["@mozilla.org/messenger;1"]
                       .createInstance(Ci.nsIMessenger);
     messenger.saveAs(this.uri, false, this.identity, null);
-  }
+  },
 };
 
 // This is similar to the method in mailCommands.js, to test the way that
 // it creates a new templates folder before saving the message as a template.
 function* saveAsTemplate() {
   let hdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
   let uri = IMAPPump.inbox.getUriForMsg(hdr);
   let identity = MailServices.accounts
@@ -78,24 +79,21 @@ function* saveAsTemplate() {
   // Verify that Templates folder doesn't exist, and then create it.
   Assert.equal(templates.parent, null);
   templates.setFlag(Ci.nsMsgFolderFlags.Templates);
   templates.createStorageIfMissing(new saveAsUrlListener(uri, identity));
   yield false;
 }
 
 // listener for saveAsTemplate adding a message to the templates folder.
-var mfnListener =
-{
-  msgAdded: function msgAdded(aMsg)
-  {
+var mfnListener = {
+  msgAdded(aMsg) {
     // Check this is the templates folder.
     Assert.equal(aMsg.folder.prettyName, "Templates");
     async_driver();
   },
 };
 
 
-function run_test()
-{
+function run_test() {
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
   async_run_tests(tests);
 }
--- a/mailnews/imap/test/unit/test_starttlsFailure.js
+++ b/mailnews/imap/test/unit/test_starttlsFailure.js
@@ -1,32 +1,35 @@
 /**
  * This test checks that we handle the server dropping the connection
  * on starttls. Since fakeserver doesn't support STARTTLS, I've made
  * it drop the connection when it's attempted.
  */
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/alertTestUtils.js");
 load("../../../resources/asyncTestUtils.js");
 
 var gGotAlert = false;
 
+/* exported alert */// to asyncTestUtils.js
 function alert(aDialogTitle, aText) {
   Assert.ok(aText.startsWith("Server localhost has disconnected"));
   gGotAlert = true;
 }
 
 var tests = [
   setup,
   check_alert,
-  teardown
+  teardown,
 ];
 
 function* setup() {
   // set up IMAP fakeserver and incoming server
   IMAPPump.daemon = new imapDaemon();
   IMAPPump.server = makeServer(IMAPPump.daemon, "", {dropOnStartTLS: true});
   IMAPPump.incomingServer = createLocalIMAPServer(IMAPPump.server.port);
   IMAPPump.incomingServer.socketType = Ci.nsMsgSocketType.alwaysSTARTTLS;
--- a/mailnews/imap/test/unit/test_stopMovingToLocalFolder.js
+++ b/mailnews/imap/test/unit/test_stopMovingToLocalFolder.js
@@ -3,47 +3,50 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Test that the message failed to move to a local folder remains on IMAP
  * server. */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 setupIMAPPump();
 
 function stop_server() {
   IMAPPump.incomingServer.closeCachedConnections();
   IMAPPump.server.stop();
   let thread = gThreadManager.currentThread;
   while (thread.hasPendingEvents())
     thread.processNextEvent(true);
 }
 
 var asyncCopyListener = {
-  OnStartCopy: function() {},
-  SetMessageKey: function(aMsgKey) {},
-  GetMessageId: function() {},
-  OnProgress: function(aProgress, aProgressMax) {
+  OnStartCopy() {},
+  SetMessageKey(aMsgKey) {},
+  GetMessageId() {},
+  OnProgress(aProgress, aProgressMax) {
     stop_server();
   },
-  OnStopCopy: function(aStatus) {
+  OnStopCopy(aStatus) {
     Assert.equal(aStatus, 0);
     async_driver();
-  }
+  },
 };
 
 var tests = [
   setup_messages,
   move_messages,
-  check_messages
+  check_messages,
 ];
 
 function* setup_messages() {
   Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
 
   let messageGenerator = new MessageGenerator();
   let messageString = messageGenerator.makeMessage().toMessageString();
   let dataUri = Services.io.newURI("data:text/plain;base64," + btoa(messageString));
@@ -74,16 +77,18 @@ function run_test() {
     // IMAPPump.server.performTest() brings this test to a halt,
     // so we need teardownIMAPPump() without IMAPPump.server.performTest().
     IMAPPump.inbox = null;
     IMAPPump.server.resetTest();
     try {
       IMAPPump.incomingServer.closeCachedConnections();
       let serverSink = IMAPPump.incomingServer.QueryInterface(Ci.nsIImapServerSink);
       serverSink.abortQueuedUrls();
-    } catch (ex) {dump(ex);}
+    } catch (ex) {
+      dump(ex);
+    }
     IMAPPump.server.stop();
     let thread = gThreadManager.currentThread;
     while (thread.hasPendingEvents())
       thread.processNextEvent(true);
   });
   async_run_tests(tests);
 }
--- a/mailnews/imap/test/unit/test_subfolderLocation.js
+++ b/mailnews/imap/test/unit/test_subfolderLocation.js
@@ -1,25 +1,25 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Test proper location of new imap offline subfolders for maildir.
 
-var CC = Components.Constructor;
-
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/alertTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/alertTestUtils.js");
 
 // Globals
 
 // Messages to load must have CRLF line endings, that is Windows style
 var gMessage = "bugmail10"; // message file used as the test message
 
-add_task(function () {
+add_task(function() {
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
   setupIMAPPump();
 });
 
 // load and update a message in the imap fake server
 add_task(async function loadImapMessage() {
   IMAPPump.mailbox.addMessage(new imapMessage(specForFileName(gMessage),
                               IMAPPump.mailbox.uidnext++, []));
@@ -59,20 +59,16 @@ add_task(function testSubfolder() {
   let subfolder1 = IMAPPump.inbox.getChildNamed(folderName1);
   let subfolder2 = IMAPPump.inbox.getChildNamed(folderName2);
   Assert.equal(subfolder1.filePath.parent.path, subfolder2.filePath.parent.path);
 });
 
 // Cleanup at end
 add_task(teardownIMAPPump);
 
-function run_test() {
-  run_next_test();
-}
-
 /*
  * helper functions
  */
 
 // given a test file, return the file uri spec
 function specForFileName(aFileName) {
   let file = do_get_file("../../../data/" + aFileName);
   let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
--- a/mailnews/imap/test/unit/test_syncChanges.js
+++ b/mailnews/imap/test/unit/test_syncChanges.js
@@ -1,15 +1,18 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Test to ensure that changes made from a different profile/machine
  * are synced correctly. In particular, we're checking that emptying out
  * an imap folder on the server makes us delete all the headers from our db.
  */
 
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
+/* import-globals-from ../../../test/resources/messageGenerator.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 load("../../../resources/messageGenerator.js");
 
 var gMessage;
 var gSecondFolder;
 var gSynthMessage;
 
@@ -32,29 +35,29 @@ var tests = [
   function* simulateMailboxEmptied() {
     gMessage.setFlag("\\Deleted");
     IMAPPump.inbox.expunge(asyncUrlListener, null);
     yield false;
     IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
     yield false;
   },
   function checkMailboxEmpty() {
-    let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gSynthMessage.messageId);
+    IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gSynthMessage.messageId);
     Assert.equal(IMAPPump.inbox.getTotalMessages(false), 0);
   },
-  teardown
+  teardown,
 ];
 
 function* setup() {
   /*
    * Set up an IMAP server.
    */
   setupIMAPPump();
 
-  IMAPPump.daemon.createMailbox("secondFolder", {subscribed : true});
+  IMAPPump.daemon.createMailbox("secondFolder", {subscribed: true});
 
   let messages = [];
   let gMessageGenerator = new MessageGenerator();
   messages = messages.concat(gMessageGenerator.makeMessage());
   gSynthMessage = messages[0];
 
   let msgURI =
     Services.io.newURI("data:text/plain;base64," +
--- a/mailnews/imap/test/unit/test_trustSpamAssassin.js
+++ b/mailnews/imap/test/unit/test_trustSpamAssassin.js
@@ -7,16 +7,18 @@
  *  SpamAssassin headers, and marking that as good
  *  without having the message return to the junk folder,
  *  as discussed in bug 540385.
  *
  * adapted from test_filterNeedsBody.js
  */
 
 // async support
+/* import-globals-from ../../../test/resources/logHelper.js */
+/* import-globals-from ../../../test/resources/asyncTestUtils.js */
 load("../../../resources/logHelper.js");
 load("../../../resources/asyncTestUtils.js");
 
 // IMAP pump
 
 // Globals
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 
@@ -28,60 +30,56 @@ setupIMAPPump();
 
 var tests = [
   createJunkFolder,
   loadImapMessage,
   testMessageInJunk,
   markMessageAsGood,
   updateFoldersAndCheck,
   endTest,
-]
+];
 
 var gJunkFolder;
-function* createJunkFolder()
-{
+function* createJunkFolder() {
   IMAPPump.incomingServer.rootFolder.createSubfolder("Junk", null);
-  dl('wait for folderAdded');
+  dl("wait for folderAdded");
   yield false;
   gJunkFolder = IMAPPump.incomingServer.rootFolder.getChildNamed("Junk");
   Assert.ok(gJunkFolder instanceof Ci.nsIMsgImapMailFolder);
   gJunkFolder.updateFolderWithListener(null, asyncUrlListener);
-  dl('wait for OnStopRunningURL');
+  dl("wait for OnStopRunningURL");
   yield false;
 }
 
 /*
  * Load and update a message in the imap fake server, should move
  *  SpamAssassin-marked junk message to junk folder
  */
-function* loadImapMessage()
-{
+function* loadImapMessage() {
   IMAPPump.mailbox.addMessage(new imapMessage(specForFileName(gMessage),
                           IMAPPump.mailbox.uidnext++, []));
   /*
    * The message matched the SpamAssassin header, so it moved
    *  to the junk folder
    */
   IMAPPump.inbox.updateFolder(null);
-  dl('wait for msgsMoveCopyCompleted');
+  dl("wait for msgsMoveCopyCompleted");
   yield false;
   gJunkFolder.updateFolderWithListener(null, asyncUrlListener);
-  dl('wait for OnStopRunningURL');
+  dl("wait for OnStopRunningURL");
   yield false;
 }
 
-function* testMessageInJunk()
-{
+function* testMessageInJunk() {
   Assert.equal(0, IMAPPump.inbox.getTotalMessages(false));
   Assert.equal(1, gJunkFolder.getTotalMessages(false));
   yield true;
 }
 
-function* markMessageAsGood()
-{
+function* markMessageAsGood() {
   /*
    * This is done in the application in nsMsgDBView, which is difficult
    *  to test in xpcshell tests. We aren't really trying to test that here
    *  though, since the point of this test is working with the server-based
    *  filters. So I will simply simulate the operations that would typically
    *  be done by a manual marking of the messages.
    */
   let msgHdr = mailTestUtils.firstMsgHdr(gJunkFolder);
@@ -104,41 +102,38 @@ function* markMessageAsGood()
                     in boolean isMove,
                     in nsIMsgCopyServiceListener listener,
                     in nsIMsgWindow msgWindow,
                     in boolean allowUndo);
   */
 
   MailServices.copy.CopyMessages(gJunkFolder, messages, IMAPPump.inbox, true,
                                  null, null, false);
-  dl('wait for msgsMoveCopyCompleted');
+  dl("wait for msgsMoveCopyCompleted");
   yield false;
 }
 
-function* updateFoldersAndCheck()
-{
+function* updateFoldersAndCheck() {
   IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
-  dl('wait for OnStopRunningURL');
+  dl("wait for OnStopRunningURL");
   yield false;
   gJunkFolder.updateFolderWithListener(null, asyncUrlListener);
-  dl('wait for OnStopRunningURL');
+  dl("wait for OnStopRunningURL");
   yield false;
   // bug 540385 causes this test to fail
   Assert.equal(1, IMAPPump.inbox.getTotalMessages(false));
   Assert.equal(0, gJunkFolder.getTotalMessages(false));
   yield true;
 }
 
-function endTest()
-{
+function endTest() {
   teardownIMAPPump();
 }
 
-function run_test()
-{
+function run_test() {
   let server = IMAPPump.incomingServer;
   let spamSettings = server.spamSettings;
   server.setBoolValue("useServerFilter", true);
   server.setCharValue("serverFilterName", "SpamAssassin");
   server.setIntValue("serverFilterTrustFlags", Ci.nsISpamSettings.TRUST_POSITIVES);
   server.setBoolValue("moveOnSpam", true);
   server.setIntValue("moveTargetMode", Ci.nsISpamSettings.MOVE_TARGET_MODE_ACCOUNT);
   server.setCharValue("spamActionTargetAccount", server.serverURI);
@@ -149,50 +144,45 @@ function run_test()
   const nsIMFNService = Ci.nsIMsgFolderNotificationService;
 
   let flags =
         nsIMFNService.msgsMoveCopyCompleted |
         nsIMFNService.folderAdded |
         nsIMFNService.msgAdded;
   MailServices.mfn.addListener(mfnListener, flags);
 
-  //start first test
+  // start first test
   async_run_tests(tests);
 }
 
-var mfnListener =
-{
-  msgsMoveCopyCompleted: function (aMove, aSrcMsgs, aDestFolder, aDestMsgs)
-  {
-    dl('msgsMoveCopyCompleted to folder ' + aDestFolder.name);
+var mfnListener = {
+  msgsMoveCopyCompleted(aMove, aSrcMsgs, aDestFolder, aDestMsgs) {
+    dl("msgsMoveCopyCompleted to folder " + aDestFolder.name);
     async_driver();
   },
 
-  folderAdded: function (aFolder)
-  {
-    dl('folderAdded <' + aFolder.name + '>');
+  folderAdded(aFolder) {
+    dl("folderAdded <" + aFolder.name + ">");
     // we are only using async add on the Junk folder
     if (aFolder.name == "Junk")
       async_driver();
   },
 
-  msgAdded: function msgAdded(aMsg)
-  {
-    dl('msgAdded with subject <' + aMsg.subject + '>');
-  }
+  msgAdded(aMsg) {
+    dl("msgAdded with subject <" + aMsg.subject + ">");
+  },
 };
 
 /*
  * helper functions
  */
 
 // given a test file, return the file uri spec
-function specForFileName(aFileName)
-{
+function specForFileName(aFileName) {
   let file = do_get_file("../../../data/" + aFileName);
   let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
   return msgfileuri.spec;
 }
 
 // quick shorthand for output of a line of text.
 function dl(text) {
-  dump(text + '\n');
+  dump(text + "\n");
 }