Bug 824150 - Code cleanup in /mail/ and /mailnews/: Use new String methods like startsWith, endsWith, contains, remaining Services.jsm switches and querySelector use instead of NodeList calls: fakeserver. r=mbanner
authorSebastian Hengst <archaeopteryx@coole-files.de>
Sat, 09 Feb 2013 20:01:21 +0100
changeset 14841 9e7319029574532affae61a2b6e9dc5b2453ba5d
parent 14840 aeb1127152ac457aef2ec6484c5a177f9d34358d
child 14842 59e6970aea76a5207a7ab01b476a8fd2ce081b71
push id867
push userbugzilla@standard8.plus.com
push dateMon, 01 Apr 2013 20:44:27 +0000
treeherdercomm-beta@797726b8d244 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbanner
bugs824150
Bug 824150 - Code cleanup in /mail/ and /mailnews/: Use new String methods like startsWith, endsWith, contains, remaining Services.jsm switches and querySelector use instead of NodeList calls: fakeserver. r=mbanner
mailnews/base/test/unit/test_testsuite_fakeserver_imapd_gmail.js
mailnews/base/test/unit/test_testsuite_fakeserver_imapd_list-extended.js
mailnews/imap/test/unit/test_imapContentLength.js
mailnews/test/fakeserver/imapd.js
mailnews/test/fakeserver/maild.js
mailnews/test/fakeserver/nntpd.js
mailnews/test/fakeserver/smtpd.js
--- a/mailnews/base/test/unit/test_testsuite_fakeserver_imapd_gmail.js
+++ b/mailnews/base/test/unit/test_testsuite_fakeserver_imapd_gmail.js
@@ -40,36 +40,36 @@ function setupMailboxes()
   gIMAPDaemon.createMailbox("[Gmail]/Sent", {specialUseFlag : "\\Sent"});
   gIMAPDaemon.createMailbox("[Gmail]/Spam", {specialUseFlag : "\\Spam"});
   gIMAPDaemon.createMailbox("[Gmail]/Starred", {specialUseFlag : "\\Starred"});
   gIMAPDaemon.createMailbox("[Gmail]/Trash", {specialUseFlag : "\\Trash"});
   gIMAPDaemon.createMailbox("test", {});
 
   handler = gIMAPServer._handlerCreator(gIMAPDaemon);
   let response = handler.onError('1', 'LOGIN user password');
-  do_check_true(response.indexOf('OK') >= 0);
+  do_check_true(response.contains('OK'));
   // wait for imap pump to do its thing or else we get memory leaks
   gIMAPInbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
 // test that 'XLIST "" "*"' returns the proper responses
 function testXlist()
 {
   let response = handler.onError('2', 'XLIST "" "*"');
 
-  do_check_true(response.indexOf('* LIST (\\HasNoChildren \\Inbox) "/" "INBOX"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\Noselect \\HasChildren) "/" "[Gmail]"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\HasNoChildren \\AllMail) "/" "[Gmail]/All Mail"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\HasNoChildren \\Drafts) "/" "[Gmail]/Drafts"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\HasNoChildren \\Sent) "/" "[Gmail]/Sent"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\HasNoChildren \\Spam) "/" "[Gmail]/Spam"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\HasNoChildren \\Starred) "/" "[Gmail]/Starred"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\HasNoChildren \\Trash) "/" "[Gmail]/Trash"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\HasNoChildren) "/" "test"') >= 0);
+  do_check_true(response.contains('* LIST (\\HasNoChildren \\Inbox) "/" "INBOX"'));
+  do_check_true(response.contains('* LIST (\\Noselect \\HasChildren) "/" "[Gmail]"'));
+  do_check_true(response.contains('* LIST (\\HasNoChildren \\AllMail) "/" "[Gmail]/All Mail"'));
+  do_check_true(response.contains('* LIST (\\HasNoChildren \\Drafts) "/" "[Gmail]/Drafts"'));
+  do_check_true(response.contains('* LIST (\\HasNoChildren \\Sent) "/" "[Gmail]/Sent"'));
+  do_check_true(response.contains('* LIST (\\HasNoChildren \\Spam) "/" "[Gmail]/Spam"'));
+  do_check_true(response.contains('* LIST (\\HasNoChildren \\Starred) "/" "[Gmail]/Starred"'));
+  do_check_true(response.contains('* LIST (\\HasNoChildren \\Trash) "/" "[Gmail]/Trash"'));
+  do_check_true(response.contains('* LIST (\\HasNoChildren) "/" "test"'));
 
   yield true;
 }
 
 // Cleanup at end
 function endTest()
 {
   teardownIMAPPump();
--- a/mailnews/base/test/unit/test_testsuite_fakeserver_imapd_list-extended.js
+++ b/mailnews/base/test/unit/test_testsuite_fakeserver_imapd_list-extended.js
@@ -48,106 +48,106 @@ function setupMailboxes()
                                             subscribed : true});
   gIMAPDaemon.createMailbox("Tofu", {});
   gIMAPDaemon.createMailbox("Vegetable", {subscribed : true});
   gIMAPDaemon.createMailbox("Vegetable/Broccoli", {subscribed : true});
   gIMAPDaemon.createMailbox("Vegetable/Corn", {});
 
   handler = gIMAPServer._handlerCreator(gIMAPDaemon);
   let response = handler.onError('1', 'LOGIN user password');
-  do_check_true(response.indexOf('OK') >= 0);
+  do_check_true(response.contains('OK'));
   // wait for imap pump to do it's thing or else we get memory leaks
   gIMAPInbox.updateFolderWithListener(null, asyncUrlListener);
   yield false;
 }
 
 // test that 'LIST "" "*"' returns the proper responses (standard LIST usage)
 function testList()
 {
   let response = handler.onError('2', 'LIST "" "*"');
 
-  do_check_true(response.indexOf('* LIST (\\Marked \\NoInferiors) "/" "INBOX"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Fruit"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Fruit/Apple"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Fruit/Banana"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Tofu"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Vegetable"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Vegetable/Broccoli"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Vegetable/Corn"') >= 0);
-  do_check_true(response.indexOf('Peach') == -1);
+  do_check_true(response.contains('* LIST (\\Marked \\NoInferiors) "/" "INBOX"'));
+  do_check_true(response.contains('* LIST () "/" "Fruit"'));
+  do_check_true(response.contains('* LIST () "/" "Fruit/Apple"'));
+  do_check_true(response.contains('* LIST () "/" "Fruit/Banana"'));
+  do_check_true(response.contains('* LIST () "/" "Tofu"'));
+  do_check_true(response.contains('* LIST () "/" "Vegetable"'));
+  do_check_true(response.contains('* LIST () "/" "Vegetable/Broccoli"'));
+  do_check_true(response.contains('* LIST () "/" "Vegetable/Corn"'));
+  do_check_false(response.contains('Peach'));
 
   yield true;
 }
 
 // test that 'LIST (SUBSCRIBED) "" "*"' returns the proper responses
 function testListSelectSubscribed()
 {
   let response = handler.onError('3', 'LIST (SUBSCRIBED) "" "*"');
 
-  do_check_true(response.indexOf('* LIST (\\Marked \\NoInferiors \\Subscribed) "/" "INBOX"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\Subscribed) "/" "Fruit/Banana"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\Subscribed \\NonExistent) "/" "Fruit/Peach"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\Subscribed) "/" "Vegetable"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\Subscribed) "/" "Vegetable/Broccoli"') >= 0);
-  do_check_true(response.indexOf('"Fruit"') == -1);
-  do_check_true(response.indexOf('Apple') == -1);
-  do_check_true(response.indexOf('Tofu') == -1);
-  do_check_true(response.indexOf('Corn') == -1);
+  do_check_true(response.contains('* LIST (\\Marked \\NoInferiors \\Subscribed) "/" "INBOX"'));
+  do_check_true(response.contains('* LIST (\\Subscribed) "/" "Fruit/Banana"'));
+  do_check_true(response.contains('* LIST (\\Subscribed \\NonExistent) "/" "Fruit/Peach"'));
+  do_check_true(response.contains('* LIST (\\Subscribed) "/" "Vegetable"'));
+  do_check_true(response.contains('* LIST (\\Subscribed) "/" "Vegetable/Broccoli"'));
+  do_check_false(response.contains('"Fruit"'));
+  do_check_false(response.contains('Apple'));
+  do_check_false(response.contains('Tofu'));
+  do_check_false(response.contains('Corn'));
 
   yield true;
 }
 
 // test that 'LIST "" "%" RETURN (CHILDEREN)' returns the proper responses
 function testListReturnChilderen()
 {
   let response = handler.onError('4', 'LIST "" "%" RETURN (CHILDREN)');
 
-  do_check_true(response.indexOf('* LIST (\\Marked \\NoInferiors) "/" "INBOX"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\HasChildren) "/" "Fruit"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\HasNoChildren) "/" "Tofu"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\HasChildren) "/" "Vegetable"') >= 0);
-  do_check_true(response.indexOf('Apple') == -1);
-  do_check_true(response.indexOf('Banana') == -1);
-  do_check_true(response.indexOf('Peach') == -1);
-  do_check_true(response.indexOf('Broccoli') == -1);
-  do_check_true(response.indexOf('Corn') == -1);
+  do_check_true(response.contains('* LIST (\\Marked \\NoInferiors) "/" "INBOX"'));
+  do_check_true(response.contains('* LIST (\\HasChildren) "/" "Fruit"'));
+  do_check_true(response.contains('* LIST (\\HasNoChildren) "/" "Tofu"'));
+  do_check_true(response.contains('* LIST (\\HasChildren) "/" "Vegetable"'));
+  do_check_false(response.contains('Apple'));
+  do_check_false(response.contains('Banana'));
+  do_check_false(response.contains('Peach'));
+  do_check_false(response.contains('Broccoli'));
+  do_check_false(response.contains('Corn'));
 
   yield true;
 }
 
 // test that 'LIST "" "*" RETURN (SUBSCRIBED)' returns the proper responses
 function testListReturnSubscribed()
 {
   let response = handler.onError('5', 'LIST "" "*" RETURN (SUBSCRIBED)');
 
-  do_check_true(response.indexOf('* LIST (\\Marked \\NoInferiors \\Subscribed) "/" "INBOX"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Fruit"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Fruit/Apple"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\Subscribed) "/" "Fruit/Banana"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Tofu"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\Subscribed) "/" "Vegetable"') >= 0);
-  do_check_true(response.indexOf('* LIST (\\Subscribed) "/" "Vegetable/Broccoli"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Vegetable/Corn"') >= 0);
-  do_check_true(response.indexOf('Peach') == -1);
+  do_check_true(response.contains('* LIST (\\Marked \\NoInferiors \\Subscribed) "/" "INBOX"'));
+  do_check_true(response.contains('* LIST () "/" "Fruit"'));
+  do_check_true(response.contains('* LIST () "/" "Fruit/Apple"'));
+  do_check_true(response.contains('* LIST (\\Subscribed) "/" "Fruit/Banana"'));
+  do_check_true(response.contains('* LIST () "/" "Tofu"'));
+  do_check_true(response.contains('* LIST (\\Subscribed) "/" "Vegetable"'));
+  do_check_true(response.contains('* LIST (\\Subscribed) "/" "Vegetable/Broccoli"'));
+  do_check_true(response.contains('* LIST () "/" "Vegetable/Corn"'));
+  do_check_false(response.contains('Peach'));
 
   yield true;
 }
 
 // test that 'LIST "" ("INBOX" "Tofu" "Vegetable/%")' returns the proper responses
 function testListSelectMultiple()
 {
   let response = handler._dispatchCommand('LIST', ['', '("INBOX" "Tofu" "Vegetable/%")']);
 
-  do_check_true(response.indexOf('* LIST (\\Marked \\NoInferiors) "/" "INBOX"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Tofu"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Vegetable/Broccoli"') >= 0);
-  do_check_true(response.indexOf('* LIST () "/" "Vegetable/Corn"') >= 0);
-  do_check_true(response.indexOf('"Vegetable"') == -1);
-  do_check_true(response.indexOf('Fruit') == -1);
-  do_check_true(response.indexOf('Peach') == -1);
+  do_check_true(response.contains('* LIST (\\Marked \\NoInferiors) "/" "INBOX"'));
+  do_check_true(response.contains('* LIST () "/" "Tofu"'));
+  do_check_true(response.contains('* LIST () "/" "Vegetable/Broccoli"'));
+  do_check_true(response.contains('* LIST () "/" "Vegetable/Corn"'));
+  do_check_false(response.contains('"Vegetable"'));
+  do_check_false(response.contains('Fruit'));
+  do_check_false(response.contains('Peach'));
 
   yield true;
 }
 
 // Cleanup at end
 function endTest()
 {
   handler = null;
--- a/mailnews/imap/test/unit/test_imapContentLength.js
+++ b/mailnews/imap/test/unit/test_imapContentLength.js
@@ -59,26 +59,26 @@ function verifyContentLength() {
   let messageUri = gIMAPInbox.getUriForMsg(gMsgHdr);
   // Convert this to a URI that necko can run
   let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
   let neckoURL = {};
   let messageService = messenger.messageServiceFromURI(messageUri);
   messageService.GetUrlForUri(messageUri, neckoURL, null);
   // Don't use the necko URL directly. Instead, get the spec and create a new
   // URL using the IO service
-  let urlToRun = gIOService.newURI(neckoURL.value.spec, null, null);
+  let urlToRun = Services.io.newURI(neckoURL.value.spec, null, null);
 
   // Get a channel from this URI, and check its content length
-  let channel = gIOService.newChannelFromURI(urlToRun);
+  let channel = Services.io.newChannelFromURI(urlToRun);
   do_check_eq(channel.contentLength, gFile.fileSize);
 
   // Now try an attachment. &part=1.2
-  let attachmentURL = gIOService.newURI(neckoURL.value.spec + "&part=1.2",
+  let attachmentURL = Services.io.newURI(neckoURL.value.spec + "&part=1.2",
                                         null, null);
-  let attachmentChannel = gIOService.newChannelFromURI(attachmentURL);
+  let attachmentChannel = Services.io.newChannelFromURI(attachmentURL);
   // Currently attachments have their content length set to the length of the
   // entire message
   do_check_eq(attachmentChannel.contentLength, gFile.fileSize);
 }
 
 function teardown() {
   gMFNService.removeListener(msgFolderListener);
   teardownIMAPPump();
--- a/mailnews/test/fakeserver/imapd.js
+++ b/mailnews/test/fakeserver/imapd.js
@@ -37,16 +37,18 @@
 // |       flag equality, though, uses case-sensitive checks. Therefore they  //
 // |       should be normalized to a title-case form (e.g., \Noselect).       //
 // + Synchronization: On certain synchronizing commands, the daemon will call //
 // |   a synchronizing function to allow manipulating code the chance to      //
 // |   perform various (potentially expensive) actions.                       //
 // + Messages: A message is represented internally as an annotated URI.       //
 ////////////////////////////////////////////////////////////////////////////////
 
+Components.utils.import("resource://gre/modules/Services.jsm");
+
 if (!("MimeParser" in this))
   Components.utils.import("resource:///modules/mimeParser.jsm", this);
 
 function imapDaemon(flags, syncFunc) {
   this._flags = flags;
 
   this.namespaces = [];
   this.idResponse = "NIL";
@@ -82,22 +84,22 @@ imapDaemon.prototype = {
   createNamespace : function (name, type) {
     var newbox = this.createMailbox(name, {type : type});
     this.namespaces.push(newbox);
   },
   getMailbox : function (name) {
     if (name == "")
       return this.root;
     // INBOX is case-insensitive, no matter what
-    if (name.substr(0, 5).toUpperCase() == "INBOX")
+    if (name.toUpperCase().startsWith("INBOX"))
       name = "INBOX" + name.substr(5);
     // We want to find a child who has the same name, but we don't quite know
     // what the delimiter is. The convention is that different namespaces use a
     // name starting with '#', so that's how we'll work it out.
-    if (name[0] == '#') {
+    if (name.startsWith('#')) {
       var root = null;
       for each (var mailbox in this.root._children) {
         if (mailbox.name.indexOf(name) == 0 &&
             name[mailbox.name.length] == mailbox.delimiter) {
           root = mailbox;
           break;
         }
       }
@@ -321,32 +323,28 @@ imapMailbox.prototype = {
       }
     }
     if (response.length > 0)
       delete this.__highestuid;
     return response;
   }
 }
 
-var gIOService;
 function imapMessage(URI, uid, flags) {
   this._URI = URI;
   this.uid = uid;
   this.size = 0;
   this.flags = new Array;
   for each (flag in flags)
     this.flags.push(flag);
   this.recent = false;
 }
 imapMessage.prototype = {
   get channel() {
-    if (!gIOService)
-      gIOService = Cc["@mozilla.org/network/io-service;1"]
-                     .getService(Ci.nsIIOService);
-    return gIOService.newChannel(this._URI, null, null);
+    return Services.io.newChannel(this._URI, null, null);
   },
   setFlag : function (flag) {
    if (this.flags.indexOf(flag) == -1)
      this.flags.push(flag);
   },
   // This allows us to simulate servers that approximate the rfc822 size.
   setSize: function(size) {
     this.size = size;
@@ -491,17 +489,17 @@ function parseCommand(text, partial) {
       if (current == undefined)
         throw "Unexpected CLOSE_PAREN";
       current.push(hold);
     } else if (c == ' ') {
       if (atom.length > 0) {
         current.push(atom);
         atom = '';
       }
-    } else if (text.substring(0,3).toUpperCase() == "NIL" &&
+    } else if (text.toUpperCase().startsWith("NIL") &&
                (text.length == 3 || text[3] == ' ')) {
       current.push(null);
       text = text.substring(4);
       continue;
     } else {
       atom += c;
     }
     text = text.substring(1);
@@ -511,31 +509,31 @@ function parseCommand(text, partial) {
   if (atom.length > 0)
     args.push(atom);
   return args;
 }
 
 function formatArg(argument, spec) {
   // Get NILs out of the way quickly
   var nilAccepted = false;
-  if (spec[0] == 'n' && spec[1] != 'u') {
+  if (spec.startsWith('n') && spec[1] != 'u') {
     spec = spec.substring(1);
     nilAccepted = true;
   }
   if (argument == null) {
     if (!nilAccepted)
       throw "Unexpected NIL!";
 
     return null;
   }
 
   // array!
-  if (spec[0] == '(') {
+  if (spec.startsWith('(')) {
     // typeof array is object. Don't ask me why.
-    if (typeof argument != "object")
+    if (!Array.isArray(argument))
       throw "Expected list!";
     // Strip the '(' and ')'...
     spec = spec.substring(1, spec.length - 1);
     // ... and apply to the rest
     return argument.map(function (item) { return formatArg(item, spec); });
   }
 
   // or!
@@ -585,17 +583,17 @@ function formatArg(argument, spec) {
 
   return argument;
 }
 
 // used by RFC 5258 and GMail (labels)
 function parseMailboxList(aList) {
 
   // strip enclosing parentheses
-  if (aList[0] == '(') {
+  if (aList.startsWith('(')) {
     aList = aList.substring(1, aList.length - 1);
   }
   let mailboxList = [];
   for (let i = 0; i < aList.length; i++) {
     // first, check for literals
     if (aList[i] == '{') {
       let endBracketPos = aList.indexOf('}', i);
       let literalLen = parseInt(aList.substring(i + 1, endBracketPos));
@@ -858,17 +856,17 @@ IMAP_RFC3501_handler.prototype = {
         }
         response = line + '\0' + response;
       }
     }
 
     var lines = response.split(/\u0000/);
     response = "";
     for each (var line in lines) {
-      if (line[0] != '+' && line[0] != '*')
+      if (!line.startsWith('+') && !line.startsWith('*'))
         response += this._tag + " ";
       response += line + "\r\n";
     }
     return response;
   },
   _treatArgs : function (args, command) {
     var format = this._argFormat[command];
     var treatedArgs = [];
@@ -877,22 +875,22 @@ IMAP_RFC3501_handler.prototype = {
 
       if (spec == "...") {
         treatedArgs = treatedArgs.concat(args);
         args = [];
         break;
       }
 
       if (args.length == 0)
-        if (spec[0] == '[') // == optional arg
+        if (spec.startsWith('[')) // == optional arg
           continue;
         else
           throw "BAD not enough arguments";
 
-      if (spec[0] == '[') {
+      if (spec.startsWith('[')) {
         // We have an optional argument. See if the format matches and move on
         // if it doesn't. Ideally, we'd rethink our decision if a later
         // application turns out to be wrong, but that's ugly to do
         // iteratively. Should any IMAP extension require it, we'll have to
         // come back and change this assumption, though.
         spec = spec.substr(1, spec.length - 2);
         try {
           var out = formatArg(args[0], spec);
@@ -1101,17 +1099,17 @@ IMAP_RFC3501_handler.prototype = {
       return 'BAD unknown LIST request options';
 
     let base = this._daemon.getMailbox(args[0]);
     if (!base)
       return "NO no such mailbox";
     let requestedBoxes;
     // check for multiple mailbox patterns used by LIST-EXTENDED
     // and other related RFCs
-    if (args[1][0] == "(") {
+    if (args[1].startsWith("(")) {
       requestedBoxes = parseMailboxList(args[1]);
     } else {
       requestedBoxes = [ args[1] ];
     }
     let response = "";
     for each (let requestedBox in requestedBoxes) {
       let people = base.matchKids(requestedBox);
       for each (let box in people) {
@@ -1304,17 +1302,17 @@ IMAP_RFC3501_handler.prototype = {
     }
     return response + "OK FETCH completed";
   },
   STORE : function (args, uid) {
     var ids = [];
     var messages = this._parseSequenceSet(args[0], uid, ids);
 
     args[1] = args[1].toUpperCase();
-    var silent = args[1].indexOf('.SILENT') > 0;
+    var silent = args[1].contains('.SILENT', 1);
     if (silent)
       args[1] = args[1].substring(0, args[1].indexOf('.'));
 
     if (typeof args[2] != "object")
       args[2] = [args[2]];
 
     var response = "";
     for (var i = 0; i < messages.length; i++) {
@@ -1437,17 +1435,17 @@ IMAP_RFC3501_handler.prototype = {
       if(!num || (num.length != part.length))
         throw "BAD invalid UID " + part;
       return parseInt(part);
     }
 
     var elements = set.split(/,/);
     set = [];
     for each (var part in elements) {
-      if (part.indexOf(':') == -1) {
+      if (!part.contains(':')) {
         set.push(part2num(part));
       } else {
         var range = part.split(/:/);
         range[0] = part2num(range[0]);
         range[1] = part2num(range[1]);
         if (range[0] > range[1]) {
           let temp = range[1];
           range[1] = range[0];
@@ -1511,22 +1509,22 @@ IMAP_RFC3501_handler.prototype = {
 
     // What's inside the command?
     var data = /((?:\d+\.)*\d+)(?:\.([^ ]+))?/.exec(parts[1]);
     if (data) {
       var partNum = data[1];
       query = data[2];
     } else {
       var partNum = "";
-      if (parts[1].indexOf(" ") > 0)
+      if (parts[1].contains(" ", 1))
         query = parts[1].substring(0, parts[1].indexOf(" "));
       else
         query = parts[1];
     }
-    if (parts[1].indexOf(" ") > 0)
+    if (parts[1].contains(" ", 1))
       var queryArgs = parseCommand(parts[1].substr(parts[1].indexOf(" ")))[0];
     else
       var queryArgs = [];
 
     // Now we have three parameters representing the part number (empty for top-
     // level), the subportion representing what we want to find (empty for the
     // body), and an array of arguments if we have a subquery. If we made an
     // error here, it will pop until it gets to FETCH, which will just pop at a
--- a/mailnews/test/fakeserver/maild.js
+++ b/mailnews/test/fakeserver/maild.js
@@ -312,17 +312,17 @@ function nsMailReader(server, handler, t
   if (logTransaction)
     this.transaction = { us : [], them : [] };
   else
     this.transaction = null;
 
   // Send response line
   var response = this._handler.onStartup();
   response = response.replace(/([^\r])\n/g,"$1\r\n");
-  if (response.charAt(response.length-1) != '\n')
+  if (!response.endsWith('\n'))
     response = response + "\r\n";
   if (this.transaction)
     this.transaction.us.push(response);
   this._output.write(response, response.length);
   this._output.flush();
 
   this._multiline = false;
 
@@ -431,17 +431,17 @@ nsMailReader.prototype = {
         } else {
           dump("Exception caught: " + e + '\n');
         }
       }
 
       if (!this._preventLFMunge)
         response = response.replace(/([^\r])\n/g,"$1\r\n");
 
-      if (response.charAt(response.length-1) != '\n')
+      if (!response.endsWith('\n'))
        response = response + "\r\n";
 
       if (this._debug == fsDebugRecvSend) {
         print("SEND: " + response.split(" ", 1)[0]);
       }
       else if (this._debug == fsDebugAll) {
         var responses = response.split("\n");
         responses.forEach(function (line) { print("SEND: " + line); });
--- a/mailnews/test/fakeserver/nntpd.js
+++ b/mailnews/test/fakeserver/nntpd.js
@@ -296,17 +296,17 @@ NNTP_RFC977_handler.prototype = {
         var article = new newsArticle(this.post);
         this._daemon.addArticle(article);
         this.posting = false;
         return "240 Wonderful article, your style is gorgeous!";
       }
     }
 
     if (this.posting) {
-      if (line.charAt(0) == '.')
+      if (line.startsWith('.'))
         line = line.substring(1);
 
       this.post += line+'\n';
     }
 
     return undefined;
   },
   postCommand : function (reader) {
@@ -327,17 +327,17 @@ NNTP_RFC977_handler.prototype = {
     if (args == "") {
       if (this.group == null)
         return [null, "412 no newsgroup has been selected"];
       if (this.articleKey == null)
         return [null, "420 no current article has been selected"];
 
       art = this.group[this.articleKey];
       key = this.articleKey;
-    } else if (args.charAt(0) == '<') {
+    } else if (args.startsWith('<')) {
       art = this._daemon.getArticle(args);
       key = 0;
 
       if (art == null)
         return [null, "430 no such article found"];
     } else {
       if (this.group == null)
         return [null, "412 no newsgroup has been selected"];
--- a/mailnews/test/fakeserver/smtpd.js
+++ b/mailnews/test/fakeserver/smtpd.js
@@ -230,17 +230,17 @@ SMTP_RFC2821_handler.prototype = {
       if (this.expectingData) {
         this.expectingData = false;
         return "250 Wonderful article, your style is gorgeous!";
       }
       return "503 Huch? How did you get here?";
     }
 
     if (this.expectingData) {
-      if (line.charAt(0) == '.')
+      if (line.startsWith('.'))
         line = line.substring(1);
       // This uses CR LF to match with the specification
       this._daemon.post += line + '\r\n';
     }
     return undefined;
   },
   postCommand: function(reader) {
     if (this.closing)