Bug 722187 - convert mailnews/addrbook/ to Services.jsm and MailServices.js. r=mconley
☠☠ backed out by de184df942a7 ☠ ☠
authoraceman <acelists@atlas.sk>
Tue, 14 Feb 2012 12:27:45 +0000
changeset 10832 59943cb43b167bbf343d0dfd53dfee5bb7404d30
parent 10831 7150237ed78f8477d25e2e14b57092028a4b1284
child 10833 9eddb2d0b431bfeb401c58cf0f80f1ce6ffd8b0b
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs722187
Bug 722187 - convert mailnews/addrbook/ to Services.jsm and MailServices.js. r=mconley
mailnews/addrbook/content/abAddressBookNameDialog.js
mailnews/addrbook/content/abDragDrop.js
mailnews/addrbook/content/abMailListDialog.js
mailnews/addrbook/content/addrbookWidgets.xml
mailnews/addrbook/prefs/content/pref-directory-add.js
mailnews/addrbook/prefs/content/pref-editdirectories.js
mailnews/addrbook/src/nsAbAutoCompleteMyDomain.js
mailnews/addrbook/src/nsAbAutoCompleteSearch.js
mailnews/addrbook/src/nsAbLDAPAttributeMap.js
--- a/mailnews/addrbook/content/abAddressBookNameDialog.js
+++ b/mailnews/addrbook/content/abAddressBookNameDialog.js
@@ -31,42 +31,41 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+Components.utils.import("resource:///modules/mailServices.js");
+
 var gOkButton;
 var gNameInput;
 var gDirectory = null;
 
 const kPersonalAddressbookURI = "moz-abmdbdirectory://abook.mab";
 const kCollectedAddressbookURI = "moz-abmdbdirectory://history.mab";
 const kPABDirectory = 2; // defined in nsDirPrefs.h
 
 function abNameOnLoad()
 {
-  // Get the document elements.  
+  // Get the document elements.
   gOkButton = document.documentElement.getButton('accept');
   gNameInput = document.getElementById('name');
 
   // look in arguments[0] for parameters to see if we have a directory or not
   if ("arguments" in window && window.arguments[0] &&
       "selectedDirectory" in window.arguments[0]) {
     gDirectory = window.arguments[0].selectedDirectory;
     gNameInput.value = gDirectory.dirName;
   }
 
   // Work out the window title (if we have a directory specified, then it's a
   // rename).
-  var strBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
-    .getService(Components.interfaces.nsIStringBundleService);
-
   var bundle = document.getElementById("bundle_addressBook");
 
   document.title = bundle.getString(gDirectory ?
     'renameAddressBookTitle' : 'newAddressBookTitle');
 
   if (gDirectory &&
      (gDirectory.URI == kCollectedAddressbookURI ||
        gDirectory.URI == kPersonalAddressbookURI)) {
@@ -85,19 +84,17 @@ function abNameOKButton()
 {
   var newName = gNameInput.value.trim();
 
   // Either create a new directory or update an existing one depending on what
   // we were given when we started.
   if (gDirectory)
     gDirectory.dirName = newName;
   else
-    Components.classes["@mozilla.org/abmanager;1"]
-              .getService(Components.interfaces.nsIAbManager)
-              .newAddressBook(newName, "", kPABDirectory);
+    MailServices.ab.newAddressBook(newName, "", kPABDirectory);
 
   return true;
 }
 
 function abNameDoOkEnabling()
 {
   gOkButton.disabled = !/\S/.test(gNameInput.value);
 }
--- a/mailnews/addrbook/content/abDragDrop.js
+++ b/mailnews/addrbook/content/abDragDrop.js
@@ -76,21 +76,21 @@ var abResultsPaneObserver = {
 
   onDragExit: function (aEvent, aDragSession)
     {
     },
 
   onDragOver: function (aEvent, aFlavour, aDragSession)
     {
     },
- 
+
   getSupportedFlavours: function ()
-	{
-     return null;
-  }
+    {
+      return null;
+    }
 };
 
 
 var dragService = Components.classes["@mozilla.org/widget/dragservice;1"]
                             .getService().QueryInterface(Components.interfaces.nsIDragService);
 
 var abDirTreeObserver = {
   /**
@@ -131,17 +131,17 @@ var abDirTreeObserver = {
     if (targetURI == srcURI)
       return false;
 
     // determine if we dragging from a mailing list on a directory x to the parent (directory x).
     // if so, don't allow the drop
     if (srcURI.substring(0, targetURI.length) == targetURI)
       return false
 
-    // check if we can write to the target directory 
+    // check if we can write to the target directory
     // e.g. LDAP is readonly currently
     var targetDirectory = GetDirectoryFromURI(targetURI);
 
     if (targetDirectory.readOnly)
       return false;
 
     var dragSession = dragService.getCurrentSession();
     if (!dragSession)
@@ -378,17 +378,17 @@ function DragAddressOverTargetControl(ev
     }
   }
   dragSession.canDrop = canDrop;
 }
 
 function DropAddressOverTargetControl(event)
 {
   var dragSession = gDragService.getCurrentSession();
-  
+
   var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
   trans.addDataFlavor("text/x-moz-address");
 
   for ( var i = 0; i < dragSession.numDropItems; ++i )
   {
     dragSession.getData ( trans, i );
     var dataObj = new Object();
     var bestFlavor = new Object();
@@ -398,20 +398,20 @@ function DropAddressOverTargetControl(ev
     try
     {
       trans.getAnyTransferData ( bestFlavor, dataObj, len);
     }
     catch (ex)
     {
       continue;
     }
- 
-    if ( dataObj )  
+
+    if ( dataObj )
       dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsString);
-    if ( !dataObj ) 
+    if ( !dataObj )
       continue;
 
     // pull the address out of the data object
     var address = dataObj.data.substring(0, len.value);
     if (!address)
       continue;
 
     DropRecipient(address);
--- a/mailnews/addrbook/content/abMailListDialog.js
+++ b/mailnews/addrbook/content/abMailListDialog.js
@@ -36,18 +36,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 top.MAX_RECIPIENTS = 1;
 var inputElementType = "";
 
 var gListCard;
 var gEditList;
 var oldListName = "";
-var gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
-var gHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser);
 var gLoadListeners = [];
 var gSaveListeners = [];
 
 try
 {
   var gDragService = Components.classes["@mozilla.org/widget/dragservice;1"]
                                .getService(Components.interfaces.nsIDragService);
 }
@@ -61,22 +59,19 @@ function handleKeyPress(element, event)
   if (element.value != "" && event.keyCode == 13) {
     event.stopPropagation();
     event.preventDefault();
   }
 }
 
 function mailingListExists(listname)
 {
-  var addressbook = Components.classes["@mozilla.org/abmanager;1"]
-                              .getService(Components.interfaces.nsIAbManager);
-
-  if (addressbook.mailListNameExists(listname))
+  if (MailServices.ab.mailListNameExists(listname))
   {
-    gPromptService.alert(window, 
+    Services.prompt.alert(window,
       gAddressBookBundle.getString("mailListNameExistsTitle"),
       gAddressBookBundle.getString("mailListNameExistsMessage"));
     return true;
   }
   return false;
 }
 
 function GetListValue(mailList, doAdd)
@@ -113,17 +108,17 @@ function GetListValue(mailList, doAdd)
   var oldTotal = mailList.addressLists.length;
   var i = 1;
   var pos = 0;
   var inputField, fieldValue, cardproperty;
   while ((inputField = awGetInputElement(i)))
   {
 
     fieldValue = inputField.value;
-    
+
     if (doAdd || (!doAdd && pos >= oldTotal))
       cardproperty = Components.classes["@mozilla.org/addressbook/cardproperty;1"].createInstance();
     else
       cardproperty = mailList.addressLists.queryElementAt(pos, Components.interfaces.nsIAbCard);
 
     if (fieldValue == "")
     {
       if (!doAdd && cardproperty)
@@ -141,17 +136,17 @@ function GetListValue(mailList, doAdd)
     else if (cardproperty)
     {
       cardproperty = cardproperty.QueryInterface(Components.interfaces.nsIAbCard);
       if (cardproperty)
       {
         var addresses = {};
         var names = {};
         var fullNames = {};
-        var numAddresses = gHeaderParser.parseHeadersWithArray(fieldValue, addresses, names, fullNames);
+        var numAddresses = MailServices.headerParser.parseHeadersWithArray(fieldValue, addresses, names, fullNames);
         for (var j = 0; j < numAddresses; j++)
         {
           if (j > 0)
           {
             cardproperty = Components.classes["@mozilla.org/addressbook/cardproperty;1"].createInstance();
             cardproperty = cardproperty.QueryInterface(Components.interfaces.nsIAbCard);
           }
           cardproperty.primaryEmail = addresses.value[j];
@@ -296,18 +291,18 @@ function OnLoadEditList()
       var listbox = document.getElementById('addressingWidget');
       var newListBoxNode = listbox.cloneNode(false);
       var templateNode = listbox.getElementsByTagName("listitem")[0];
 
       top.MAX_RECIPIENTS = 0;
       for ( var i = 0;  i < total; i++ )
       {
         var card = gEditList.addressLists.queryElementAt(i, Components.interfaces.nsIAbCard);
-        var address = gHeaderParser.makeFullAddress(card.displayName,
-                                                    card.primaryEmail);
+        let address = MailServices.headerParser.makeFullAddress(card.displayName,
+                                                                card.primaryEmail);
         SetInputValue(address, newListBoxNode, templateNode);
       }
       var parent = listbox.parentNode;
       parent.replaceChild(newListBoxNode, listbox);
     }
   }
 
   // Is this directory read-only? If so, we now need to set all the fields to
@@ -625,9 +620,8 @@ function NotifyLoadListeners(aMailingLis
 
 /* Notifies all save listeners.
  */
 function NotifySaveListeners(aMailingList)
 {
   for (let i = 0; i < gSaveListeners.length; i++)
     gSaveListeners[i](aMailingList, document);
 }
-
--- a/mailnews/addrbook/content/addrbookWidgets.xml
+++ b/mailnews/addrbook/content/addrbookWidgets.xml
@@ -50,21 +50,18 @@
 
       <!-- Represents the nsIAbDirectory attribute used as the value of the
            parent menulist. Defaults to URI but can be e.g. dirPrefId -->
       <field name="_value">this.getAttribute("value") || "URI"</field>
 
       <constructor>
         <![CDATA[
           // Init the address book cache.
-          const nsIAbManager = Components.interfaces.nsIAbManager;
           const nsIAbDirectory = Components.interfaces.nsIAbDirectory;
-          var abManager = Components.classes["@mozilla.org/abmanager;1"]
-                                    .getService(nsIAbManager);
-          var directories = abManager.directories;
+          let directories = MailServices.ab.directories;
           while (directories && directories.hasMoreElements()) {
             var ab = directories.getNext();
             if (ab instanceof nsIAbDirectory && this._matches(ab))
               this._directories.push(ab);
           }
 
           this._directories.sort(this._compare);
 
@@ -82,28 +79,26 @@
 
           // Attempt to select the persisted or otherwise first directory.
           menulist.value = menulist.value;
           if (!menulist.selectedItem && this.hasChildNodes())
             menulist.selectedIndex = 0;
 
           const nsIAbListener = Components.interfaces.nsIAbListener;
           // Add a listener so we can update correctly if the list should change
-          abManager.addAddressBookListener(this,
-                                           nsIAbListener.itemAdded |
-                                           nsIAbListener.directoryRemoved |
-                                           nsIAbListener.itemChanged);
+          MailServices.ab.addAddressBookListener(this,
+                                                 nsIAbListener.itemAdded |
+                                                 nsIAbListener.directoryRemoved |
+                                                 nsIAbListener.itemChanged);
         ]]>
       </constructor>
 
       <destructor>
         <![CDATA[
-          Components.classes["@mozilla.org/abmanager;1"]
-                    .getService(Components.interfaces.nsIAbManager)
-                    .removeAddressBookListener(this);
+          MailServices.ab.removeAddressBookListener(this);
 
           // Empty out anything in the list.
           while (this.hasChildNodes())
             this.removeChild(this.lastChild);
         ]]>
       </destructor>
 
       <!-- nsIAbListener methods -->
--- a/mailnews/addrbook/prefs/content/pref-directory-add.js
+++ b/mailnews/addrbook/prefs/content/pref-directory-add.js
@@ -1,12 +1,13 @@
 /* -*- Mode: Java; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource:///modules/mailServices.js");
 
-var gPrefInt = null;
 var gCurrentDirectory = null;
 var gReplicationBundle = null;
 var gReplicationService =
   Components.classes["@mozilla.org/addressbook/ldap-replication-service;1"].
              getService(Components.interfaces.nsIAbLDAPReplicationService);
 var gReplicationCancelled = false;
 var gProgressText;
 var gProgressMeter;
@@ -23,18 +24,16 @@ var ldapOfflineObserver = {
     // sanity checks
     if (topic != "network:offline-status-changed") return;
     setDownloadOfflineOnlineState(state == "offline");
   }
 }
 
 function Startup()
 {
-  gPrefInt = Components.classes["@mozilla.org/preferences-service;1"]
-    .getService(Components.interfaces.nsIPrefBranch);
   gReplicationBundle = document.getElementById("bundle_replication");
 
   document.getElementById("download").label =
     gReplicationBundle.getString("downloadButton");
   document.getElementById("download").accessKey =
     gReplicationBundle.getString("downloadButton.accesskey");
 
   if ( "arguments" in window && window.arguments[0] ) {
@@ -43,47 +42,40 @@ function Startup()
       fillSettings();
     } catch (ex) {
       dump("pref-directory-add.js:Startup(): fillSettings() exception: " 
            + ex + "\n");
     }
 
     // Only set up the download button for online/offline status toggling
     // if the pref isn't locked to disable the button.
-    if (!gPrefInt.prefIsLocked(gCurrentDirectory.dirPrefId +
-                               ".disable_button_download")) {
+    if (!Services.prefs.prefIsLocked(gCurrentDirectory.dirPrefId +
+                                     ".disable_button_download")) {
       // Now connect to the offline/online observer
-      var observerService = Components.classes["@mozilla.org/observer-service;1"]
-                                      .getService(Components.interfaces.nsIObserverService);
-      observerService.addObserver(ldapOfflineObserver,
-                                  "network:offline-status-changed", false);
+      Services.obs.addObserver(ldapOfflineObserver,
+                               "network:offline-status-changed", false);
 
-      // Now set the initial offline/online state.
-      var ioService = Components.classes["@mozilla.org/network/io-service;1"]
-                                .getService(Components.interfaces.nsIIOService);
-      // And update the state
-      setDownloadOfflineOnlineState(ioService.offline);
+      // Now set the initial offline/online state and update the state
+      setDownloadOfflineOnlineState(Services.io.offline);
     }
   } else {
     fillDefaultSettings();
     // Don't add observer here as it doesn't make any sense.
   }
 }
 
 function onUnload()
 {
   if ("arguments" in window && 
       window.arguments[0] &&
-      !gPrefInt.prefIsLocked(gCurrentDirectory.dirPrefId +
-                             ".disable_button_download")) {
+      !Services.prefs.prefIsLocked(gCurrentDirectory.dirPrefId +
+                                   ".disable_button_download")) {
     // Remove the observer that we put in on dialog startup
-    var observerService = Components.classes["@mozilla.org/observer-service;1"]
-                                    .getService(Components.interfaces.nsIObserverService);
-    observerService.removeObserver(ldapOfflineObserver,
-                                   "network:offline-status-changed");
+    Services.obs.removeObserver(ldapOfflineObserver,
+                                "network:offline-status-changed");
   }
 }
 
 var progressListener = {
   onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
   {
     if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_START) {
       // start the spinning
@@ -230,24 +222,24 @@ function fillSettings()
   DisableElementIfPrefIsLocked(gCurrentDirectory.dirPrefId + ".description", "description");
   DisableElementIfPrefIsLocked(gCurrentDirectory.dirPrefId + ".disable_button_download", "download");
   DisableElementIfPrefIsLocked(gCurrentDirectory.dirPrefId + ".maxHits", "results");
   DisableElementIfPrefIsLocked(gCurrentDirectory.dirPrefId + ".auth.dn", "login");
 }
 
 function DisableElementIfPrefIsLocked(aPrefName, aElementId)
 {
-  if (gPrefInt.prefIsLocked(aPrefName))
+  if (Services.prefs.prefIsLocked(aPrefName))
     document.getElementById(aElementId).setAttribute('disabled', true);
 }
 
 // disables all the text fields corresponding to the .uri pref.
 function DisableUriFields(aPrefName)
 {
-  if (gPrefInt.prefIsLocked(aPrefName)) {
+  if (Services.prefs.prefIsLocked(aPrefName)) {
     var lockedElements = document.getElementsByAttribute("disableiflocked", "true");
     for (var i=0; i<lockedElements.length; i++)
       lockedElements[i].setAttribute('disabled', 'true');
   }
 }
 
 function onSecure()
 {
@@ -314,22 +306,20 @@ function onAccept()
     // XXX write isValidDn and call it on the dn string here?
     else if (port && hasCharacters(port))
       errorValue = "invalidPortNumber";
     else if (results && hasCharacters(results))
       errorValue = "invalidResults";
     if (!errorValue) {
       // XXX Due to the LDAP c-sdk pass a dummy url to the IO service, then
       // update the parts (bug 473351).
-      var ldapUrl = Components.classes["@mozilla.org/network/io-service;1"]
-        .getService(Components.interfaces.nsIIOService)
-        .newURI((secure.checked ? "ldaps://" : "ldap://") + "localhost/dc=???",
-                null, null)
+      let ldapUrl = Services.io.newURI(
+        (secure.checked ? "ldaps://" : "ldap://") + "localhost/dc=???", null, null)
         .QueryInterface(Components.interfaces.nsILDAPURL);
-      
+
       ldapUrl.host = hostname;
       ldapUrl.port = port ? port :
                             (secure.checked ? kDefaultSecureLDAPPort :
                                               kDefaultLDAPPort);
       ldapUrl.dn = document.getElementById("basedn").value;
       ldapUrl.scope = document.getElementById("one").selected ?
                       Components.interfaces.nsILDAPURL.SCOPE_ONELEVEL :
                       Components.interfaces.nsILDAPURL.SCOPE_SUBTREE;
@@ -364,23 +354,19 @@ function onAccept()
 
       window.opener.gNewServer = description;
       // set window.opener.gUpdate to true so that LDAP Directory Servers
       // dialog gets updated
       window.opener.gUpdate = true; 
     } else {
       var addressBookBundle = document.getElementById("bundle_addressBook");
 
-      var promptService = Components.
-                          classes["@mozilla.org/embedcomp/prompt-service;1"].
-                          getService(Components.interfaces.nsIPromptService);
-
-      promptService.alert(window,
-                          document.title,
-                          addressBookBundle.getString(errorValue));
+      Services.prompt.alert(window,
+                            document.title,
+                            addressBookBundle.getString(errorValue));
       return false;
     }
   } catch (outer) {
     dump("Internal error in pref-directory-add.js:onAccept() " + outer + "\n");
   }
   return true;
 }
 
--- a/mailnews/addrbook/prefs/content/pref-editdirectories.js
+++ b/mailnews/addrbook/prefs/content/pref-editdirectories.js
@@ -31,16 +31,19 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource:///modules/mailServices.js");
+
 // Listener to refresh the list items if something changes. In all these
 // cases we just rebuild the list as it is easier than searching/adding in the
 // correct places an would be an infrequent operation.
 var gAddressBookAbListener = {
   onItemAdded: function(parentDir, item) {
     if (item instanceof Components.interfaces.nsIAbDirectory) {
       fillDirectoryList();
     }
@@ -58,58 +61,48 @@ var gAddressBookAbListener = {
 };
 
 function onInitEditDirectories()
 {
   // For AbDeleteDirectory in abCommon.js
   gAddressBookBundle = document.getElementById("bundle_addressBook");
 
   // If the pref is locked disable the "Add" button
-  var prefs = Components.classes["@mozilla.org/preferences-service;1"]
-                        .getService(Components.interfaces.nsIPrefBranch);
-
-  if (prefs.prefIsLocked("ldap_2.disable_button_add"))
+  if (Services.prefs.prefIsLocked("ldap_2.disable_button_add"))
     document.getElementById("addButton").setAttribute('disabled', true);
 
   // Fill out the directory list
   fillDirectoryList();
 
   const nsIAbListener = Components.interfaces.nsIAbListener;
   // Add a listener so we can update correctly if the list should change
-  Components.classes["@mozilla.org/abmanager;1"]
-            .getService(Components.interfaces.nsIAbManager)
-            .addAddressBookListener(gAddressBookAbListener,
-                                    nsIAbListener.itemAdded |
-                                    nsIAbListener.directoryRemoved |
-                                    nsIAbListener.itemChanged);
+  MailServices.ab.addAddressBookListener(gAddressBookAbListener,
+                                         nsIAbListener.itemAdded |
+                                         nsIAbListener.directoryRemoved |
+                                         nsIAbListener.itemChanged);
 }
 
 function onUninitEditDirectories()
 {
-  Components.classes["@mozilla.org/abmanager;1"]
-            .getService(Components.interfaces.nsIAbManager)
-            .removeAddressBookListener(gAddressBookAbListener);
+  MailServices.ab.removeAddressBookListener(gAddressBookAbListener);
 }
 
 function fillDirectoryList()
 {
   var abList = document.getElementById("directoriesList");
 
   // Empty out anything in the list
   while (abList.hasChildNodes())
     abList.removeChild(abList.lastChild);
 
   // Init the address book list
-  var addressBooks = Components.classes["@mozilla.org/abmanager;1"]
-                               .getService(Components.interfaces.nsIAbManager)
-                               .directories;
-  var holdingArray = [];
-
-  while (addressBooks && addressBooks.hasMoreElements()) {
-    var ab = addressBooks.getNext();
+  let directories = MailServices.ab.directories;
+  let holdingArray = [];
+  while (directories && directories.hasMoreElements()) {
+    let ab = directories.getNext();
     if (ab instanceof Components.interfaces.nsIAbDirectory && ab.isRemote)
       holdingArray.push(ab);
   }
 
   holdingArray.sort(function (a, b) { return a.dirName.localeCompare(b.dirName); });
 
   holdingArray.forEach(function (ab) {
     var item = document.createElement('listitem');
@@ -126,24 +119,20 @@ function selectDirectory()
   var editButton = document.getElementById("editButton");
   var removeButton = document.getElementById("removeButton");
 
   if (abList && abList.selectedItem) {
     editButton.removeAttribute("disabled");
 
     // If the disable delete button pref for the selected directory is set,
     // disable the delete button for that directory.
-    var disable = false;
-    var prefs = Components.classes["@mozilla.org/preferences-service;1"]
-                          .getService(Components.interfaces.nsIPrefBranch);
-    var ab = Components.classes["@mozilla.org/abmanager;1"]
-                       .getService(Components.interfaces.nsIAbManager)
-                       .getDirectory(abList.value);
+    let disable = false;
+    let ab = MailServices.ab.getDirectory(abList.value);
     try {
-      disable = prefs.getBoolPref(ab.dirPrefId + ".disable_delete");
+      disable = Services.prefs.getBoolPref(ab.dirPrefId + ".disable_delete");
     }
     catch(ex){
       // If this preference is not set, it's ok.
     }
     if (disable)
       removeButton.setAttribute("disabled", true);
     else
       removeButton.removeAttribute("disabled");
@@ -163,20 +152,18 @@ function dblClickDirectory(event)
   editDirectory();
 }
 
 function editDirectory()
 {
   var abList = document.getElementById("directoriesList");
 
   if (abList && abList.selectedItem) {
-    var abURI = abList.value;
-    var ab = Components.classes["@mozilla.org/abmanager;1"]
-                       .getService(Components.interfaces.nsIAbManager)
-                       .getDirectory(abURI);
+    let abURI = abList.value;
+    let ab = MailServices.ab.getDirectory(abURI);
 
     window.openDialog(ab.propertiesChromeURI, "editDirectory",
                       "chrome,modal=yes,resizable=no",
                       { selectedDirectory: ab });
   }
 }
 
 function removeDirectory()
--- a/mailnews/addrbook/src/nsAbAutoCompleteMyDomain.js
+++ b/mailnews/addrbook/src/nsAbAutoCompleteMyDomain.js
@@ -29,16 +29,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function nsAbAutoCompleteMyDomain() {}
 
 nsAbAutoCompleteMyDomain.prototype = {
   classID: Components.ID("{5b259db2-e451-4de9-8a6f-cfba91402973}"),
   QueryInterface: XPCOMUtils.generateQI([
       Components.interfaces.nsIAutoCompleteSearch]),
@@ -46,20 +47,17 @@ nsAbAutoCompleteMyDomain.prototype = {
   cachedParam: "",
   cachedIdentity: null,
 
   startSearch: function(aString, aParam, aResult, aListener) {
     const ACR = Components.interfaces.nsIAutoCompleteResult;
     var address = null;
     if (aString && !/,/.test(aString)) {
       if (aParam != this.cachedParam) {
-        this.cachedIdentity =
-            Components.classes['@mozilla.org/messenger/account-manager;1']
-                      .getService(Components.interfaces.nsIMsgAccountManager)
-                      .getIdentity(aParam);
+        this.cachedIdentity = MailServices.accounts.getIdentity(aParam);
         this.cachedParam = aParam;
       }
       if (this.cachedIdentity.autocompleteToMyDomain)
         address = /@/.test(aString) ? aString :
                   this.cachedIdentity.email.replace(/[^@]*/, aString);
     }
 
     var result = {
--- a/mailnews/addrbook/src/nsAbAutoCompleteSearch.js
+++ b/mailnews/addrbook/src/nsAbAutoCompleteSearch.js
@@ -30,19 +30,20 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
-
 const ACR = Components.interfaces.nsIAutoCompleteResult;
 const nsIAbAutoCompleteResult = Components.interfaces.nsIAbAutoCompleteResult;
 
 function nsAbAutoCompleteResult(aSearchString) {
   // Can't create this in the prototype as we'd get the same array for
   // all instances
   this._searchResults = new Array();
   this.searchString = aSearchString;
@@ -105,20 +106,18 @@ function nsAbAutoCompleteSearch() {}
 nsAbAutoCompleteSearch.prototype = {
   // For component registration
   classID: Components.ID("2f946df9-114c-41fe-8899-81f10daf4f0c"),
 
   // This is set from a preference,
   // 0 = no comment column, 1 = name of address book this card came from
   // Other numbers currently unused (hence default to zero)
   _commentColumn: 0,
-  _parser: Components.classes["@mozilla.org/messenger/headerparser;1"]
-                     .getService(Components.interfaces.nsIMsgHeaderParser),
-  _abManager: Components.classes["@mozilla.org/abmanager;1"]
-                        .getService(Components.interfaces.nsIAbManager),
+  _parser: MailServices.headerParser,
+  _abManager: MailServices.ab,
 
   // Private methods
 
   /**
    * Returns the popularity index for a given card. This takes account of a
    * translation bug whereby Thunderbird 2 stores its values in mork as
    * hexadecimal, and Thunderbird 3 stores as decimal.
    *
@@ -388,22 +387,19 @@ nsAbAutoCompleteSearch.prototype = {
     // The comma check is so that we don't autocomplete against the user
     // entering multiple addresses.
     if (!aSearchString || /,/.test(aSearchString)) {
       result.searchResult = ACR.RESULT_IGNORED;
       aListener.onSearchResult(this, result);
       return;
     }
 
-    var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]
-                            .getService(Components.interfaces.nsIPrefBranch);
-
     // Find out about the comment column
     try {
-      this._commentColumn = prefSvc.getIntPref("mail.autoComplete.commentColumn");
+      this._commentColumn = Services.prefs.getIntPref("mail.autoComplete.commentColumn");
     } catch(e) { }
 
     // Craft this by hand - we want the first item to contain the full string,
     // the second item with just the first word, and the third item with
     // anything after the first word.
     var fullString = aSearchString.toLocaleLowerCase();
     var firstWord = "";
     var rest = "";
--- a/mailnews/addrbook/src/nsAbLDAPAttributeMap.js
+++ b/mailnews/addrbook/src/nsAbLDAPAttributeMap.js
@@ -31,16 +31,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const NS_ABLDAPATTRIBUTEMAP_CID = Components.ID(
   "{127b341a-bdda-4270-85e1-edff569a9b85}");
 const NS_ABLDAPATTRIBUTEMAPSERVICE_CID = Components.ID(
   "{4ed7d5e1-8800-40da-9e78-c4f509d7ac5e}");
 
 function nsAbLDAPAttributeMap() {
@@ -143,21 +144,18 @@ nsAbLDAPAttributeMap.prototype = {
       props.push(prop);
     }
 
     aCount.value = props.length;
     return props;
   },
 
   setFromPrefs: function setFromPrefs(aPrefBranchName) {
-    var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].
-      getService(Components.interfaces.nsIPrefService);
-
     // get the right pref branch
-    var branch = prefSvc.getBranch(aPrefBranchName + ".");
+    let branch = Services.prefs.getBranch(aPrefBranchName + ".");
 
     // get the list of children
     var childCount = {};
     var children = branch.getChildList("", childCount);
 
     // do the actual sets
     for each (var child in children) {
       this.setAttributeList(child, branch.getCharPref(child), true);