Bug 738991 - Convert msgHdrViewOverlay.js to Services.jsm and MailServices.js. r=squib
authoraceman <acelists@atlas.sk>
Thu, 28 Jun 2012 21:12:24 -0400
changeset 10541 2d29995c7043fd4c22fb94ae0eb0b1b74e23916b
parent 10540 f0373381ad06ed918a813a7b919e906bb60d1335
child 10542 85713dfab9f82a17527878dbfdfa9a73e5202920
push id7963
push userryanvm@gmail.com
push dateFri, 29 Jun 2012 01:14:31 +0000
treeherdercomm-central@85713dfab9f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssquib
bugs738991
Bug 738991 - Convert msgHdrViewOverlay.js to Services.jsm and MailServices.js. r=squib
mail/base/content/msgHdrViewOverlay.js
--- a/mail/base/content/msgHdrViewOverlay.js
+++ b/mail/base/content/msgHdrViewOverlay.js
@@ -160,56 +160,54 @@ function createHeaderEntry(prefix, heade
   // later attach it to any <mail-emailaddress> tags it creates for later
   // extraction and use by UpdateEmailNodeDetails.
   this.enclosingBox.headerName = headerListInfo.name;
 
 }
 
 function initializeHeaderViewTables()
 {
-  var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
-                             .getService(Components.interfaces.nsIPrefBranch);
   // Iterate over each header in our header list arrays and create header entries
   // for each one. These header entries are then stored in the appropriate header
   // table.
   var index;
   for (index = 0; index < gExpandedHeaderList.length; index++) {
     var headerName = gExpandedHeaderList[index].name;
     gExpandedHeaderView[headerName] =
       new createHeaderEntry("expanded", gExpandedHeaderList[index]);
   }
 
   var extraHeaders =
-    prefBranch.getCharPref("mailnews.headers.extraExpandedHeaders").split(" ");
+    Services.prefs.getCharPref("mailnews.headers.extraExpandedHeaders").split(" ");
   for (index = 0; index < extraHeaders.length; index++) {
     var extraHeader = extraHeaders[index];
     gExpandedHeaderView[extraHeader.toLowerCase()] =
       new createNewHeaderView(extraHeader, extraHeader);
   }
 
-  if (prefBranch.getBoolPref("mailnews.headers.showOrganization")) {
+  if (Services.prefs.getBoolPref("mailnews.headers.showOrganization")) {
     var organizationEntry = { name: "organization",
                               outputFunction: updateHeaderValue };
     gExpandedHeaderView[organizationEntry.name] =
       new createHeaderEntry("expanded", organizationEntry);
   }
 
-  if (prefBranch.getBoolPref("mailnews.headers.showUserAgent")) {
+  if (Services.prefs.getBoolPref("mailnews.headers.showUserAgent")) {
     var userAgentEntry = { name: "user-agent", outputFunction: updateHeaderValue };
     gExpandedHeaderView[userAgentEntry.name] =
       new createHeaderEntry("expanded", userAgentEntry);
   }
 
-  if (prefBranch.getBoolPref("mailnews.headers.showMessageId")) {
+  if (Services.prefs.getBoolPref("mailnews.headers.showMessageId")) {
     var messageIdEntry = { name: "message-id", outputFunction: OutputMessageIds };
     gExpandedHeaderView[messageIdEntry.name] =
       new createHeaderEntry("expanded", messageIdEntry);
   }
 
-  if (prefBranch.getBoolPref("mailnews.headers.showSender")) {
+  if (Services.prefs.getBoolPref("mailnews.headers.showSender")) {
     var senderEntry = { name: "sender", outputFunction: OutputEmailAddresses };
     gExpandedHeaderView[senderEntry.name] =
       new createHeaderEntry("expanded", senderEntry);
   }
 }
 
 function OnLoadMsgHeaderPane()
 {
@@ -226,20 +224,18 @@ function OnLoadMsgHeaderPane()
   // listen to the
   pref.addObserver("mail.showCondensedAddresses", MsgHdrViewObserver, false);
   pref.addObserver("mailnews.headers.showReferences", MsgHdrViewObserver, false);
 
   initializeHeaderViewTables();
 
   // Add an address book listener so we can update the header view when things
   // change.
-  Components.classes["@mozilla.org/abmanager;1"]
-            .getService(Components.interfaces.nsIAbManager)
-            .addAddressBookListener(AddressBookListener,
-                                    Components.interfaces.nsIAbListener.all);
+  MailServices.ab.addAddressBookListener(AddressBookListener,
+                                         Components.interfaces.nsIAbListener.all);
 
   // If an invalid index is selected; reset to 0.  One way this can happen
   // is if a value of 1 was persisted to localStore.rdf by Tb2 (when there were
   // two panels), and then the user upgraded to Tb3, which only has one.
   // Presumably this can also catch cases of extension uninstalls as well.
   let deckElement = document.getElementById("msgHeaderViewDeck")
 
   // If the selectedIndex was 0, then we were using the compact header, (if we
@@ -333,19 +329,17 @@ function initToolbarMenu() {
   return;
 }
 
 function OnUnloadMsgHeaderPane()
 {
   pref.removeObserver("mail.showCondensedAddresses", MsgHdrViewObserver);
   pref.removeObserver("mailnews.headers.showReferences", MsgHdrViewObserver);
 
-  Components.classes["@mozilla.org/abmanager;1"]
-            .getService(Components.interfaces.nsIAbManager)
-            .removeAddressBookListener(AddressBookListener);
+  MailServices.ab.removeAddressBookListener(AddressBookListener);
 
   // dispatch an event letting any listeners know that we have unloaded
   // the message pane
   var event = document.createEvent("Events");
   event.initEvent("messagepane-unloaded", false, true);
   var headerViewElement = document.getElementById("msgHeaderView");
   headerViewElement.dispatchEvent(event);
 }
@@ -534,41 +528,38 @@ var messageHeaderSink = {
         }
         else
          currentHeaderData[lowerCaseHeaderName] = header;
       } // while we have more headers to parse
 
       // Process message tags as if they were headers in the message.
       SetTagHeader();
 
-      var msgHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"]
-                                      .getService(Components.interfaces.nsIMsgHeaderParser);
-
       if (("from" in currentHeaderData) && ("sender" in currentHeaderData)) {
         var senderMailbox = kMailboxSeparator +
-          msgHeaderParser.extractHeaderAddressMailboxes(
+          MailServices.headerParser.extractHeaderAddressMailboxes(
             currentHeaderData.sender.headerValue) + kMailboxSeparator;
         var fromMailboxes = kMailboxSeparator +
-          msgHeaderParser.extractHeaderAddressMailboxes(
+          MailServices.headerParser.extractHeaderAddressMailboxes(
             currentHeaderData.from.headerValue) + kMailboxSeparator;
         if (fromMailboxes.indexOf(senderMailbox) >= 0)
           delete currentHeaderData.sender;
       }
 
       // We don't need to show the reply-to header if its value is either
       // the From field (totally pointless) or the To field (common for
       // mailing lists, but not that useful).
       if (("from" in currentHeaderData) &&
           ("to" in currentHeaderData) &&
           ("reply-to" in currentHeaderData)) {
-        var replyToMailbox = msgHeaderParser.extractHeaderAddressMailboxes(
+        var replyToMailbox = MailServices.headerParser.extractHeaderAddressMailboxes(
             currentHeaderData["reply-to"].headerValue);
-        var fromMailboxes = msgHeaderParser.extractHeaderAddressMailboxes(
+        var fromMailboxes = MailServices.headerParser.extractHeaderAddressMailboxes(
             currentHeaderData.from.headerValue);
-        var toMailboxes = msgHeaderParser.extractHeaderAddressMailboxes(
+        var toMailboxes = MailServices.headerParser.extractHeaderAddressMailboxes(
             currentHeaderData.to.headerValue);
 
         if (replyToMailbox == fromMailboxes || replyToMailbox == toMailboxes)
           delete currentHeaderData["reply-to"];
       }
 
       this.onEndHeaders();
     },
@@ -732,19 +723,17 @@ var messageHeaderSink = {
 function SetTagHeader()
 {
   // It would be nice if we passed in the msgHdr from the back end.
   var msgHdr = gFolderDisplay.selectedMessage;
   if (!msgHdr)
     return; // no msgHdr to add our tags to
 
   // get the list of known tags
-  var tagService = Components.classes["@mozilla.org/messenger/tagservice;1"]
-                   .getService(Components.interfaces.nsIMsgTagService);
-  var tagArray = tagService.getAllTags({});
+  var tagArray = MailServices.tags.getAllTags({});
   var tagKeys = {};
   for each (var tagInfo in tagArray)
     if (tagInfo.tag)
       tagKeys[tagInfo.key] = true;
 
   // extract the tag keys from the msgHdr
   var msgKeyArray = msgHdr.getStringProperty("keywords").split(" ");
 
@@ -1168,20 +1157,19 @@ function OutputEmailAddresses(headerEntr
   if (!emailAddresses)
     return;
 
   var addresses = {};
   var fullNames = {};
   var names = {};
   var numAddresses =  0;
 
-  var msgHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"]
-                                  .getService(Components.interfaces.nsIMsgHeaderParser);
-  numAddresses = msgHeaderParser.parseHeadersWithArray(emailAddresses, addresses,
-                                                       names, fullNames);
+  numAddresses = MailServices.headerParser
+                             .parseHeadersWithArray(emailAddresses, addresses,
+                                                    names, fullNames);
   var index = 0;
   while (index < numAddresses) {
     // If we want to include short/long toggle views and we have a long view,
     // always add it. If we aren't including a short/long view OR if we are and
     // we haven't parsed enough addresses to reach the cutoff valve yet then add
     // it to the default (short) div.
     let address = {};
     address.emailAddress = addresses.value[index];
@@ -1477,19 +1465,17 @@ function setupEmailAddressPopup(emailAdd
  * @return              an object with two properties, .book and .card
  */
 function getCardForEmail(emailAddress)
 {
   // Email address is searched for in any of the address books that support
   // the cardForEmailAddress function.
   // Future expansion could be to domain matches
 
-  var books = Components.classes["@mozilla.org/abmanager;1"]
-                        .getService(Components.interfaces.nsIAbManager)
-                        .directories;
+  var books = MailServices.ab.directories;
 
   var result = { book: null, card: null };
 
   while (!result.card && books.hasMoreElements()) {
     var ab = books.getNext()
                   .QueryInterface(Components.interfaces.nsIAbDirectory);
     try {
       var card = ab.cardForEmailAddress(emailAddress);
@@ -1540,20 +1526,18 @@ function AddContact(emailAddressNode)
 {
   // When we collect an address, it updates the AB which sends out
   // notifications to update the UI. In the add case we don't want to update
   // the UI so that accidentally double-clicking on the star doesn't lead
   // to something strange (i.e star would be moved out from underneath,
   // leaving something else there).
   emailAddressNode.setAttribute("updatingUI", true);
 
-  let abManager = Components.classes["@mozilla.org/abmanager;1"]
-                            .getService(Components.interfaces.nsIAbManager);
   const kPersonalAddressbookURI = "moz-abmdbdirectory://abook.mab";
-  let addressBook = abManager.getDirectory(kPersonalAddressbookURI);
+  let addressBook = MailServices.ab.getDirectory(kPersonalAddressbookURI);
 
   let card = Components.classes["@mozilla.org/addressbook/cardproperty;1"]
                        .createInstance(Components.interfaces.nsIAbCard);
   card.displayName = emailAddressNode.getAttribute("displayName");
   card.primaryEmail = emailAddressNode.getAttribute("emailAddress");
 
   // Just save the new node straight away.
   addressBook.addCard(card);
@@ -2110,19 +2094,17 @@ function displayAttachmentsForExpandedVi
     attachmentView.collapsed = true;
     attachmentSplitter.collapsed = true;
   }
   else if (!gBuildAttachmentsForCurrentMsg) {
     attachmentView.collapsed = false;
 
     var attachmentList = document.getElementById("attachmentList");
 
-    var viewMode = Components.classes["@mozilla.org/preferences-service;1"]
-                             .getService(Components.interfaces.nsIPrefBranch)
-                             .getIntPref("mailnews.attachments.display.view");
+    var viewMode = Services.prefs.getIntPref("mailnews.attachments.display.view");
     var views = ["small", "large", "tile"];
     attachmentList.view = views[viewMode];
     attachmentList.controllers.appendController(AttachmentListController);
 
     toggleAttachmentList(false);
 
     var lastPartID;
     var unknownSize = false;
@@ -2665,19 +2647,17 @@ nsDummyMsgHeader.prototype =
   // If you change us to return a fake folder, please update
   // folderDisplay.js's FolderDisplayWidget's selectedMessageIsExternal getter.
   folder : null
 };
 
 function onShowOtherActionsPopup()
 {
   // Enable/disable the Open Conversation button.
-  let prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
-                             .getService(Components.interfaces.nsIPrefBranch);
-  let glodaEnabled = prefBranch.getBoolPref("mailnews.database.global.indexer.enabled");
+  let glodaEnabled = Services.prefs.getBoolPref("mailnews.database.global.indexer.enabled");
 
   let openConversation = document.getElementById("otherActionsOpenConversation");
   openConversation.disabled = !glodaEnabled;
   if (glodaEnabled && gFolderDisplay.selectedMessages.length > 0) {
     let message = gFolderDisplay.selectedMessages[0];
     let isMessageIndexed = Gloda.isMessageIndexed(message);
     openConversation.disabled = !isMessageIndexed;
   }
@@ -2702,19 +2682,18 @@ ConversationOpener.prototype = {
       this._items = [];
       this._msgHdr = messages[0];
       this._queries = [Gloda.getMessageCollectionForHeaders(messages, this)];
     } catch (e) {
       logException(e);
     }
   },
   isSelectedMessageIndexed: function() {
-    let prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
-                               .getService(Components.interfaces.nsIPrefBranch);
-    let glodaEnabled = prefBranch.getBoolPref("mailnews.database.global.indexer.enabled");
+    let glodaEnabled = Services.prefs
+      .getBoolPref("mailnews.database.global.indexer.enabled");
 
     if (glodaEnabled && gFolderDisplay.selectedMessages.length > 0) {
       let message = gFolderDisplay.selectedMessages[0];
       return Gloda.isMessageIndexed(message);
     }
     return false;
   },
   onItemsAdded: function(aItems) {