Bug 664834 - Switch suite/mailnews to use Services.io r=neil
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sat, 18 Jun 2011 18:42:16 +0100
changeset 7967 8f52a70cb585dbbe94d60be0c341c84d17b47360
parent 7966 28902a0bb8344e40b388a6dd3af6420a6a04b782
child 7968 6a9dc33c7bc34e9484085e64e2fd649cc232851e
push id6126
push useriann_cvs@blueyonder.co.uk
push dateSat, 18 Jun 2011 17:41:03 +0000
treeherdercomm-central@8f52a70cb585 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs664834
Bug 664834 - Switch suite/mailnews to use Services.io r=neil
suite/mailnews/addrbook/abCardViewOverlay.js
suite/mailnews/compose/MsgComposeCommands.js
suite/mailnews/mail-offline.js
suite/mailnews/mail3PaneWindowCommands.js
suite/mailnews/mailContextMenus.js
suite/mailnews/mailTasksOverlay.js
suite/mailnews/mailWindow.js
suite/mailnews/mailWindowOverlay.js
suite/mailnews/messageWindow.js
suite/mailnews/msgHdrViewOverlay.js
suite/mailnews/msgMail3PaneWindow.js
suite/mailnews/phishingDetector.js
suite/mailnews/prefs/pref-notifications.js
--- a/suite/mailnews/addrbook/abCardViewOverlay.js
+++ b/suite/mailnews/addrbook/abCardViewOverlay.js
@@ -44,18 +44,17 @@ var gPrefs = Components.classes["@mozill
 gPrefs = gPrefs.getService();
 gPrefs = gPrefs.QueryInterface(Components.interfaces.nsIPrefBranch);
 
 var gProfileDirURL;
 
 var gMapItURLFormat = gPrefs.getComplexValue("mail.addr_book.mapit_url.format", 
                                               Components.interfaces.nsIPrefLocalizedString).data;
 
-var gIOService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
-var gFileHandler = gIOService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
+var gFileHandler = Services.io.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
 
 var zListName;
 var zPrimaryEmail;
 var zSecondaryEmail;
 var zScreenName;
 var zNickname;
 var zDisplayName;
 var zWork;
@@ -367,17 +366,17 @@ function setBuddyIcon(card, buddyIcon)
   try {
     var myScreenName = gPrefs.getCharPref("aim.session.screenname");
     if (myScreenName && card.primaryEmail) {
       if (!gProfileDirURL) {
         // lazily create these file urls, and keep them around
         var dirService = Components.classes["@mozilla.org/file/directory_service;1"]
             .getService(Components.interfaces.nsIProperties);
         var profileDir = dirService.get("ProfD", Components.interfaces.nsIFile);
-        gProfileDirURL = gIOService.newFileURI(profileDir);
+        gProfileDirURL = Services.io.newFileURI(profileDir);
       }
 
       // if we did have a buddy icon on disk for this screenname, this would be the file url spec for it
       var iconURLStr = gProfileDirURL.spec + "/NIM/" + myScreenName + "/picture/" + card.getProperty("_AimScreenName") + ".gif";
 
       // check if the file exists
       var file = gFileHandler.getFileFromURLSpec(iconURLStr);
             
--- a/suite/mailnews/compose/MsgComposeCommands.js
+++ b/suite/mailnews/compose/MsgComposeCommands.js
@@ -81,26 +81,24 @@ var gMessenger = Components.classes["@mo
                            .createInstance(Components.interfaces.nsIMessenger);
 
 /**
  * Global variables, need to be re-initialized every time mostly because we need to release them when the window close
  */
 var gHideMenus;
 var gMsgCompose;
 var gAccountManager;
-var gIOService;
 var gPromptService;
 var gWindowLocked;
 var gContentChanged;
 var gAutoSaving;
 var gCurrentIdentity;
 var defaultSaveOperation;
 var gSendOrSaveOperationInProgress;
 var gCloseWindowAfterSave;
-var gIsOffline;
 var gSessionAdded;
 var gCurrentAutocompleteDirectory;
 var gSetupLdapAutocomplete;
 var gLDAPSession;
 var gSavedSendNowKey;
 var gSendFormat;
 var gLogComposePerformance;
 
@@ -125,28 +123,26 @@ var gAutoSaveTimeout;
 var gAutoSaveKickedIn;
 var gEditingDraft;
 
 const kComposeAttachDirPrefName = "mail.compose.attach.dir";
 
 function InitializeGlobalVariables()
 {
   gAccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
-  gIOService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
   gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
 
   gMsgCompose = null;
   gWindowLocked = false;
   gContentChanged = false;
   gCurrentIdentity = null;
   defaultSaveOperation = "draft";
   gSendOrSaveOperationInProgress = false;
   gAutoSaving = false;
   gCloseWindowAfterSave = false;
-  gIsOffline = gIOService.offline;
   gSessionAdded = false;
   gCurrentAutocompleteDirectory = null;
   gSetupLdapAutocomplete = false;
   gLDAPSession = null;
   gSavedSendNowKey = null;
   gSendFormat = nsIMsgCompSendFormat.AskUser;
   gSendDefaultCharset = null;
   gCharsetTitle = null;
@@ -161,17 +157,16 @@ function InitializeGlobalVariables()
   gReceiptOptionChanged = false;
   gAttachVCardOptionChanged = false;
 }
 InitializeGlobalVariables();
 
 function ReleaseGlobalVariables()
 {
   gAccountManager = null;
-  gIOService = null;
   gPromptService = null;
   gCurrentIdentity = null;
   gCurrentAutocompleteDirectory = null;
   if (gLDAPSession) {
     gLDAPSession = null;
     Components.utils.forceGC();
   }
   gCharsetConvertManager = null;
@@ -454,17 +449,17 @@ var defaultController =
       case "cmd_saveAsTemplate":
       case "cmd_sendButton":
       case "cmd_sendLater":
       case "cmd_printSetup":
       case "cmd_print":
       case "cmd_sendWithCheck":
         return !gWindowLocked;
       case "cmd_sendNow":
-        return !(gWindowLocked || gIsOffline);
+        return !(gWindowLocked || Services.io.offline);
       case "cmd_quit":
         return true;
 
       //Edit Menu
       case "cmd_delete":
         return MessageGetNumSelectedAttachments() > 0;
       case "cmd_renameAttachment":
         return MessageGetNumSelectedAttachments() == 1;
@@ -503,17 +498,17 @@ var defaultController =
       case "cmd_close"              : DoCommandClose();       break;
       case "cmd_saveDefault"        : Save();                 break;
       case "cmd_saveAsFile"         : SaveAsFile(true);       break;
       case "cmd_saveAsDraft"        : SaveAsDraft();          break;
       case "cmd_saveAsTemplate"     : SaveAsTemplate();       break;
       case "cmd_sendButton"         :
         if (defaultController.isCommandEnabled(command))
         {
-          if (gIOService && gIOService.offline)
+          if (Services.io.offline)
             SendMessageLater();
           else
             SendMessage();
         }
         break;
       case "cmd_sendNow"            : if (defaultController.isCommandEnabled(command)) SendMessage();          break;
       case "cmd_sendWithCheck"   : if (defaultController.isCommandEnabled(command)) SendMessageWithCheck();          break;
       case "cmd_sendLater"          : if (defaultController.isCommandEnabled(command)) SendMessageLater();     break;
@@ -661,39 +656,34 @@ function updateOptionItems()
 {
   goUpdateCommand("cmd_quoteMessage");
 }
 
 var messageComposeOfflineObserver = {
   observe: function(subject, topic, state) {
     // sanity checks
     if (topic != "network:offline-status-changed") return;
-    if (state == "offline")
-      gIsOffline = true;
-    else
-      gIsOffline = false;
-    MessageComposeOfflineStateChanged(gIsOffline);
+    MessageComposeOfflineStateChanged(state == "offline");
 
     try {
         setupLdapAutocompleteSession();
     } catch (ex) {
         // catch the exception and ignore it, so that if LDAP setup
         // fails, the entire compose window stuff doesn't get aborted
     }
   }
 }
 
 function AddMessageComposeOfflineObserver()
 {
   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
   observerService.addObserver(messageComposeOfflineObserver, "network:offline-status-changed", false);
 
-  gIsOffline = gIOService.offline;
   // set the initial state of the send button
-  MessageComposeOfflineStateChanged(gIsOffline);
+  MessageComposeOfflineStateChanged(Services.io.offline);
 }
 
 function RemoveMessageComposeOfflineObserver()
 {
   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
   observerService.removeObserver(messageComposeOfflineObserver,"network:offline-status-changed");
 }
 
@@ -809,17 +799,17 @@ function setupLdapAutocompleteSession()
         if (LDAPSession) {
           try {
             LDAPSession = LDAPSession.createInstance()
                 .QueryInterface(Components.interfaces.nsILDAPAutoCompleteSession);
           } catch (ex) {dump ("ERROR: Cannot get the LDAP autocomplete session\n" + ex + "\n");}
         }
     }
 
-    if (autocompleteDirectory && !gIsOffline) {
+    if (autocompleteDirectory && !Services.io.offline) {
         // Add observer on the directory server we are autocompleting against
         // only if current server is different from previous.
         // Remove observer if current server is different from previous
         gCurrentAutocompleteDirectory = autocompleteDirectory;
         if (prevAutocompleteDirectory) {
           if (prevAutocompleteDirectory != gCurrentAutocompleteDirectory) {
             RemoveDirectorySettingsObserver(prevAutocompleteDirectory);
             AddDirectorySettingsObserver();
@@ -830,20 +820,18 @@ function setupLdapAutocompleteSession()
 
         // fill in the session params if there is a session
         //
         if (LDAPSession) {
             let url = sPrefs.getComplexValue(autocompleteDirectory +".uri",
               Components.interfaces.nsISupportsString).data;
 
             LDAPSession.serverURL =
-              Components.classes["@mozilla.org/network/io-service;1"]
-                        .getService(Components.interfaces.nsIIOService)
-                        .newURI(url, null, null)
-                        .QueryInterface(Components.interfaces.nsILDAPURL);
+              Services.io.newURI(url, null, null)
+                         .QueryInterface(Components.interfaces.nsILDAPURL);
 
             // get the login to authenticate as, if there is one
             //
             try {
                 LDAPSession.login = sPrefs.getComplexValue(
                     autocompleteDirectory + ".auth.dn",
                     Components.interfaces.nsISupportsString).data;
             } catch (ex) {
@@ -1170,17 +1158,17 @@ function ComposeFieldsReady()
 // checks if the passed in string is a mailto url, if it is, generates nsIMsgComposeParams
 // for the url and returns them.
 function handleMailtoArgs(mailtoUrl)
 {
   // see if the string is a mailto url....do this by checking the first 7 characters of the string
   if (/^mailto:/i.test(mailtoUrl))
   {
     // if it is a mailto url, turn the mailto url into a MsgComposeParams object....
-    var uri = gIOService.newURI(mailtoUrl, null, null);
+    var uri = Services.io.newURI(mailtoUrl, null, null);
 
     if (uri)
       return sMsgComposeService.getParamsForMailto(uri);
   }
 
   return null;
 }
 
@@ -1951,18 +1939,18 @@ function SendMessageWithCheck()
         if (buttonPressed != 0) {
             return;
         }
         if (checkValue.value) {
             sPrefs.setBoolPref("mail.warn_on_send_accel_key", false);
         }
     }
 
-  GenericSendMessage(gIsOffline ? nsIMsgCompDeliverMode.Later
-                                 : nsIMsgCompDeliverMode.Now);
+  GenericSendMessage(Services.io.offline ? nsIMsgCompDeliverMode.Later
+                                         : nsIMsgCompDeliverMode.Now);
 }
 
 function SendMessageLater()
 {
   dump("SendMessageLater from XUL\n");
   GenericSendMessage(nsIMsgCompDeliverMode.Later);
 }
 
@@ -2571,19 +2559,17 @@ function AttachFiles(attachments)
 
   while (attachments.hasMoreElements()) {
     var currentFile = attachments.getNext().QueryInterface(Components.interfaces.nsILocalFile);
 
     if (!firstAttachedFile) {
       firstAttachedFile = currentFile;
     }
 
-    var ioService = Components.classes["@mozilla.org/network/io-service;1"]
-    ioService = ioService.getService(Components.interfaces.nsIIOService);
-    var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
+    var fileHandler = Services.io.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
     var currentAttachment = fileHandler.getURLSpecFromFile(currentFile);
 
     if (!DuplicateFileCheck(currentAttachment)) {
       var attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"].createInstance(Components.interfaces.nsIMsgAttachment);
       attachment.url = currentAttachment;
       attachment.size = currentFile.fileSize;
       AddAttachment(attachment);
       gContentChanged = true;
@@ -3082,19 +3068,17 @@ var attachmentBucketObserver = {
         let rawData = item.data;
 
         if (item.flavour.contentType == "text/x-moz-url" ||
             item.flavour.contentType == "text/x-moz-message" ||
             item.flavour.contentType == "application/x-moz-file")
         {
           if (item.flavour.contentType == "application/x-moz-file")
           {
-            let ioService = Components.classes["@mozilla.org/network/io-service;1"]
-                            .getService(Components.interfaces.nsIIOService);
-            let fileHandler = ioService.getProtocolHandler("file")
+            let fileHandler = Services.io.getProtocolHandler("file")
                               .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
             size = rawData.fileSize;
             rawData = fileHandler.getURLSpecFromFile(rawData);
           }
           else if (item.flavour.contentType == "text/x-moz-message")
           {
             size = gMessenger.messageServiceFromURI(rawData)
                              .messageURIToMsgHdr(rawData).messageSize;
@@ -3120,17 +3104,17 @@ var attachmentBucketObserver = {
               // if this is a url (or selected text)
               // see if it's a valid url by checking
               // if we can extract a scheme
               // using the ioservice
               //
               // also skip mailto:, since it doesn't make sense
               // to attach and send mailto urls
               try {
-                let scheme = gIOService.extractScheme(rawData);
+                let scheme = Services.io.extractScheme(rawData);
                 // don't attach mailto: urls
                 if (scheme == "mailto")
                   isValid = false;
               }
               catch (ex) {
                 isValid = false;
               }
             }
--- a/suite/mailnews/mail-offline.js
+++ b/suite/mailnews/mail-offline.js
@@ -157,24 +157,16 @@ function PromptDownloadMessages()
       gMailOfflinePrefs.setIntPref("offline.download.download_messages", 2*!checkValue.value);
       gOfflineManager.synchronizeForOffline(false, false, false, true, msgWindow);
       return true;
     }
   }
   return false;
 }
 
-// online?
-function CheckOnline()
-{
-  var ioService = Components.classes["@mozilla.org/network/io-service;1"]
-                         .getService(Components.interfaces.nsIIOService);
-  return (!ioService.offline);
-}
-
 // Init Pref Service & Offline Manager
 function InitServices()
 {
   if (!gMailOfflinePrefs) 
     GetMailOfflinePrefs();
 
   if (!gOfflineManager) 
     GetOfflineMgrService();
@@ -188,27 +180,22 @@ function GetOfflineMgrService()
         .getService(Components.interfaces.nsIMsgOfflineManager);
   }
 }
 
 // This function must always return false to prevent toggling of offline state because
 // we change the offline state ourselves
 function MailCheckBeforeOfflineChange()
 {
-  var ioService = Components.classes["@mozilla.org/network/io-service;1"]
-                            .getService(Components.interfaces.nsIIOService);
-
-  var goingOnline = ioService.offline;
-
   InitServices();
 
   var prefSendUnsentMessages = gMailOfflinePrefs.getIntPref("offline.send.unsent_messages");
   var prefDownloadMessages   = gMailOfflinePrefs.getIntPref("offline.download.download_messages");
 
-  if(goingOnline) {
+  if (Services.io.offline) {
     switch(prefSendUnsentMessages) { 
     case 0:
       if(CheckForUnsentMessages()) { 
         if(! PromptSendMessages()) 
           return false;
       }
       else 
         gOfflineManager.goOnline(false /* sendUnsentMessages */, 
--- a/suite/mailnews/mail3PaneWindowCommands.js
+++ b/suite/mailnews/mail3PaneWindowCommands.js
@@ -233,17 +233,17 @@ var DefaultController =
       case "cmd_close":
       case "cmd_selectAll":
       case "cmd_selectThread":
       case "cmd_selectFlagged":
 				return true;
       case "cmd_downloadFlagged":
       case "cmd_downloadSelected":
       case "cmd_synchronizeOffline":
-        return(CheckOnline());
+        return !Services.io.offline;
 
       case "cmd_watchThread":
       case "cmd_killThread":
       case "cmd_killSubthread":
       case "cmd_cancel":
         return(isNewsURI(GetFirstSelectedMessage()));
 
 			default:
@@ -459,21 +459,22 @@ var DefaultController =
         return IsEmptyTrashEnabled();
       case "cmd_compactFolder":
         return IsCompactFolderEnabled();
       case "cmd_setFolderCharset":
         return IsFolderCharsetEnabled();
       case "cmd_close":
         return true;
       case "cmd_downloadFlagged":
-        return(CheckOnline());
+        return !Services.io.offline;
       case "cmd_downloadSelected":
-        return (IsFolderSelected() && CheckOnline() && GetNumSelectedMessages() > 0);
+        return IsFolderSelected() && !Services.io.offline &&
+               GetNumSelectedMessages() > 0;
       case "cmd_synchronizeOffline":
-        return CheckOnline();
+        return !Services.io.offline;
       case "cmd_settingsOffline":
         return IsAccountOfflineEnabled();
       default:
         return false;
     }
     return false;
   },
 
--- a/suite/mailnews/mailContextMenus.js
+++ b/suite/mailnews/mailContextMenus.js
@@ -348,24 +348,21 @@ function SetupCompactMenuItem(folder, nu
   if (canCompact)
     SetMenuItemLabel("folderPaneContext-compact", gMessengerBundle.getString("compactFolder"));
 }
 
 function SetupNewMenuItem(folder, numSelected, isServer, serverType, specialFolder)
 {
   var isInbox = specialFolder == "Inbox";
 
-  const ioService = Components.classes["@mozilla.org/network/io-service;1"]
-                              .getService(Components.interfaces.nsIIOService);
-
   let showNew = (numSelected <= 1 && serverType != "nntp" &&
                  folder.canCreateSubfolders) || isInbox;
   ShowMenuItem("folderPaneContext-new", showNew);
   EnableMenuItem("folderPaneContext-new",
-                 folder.server.type != "imap" || !ioService.offline);
+                 folder.server.type != "imap" || !Services.io.offline);
   if (showNew)
   {
     if (isServer || isInbox)
       SetMenuItemLabel("folderPaneContext-new", gMessengerBundle.getString("newFolder"));
     else
       SetMenuItemLabel("folderPaneContext-new", gMessengerBundle.getString("newSubfolder"));
   }
 }
--- a/suite/mailnews/mailTasksOverlay.js
+++ b/suite/mailnews/mailTasksOverlay.js
@@ -226,19 +226,17 @@ function MailTasksOnLoad(aEvent)
   // initialize biff state
   const kObserverService = Components.classes["@mozilla.org/observer-service;1"]
                                      .getService(Components.interfaces.nsIObserverService);
   kObserverService.addObserver(biffObserver, BIFF_TOPIC, false);
   biffObserver.observe(null, BIFF_TOPIC, null); // init mini-mail icon
   addEventListener("unload", MailTasksOnUnload, false);
 
   // don't try to biff if offline, but do so silently
-  const kIOService = Components.classes["@mozilla.org/network/io-service;1"]
-                               .getService(Components.interfaces.nsIIOService);
-  if (kIOService.offline)
+  if (Services.io.offline)
     return;
 
   // Performing biff here will mean performing it for all new windows opened!
   // This might make non-users of mailnews unhappy...
   const kPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
                                 .getService(Components.interfaces.nsIPrefService)
                                 .getBranch(null);
   if (!kPrefBranch.getBoolPref("mail.biff.on_new_window"))
--- a/suite/mailnews/mailWindow.js
+++ b/suite/mailnews/mailWindow.js
@@ -543,17 +543,17 @@ function loadStartPage()
 // prompt if offline.
 function OpenInboxForServer(server)
 {
     try {
         ShowThreadPane();
         var inboxFolder = GetInboxFolder(server);
         SelectFolder(inboxFolder.URI);
 
-        if(CheckOnline()) {
+        if (!Services.io.offline) {
             if (server.type != "imap")
                 GetMessagesForInboxOnServer(server);
         }
         else if (DoGetNewMailWhenOffline()) {
                 GetMessagesForInboxOnServer(server);
         }
     }
     catch (ex) {
--- a/suite/mailnews/mailWindowOverlay.js
+++ b/suite/mailnews/mailWindowOverlay.js
@@ -125,22 +125,20 @@ function menu_new_init()
     return;
   var msgFolder = folderArray[0];
   var isServer = msgFolder.isServer;
   var serverType = msgFolder.server.type;
   var canCreateNew = msgFolder.canCreateSubfolders;
   var isInbox = msgFolder.isSpecialFolder(
                   Components.interfaces.nsMsgFolderFlags.Inbox, false);
   var isIMAPFolder = serverType == "imap";
-  var ioService = Components.classes["@mozilla.org/network/io-service;1"]
-                         .getService(Components.interfaces.nsIIOService);
   var showNew = ((serverType != 'nntp') && canCreateNew) || isInbox;
   ShowMenuItem("menu_newFolder", showNew);
   ShowMenuItem("menu_newVirtualFolder", showNew);
-  EnableMenuItem("menu_newFolder", !isIMAPFolder || !ioService.offline);
+  EnableMenuItem("menu_newFolder", !isIMAPFolder || !Services.io.offline);
   EnableMenuItem("menu_newVirtualFolder", true);
   if (showNew)
     SetMenuItemLabel("menu_newFolder", gMessengerBundle.getString((isServer || isInbox) ? "newFolderMenuItem" : "newSubfolderMenuItem"));
 }
 
 function goUpdateMailMenuItems(commandset)
 {
 //  dump("Updating commands for " + commandset.id + "\n");
@@ -973,71 +971,58 @@ function GetMessagesForInboxOnServer(ser
     inboxFolder = server.rootFolder;
 
   GetNewMessages([inboxFolder], server);
 }
 
 function MsgGetMessage()
 {
   // if offline, prompt for getting messages
-  if(CheckOnline())
+  if (DoGetNewMailWhenOffline())
     GetFolderMessages();
-  else if (DoGetNewMailWhenOffline())
-      GetFolderMessages();
 }
 
 function MsgGetMessagesForAllServers(defaultServer)
 {
   MailTasksGetMessagesForAllServers(true, msgWindow, defaultServer);
 }
 
 /**
   * Get messages for all those accounts which have the capability
   * of getting messages and have session password available i.e.,
   * curretnly logged in accounts.
   * if offline, prompt for getting messages.
   */
 function MsgGetMessagesForAllAuthenticatedAccounts()
 {
-  if (CheckOnline() || DoGetNewMailWhenOffline())
+  if (DoGetNewMailWhenOffline())
     MailTasksGetMessagesForAllServers(false, msgWindow, null);
 }
 
 /**
   * Get messages for the account selected from Menu dropdowns.
   * if offline, prompt for getting messages.
   */
 function MsgGetMessagesForAccount(aEvent)
 {
   if (!aEvent)
     return;
 
-  if(CheckOnline())
+  if (DoGetNewMailWhenOffline())
     GetMessagesForAccount(aEvent);
-  else if (DoGetNewMailWhenOffline()) 
-      GetMessagesForAccount(aEvent);
-    }
+}
 
 // if offline, prompt for getNextNMessages
 function MsgGetNextNMessages()
 {
-  var folder;
-  
-  if(CheckOnline()) {
-    folder = GetFirstSelectedMsgFolder();
+  if (DoGetNewMailWhenOffline()) {
+    var folder = GetFirstSelectedMsgFolder();
     if(folder) 
       GetNextNMessages(folder);
   }
-
-  else if(DoGetNewMailWhenOffline()) {
-      folder = GetFirstSelectedMsgFolder();
-      if(folder) {
-        GetNextNMessages(folder);
-      }
-  }
 }
 
 function MsgDeleteMessage(aReallyDelete)
 {
   // If the user deletes a message before its mark as read timer goes off,
   // we should mark it as read (unless the user changed the pref). This
   // ensures that we clear the biff indicator from the system tray when
   // the user deletes the new message.
@@ -2069,17 +2054,17 @@ function ToggleInlineAttachment(target)
 function MsgStop()
 {
     StopUrls();
 }
 
 function MsgSendUnsentMsgs()
 {
   // if offline, prompt for sendUnsentMessages
-  if(CheckOnline()) {
+  if (!Services.io.offline) {
     SendUnsentMessages();    
   }
   else {
     var option = PromptSendMessagesOffline();
     if(option == 0) {
       if (!gOfflineManager) 
         GetOfflineMgrService();
       gOfflineManager.goOnline(false /* sendUnsentMessages */, 
@@ -2323,16 +2308,19 @@ function InitPrompts()
     gPromptService = gPromptService.QueryInterface(Components.interfaces.nsIPromptService);
   }
   if (!gOfflinePromptsBundle) 
     gOfflinePromptsBundle = document.getElementById("bundle_offlinePrompts");
 }
 
 function DoGetNewMailWhenOffline()
 {
+  if (!Services.io.offline)
+    return true;
+
   var sendUnsent = false;
   var goOnline = PromptGetMessagesOffline() == 0;
   if (goOnline)
   {
     if (this.CheckForUnsentMessages != undefined && CheckForUnsentMessages())
     {
       var sendUnsentPref = gPrefBranch.getIntPref("offline.send.unsent_messages");
       switch (sendUnsentPref)
--- a/suite/mailnews/messageWindow.js
+++ b/suite/mailnews/messageWindow.js
@@ -681,17 +681,17 @@ var MessageWindowController =
       case "cmd_close":
       case "cmd_settingsOffline":
       case "cmd_createFilterFromPopup":
       case "cmd_createFilterFromMenu":
         return true;
       case "cmd_synchronizeOffline":
       case "cmd_downloadFlagged":
       case "cmd_downloadSelected":
-        return CheckOnline();
+        return !Services.io.offline;
       default:
         return false;
     }
   },
 
 	isCommandEnabled: function(command)
 	{
     var loadedFolder;
@@ -768,17 +768,17 @@ var MessageWindowController =
       case "button_getNewMessages":
       case "cmd_getMsgsForAuthAccounts":
 				return IsGetNewMessagesEnabled();
 			case "cmd_getNextNMessages":
 				return IsGetNextNMessagesEnabled();		
 			case "cmd_downloadFlagged":
 			case "cmd_downloadSelected":
       case "cmd_synchronizeOffline":
-                return CheckOnline();
+        return !Services.io.offline;
 			case "cmd_settingsOffline":
                 return IsAccountOfflineEnabled();
 			case "cmd_close":
 			case "cmd_nextMsg":
       case "button_next":
 			case "cmd_nextUnreadMsg":
       case "cmd_nextFlaggedMsg":
 			case "cmd_nextUnreadThread":
--- a/suite/mailnews/msgHdrViewOverlay.js
+++ b/suite/mailnews/msgHdrViewOverlay.js
@@ -66,17 +66,16 @@ var gCollectAddressTimer = null;
 var gBuildAttachmentsForCurrentMsg = false;
 var gBuildAttachmentPopupForCurrentMsg = true;
 var gBuiltExpandedView = false;
 var gBuiltCollapsedView = false;
 var gMessengerBundle;
 
 // Globals for setFromBuddyIcon().
 var gFileHandler;
-var gIOService = null;
 var gProfileDirURL;
 
 var gExtraExpandedHeaders;
 // Show the friendly display names for people I know, instead of the name + email address.
 var gShowCondensedEmailAddresses;
 
 var msgHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"]
                                 .getService(Components.interfaces.nsIMsgHeaderParser);
@@ -471,20 +470,18 @@ var messageHeaderSink = {
         var displayHtmlAs = pref.getIntPref("mailnews.display.html_as");
         if (inlineAttachments && !displayHtmlAs)
           return;
       }
 
       var size = null;
       if (isExternalAttachment)
       {
-        var fileHandler = Components.classes["@mozilla.org/network/io-service;1"]
-                                    .getService(Components.interfaces.nsIIOService)
-                                    .getProtocolHandler("file")
-                                    .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
+        var fileHandler = Services.io.getProtocolHandler("file")
+                                     .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
         try
         {
           size = fileHandler.getFileFromURLSpec(url).fileSize;
         }
         catch(e)
         {
           dump("Couldn't open external attachment!");
         }
@@ -1068,26 +1065,25 @@ function setFromBuddyIcon(email)
     var card = getCardForAddress(email);
     if (card)
     {
       // For now, retrieve the screen name only.
       var iconURLStr = card.getProperty("_AimScreenName", "");
       if (iconURLStr)
       {
         // Lazily create these globals.
-        if (!gIOService) {
-          gIOService = Components.classes["@mozilla.org/network/io-service;1"]
-                                 .getService(Components.interfaces.nsIIOService);
-          gFileHandler = gIOService.getProtocolHandler("file")
-                                   .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
+        if (!gFileHandler)
+        {
+          gFileHandler = Services.io.getProtocolHandler("file")
+                                    .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
 
           var profileDir = Components.classes["@mozilla.org/file/directory_service;1"]
                                      .getService(Components.interfaces.nsIProperties)
                                      .get("ProfD", Components.interfaces.nsIFile);
-          gProfileDirURL = gIOService.newFileURI(profileDir);
+          gProfileDirURL = Services.io.newFileURI(profileDir);
         }
 
         // If we did have a buddy icon on disk for this screenname,
         // this would be the file url spec for it.
         iconURLStr = gProfileDirURL.spec + "/NIM/" + myScreenName
                                          + "/picture/" + iconURLStr + ".gif";
 
         // check if the file exists
@@ -1273,17 +1269,18 @@ createNewAttachmentInfo.prototype.detach
                              encodeURIComponent(this.displayName),
                              this.uri,
                              true);
 }
 
 function CanDetachAttachments()
 {
   var uri = GetLoadedMessage();
-  var canDetach = !IsNewsMessage(uri) && (!IsImapMessage(uri) || CheckOnline());
+  var canDetach = !IsNewsMessage(uri) &&
+                  (!IsImapMessage(uri) || !Services.io.offline);
   if (canDetach && ("content-type" in currentHeaderData))
     canDetach = !ContentTypeIsSMIME(currentHeaderData["content-type"].headerValue);
   return canDetach;
 }
 
 /** Return true if the content type is an S/MIME one. */
 function ContentTypeIsSMIME(contentType)
 {
--- a/suite/mailnews/msgMail3PaneWindow.js
+++ b/suite/mailnews/msgMail3PaneWindow.js
@@ -938,17 +938,17 @@ function loadStartFolder(initialUri)
     catch(ex)
     {
       dump(ex);
       dump('Exception in LoadStartFolder caused by no default account.  We know about this\n');
     }
 
     MsgGetMessagesForAllServers(defaultServer);
 
-    if (CheckForUnsentMessages() && CheckOnline())
+    if (CheckForUnsentMessages() && !Services.io.offline)
     {
         InitPrompts();
         InitServices();
 
         var sendUnsentWhenGoingOnlinePref = pref.getIntPref("offline.send.unsent_messages");
         if(gPromptService && sendUnsentWhenGoingOnlinePref == 0) // pref is "ask"
         {
           var buttonPressed = gPromptService.confirmEx(window,
--- a/suite/mailnews/phishingDetector.js
+++ b/suite/mailnews/phishingDetector.js
@@ -104,18 +104,17 @@ function isPhishingURL(aLinkNode, aSilen
   var href = aHref || aLinkNode.href;
   if (!href)
     return false;
 
   var linkTextURL = {};
   var unobscuredHostName = {};
   var isPhishingURL = false;
 
-  var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
-  var hrefURL = ioService.newURI(href, null, null);
+  var hrefURL = Services.io.newURI(href, null, null);
   
   // only check for phishing urls if the url is an http or https link.
   // this prevents us from flagging imap and other internally handled urls
   if (hrefURL.schemeIs('http') || hrefURL.schemeIs('https'))
   {
     unobscuredHostName.value = hrefURL.host;
 
     if (hostNameIsIPAddress(hrefURL.host, unobscuredHostName) && !isLocalIPAddress(unobscuredHostName))
@@ -145,18 +144,17 @@ function misMatchedHostWithLinkText(aLin
   linkNodeText = linkNodeText.replace(/ /g, "");
 
   // only worry about http and https urls
   if (linkNodeText)
   {
     // does the link text look like a http url?
      if (linkNodeText.search(/(^http:|^https:)/) != -1)
      {
-       var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
-       var linkTextURL  = ioService.newURI(linkNodeText, null, null);
+       var linkTextURL  = Services.io.newURI(linkNodeText, null, null);
        aLinkTextURL.value = linkTextURL;
        // compare hosts, but ignore possible www. prefix
        return !(aHrefURL.host.replace(/^www\./, "") == aLinkTextURL.value.host.replace(/^www\./, ""));
      }
   }
 
   return false;
 }
--- a/suite/mailnews/prefs/pref-notifications.js
+++ b/suite/mailnews/prefs/pref-notifications.js
@@ -37,35 +37,32 @@
 
 // The contents of this file will be loaded into the scope of the object
 // <prefpane id="notifications_pane">!
 
 const nsIFileProtocolHandler = Components.interfaces.nsIFileProtocolHandler;
 
 var gSound = null;
 var gSoundUrlPref = null;
-var gIOService = null;
 var gFileHandler = null;
 
 function Startup()
 {
   // if we don't have the alert service, hide the pref UI for using alerts to notify on new mail
   // see bug #158711
   var newMailNotificationAlertUI = document.getElementById("newMailNotificationAlert");
   newMailNotificationAlertUI.hidden = !("@mozilla.org/alerts-service;1" in Components.classes);
   if (!/Mac/.test(navigator.platform))
     document.getElementById('newMailNotificationBounce').setAttribute("hidden", true);
   // show tray icon option currently available for Windows only
   var newMailNotificationTrayIconPref = document.getElementById("newMailNotificationTrayIcon");
   newMailNotificationTrayIconPref.hidden = !/^Win/.test(navigator.platform);
 
-  gIOService = Components.classes["@mozilla.org/network/io-service;1"]
-                         .getService(Components.interfaces.nsIIOService);
-  gFileHandler = gIOService.getProtocolHandler("file")
-                           .QueryInterface(nsIFileProtocolHandler);
+  gFileHandler = Services.io.getProtocolHandler("file")
+                            .QueryInterface(nsIFileProtocolHandler);
   gSoundUrlPref = document.getElementById("mail.biff.play_sound.url");
 
   PlaySoundCheck(document.getElementById("mail.biff.play_sound").value);
 }
 
 function PlaySoundCheck(aPlaySound)
 {
   let playSoundType = document.getElementById("mail.biff.play_sound.type").value;
@@ -109,14 +106,14 @@ function ReadSoundLocation(aElement)
 function PlaySound()
 {
   const nsISound = Components.interfaces.nsISound;
   if (!gSound)
     gSound = Components.classes["@mozilla.org/sound;1"]
                        .createInstance(nsISound);
   var soundURL = gSoundUrlPref.value;
   if (soundURL)
-    gSound.play(gIOService.newURI(soundURL, null, null));
+    gSound.play(Services.io.newURI(soundURL, null, null));
   else if (/Mac/.test(navigator.platform))
     gSound.beep();
   else
     gSound.playEventSound(nsISound.EVENT_NEW_MAIL_RECEIVED);
 }