Bug 309057 - Port |Bug 240138 – Show just the name and not the email address in the message pane| to SeaMonkey
authorSerge Gautherie <sgautherie.bz@free.fr>
Sat, 30 Aug 2008 00:27:14 +0100
changeset 227 be8f98ac3842
parent 226 78cce3227be8
child 228 5aa7b2fce680
push id202
push useriann_cvs@blueyonder.co.uk
push date2008-08-29 23:27 +0000
treeherdercomm-central@be8f98ac3842 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs309057, 240138
Bug 309057 - Port |Bug 240138 – Show just the name and not the email address in the message pane| to SeaMonkey p=sgautherie.bz r=iann sr=neil/jag
mailnews/base/prefs/resources/content/pref-viewing_messages.xul
mailnews/base/resources/content/msgHdrViewOverlay.js
mailnews/base/resources/content/msgHdrViewOverlay.xul
mailnews/mailnews.js
suite/locales/en-US/chrome/mailnews/pref/pref-viewing_messages.dtd
--- a/mailnews/base/prefs/resources/content/pref-viewing_messages.xul
+++ b/mailnews/base/prefs/resources/content/pref-viewing_messages.xul
@@ -33,17 +33,22 @@
    - 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 LGPL or the GPL. 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 ***** -->
 
-<!DOCTYPE overlay SYSTEM "chrome://messenger/locale/pref-viewing_messages.dtd">
+<!DOCTYPE overlay [
+<!ENTITY % pref-viewing_messagesDTD SYSTEM "chrome://messenger/locale/pref-viewing_messages.dtd">
+%pref-viewing_messagesDTD;
+<!ENTITY % editorOverlayDTD SYSTEM "chrome://editor/locale/editorOverlay.dtd">
+%editorOverlayDTD;
+]>
 
 <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <prefpane id="viewing_messages_pane"
             label="&pref.viewing.messages.title;"
             script="chrome://messenger/content/pref-viewing_messages.js">
 
     <preferences id="viewing_messages_preferences">
       <preference id="mailnews.reuse_message_window"
@@ -76,16 +81,19 @@
                   name="mail.quoted_style"
                   type="int"/>
       <preference id="mail.quoted_size"
                   name="mail.quoted_size"
                   type="int"/>
       <preference id="mail.citation_color"
                   name="mail.citation_color"
                   type="string"/>
+      <preference id="mail.showCondensedAddresses"
+                  name="mail.showCondensedAddresses"
+                  type="bool"/>
     </preferences>
 
     <groupbox align="start">
       <caption label="&generalMessageDisplay.caption;"/>
       <label value="&openingMessages.label;" control="reuseMessageWindow"/>
       <hbox class="indent" align="center">
         <radiogroup id="reuseMessageWindow" orient="horizontal"
                     preference="mailnews.reuse_message_window">
@@ -96,16 +104,20 @@
         </radiogroup>
       </hbox>
 
       <separator class="thin"/>
 
       <checkbox id="disableContent" label="&disableContent.label;"
                 accesskey="&disableContent.accesskey;"
                 preference="mailnews.message_display.disable_remote_image"/>
+      <checkbox id="showCondensedAddresses"
+                label="&showCondensedAddresses.label;"
+                accesskey="&showCondensedAddresses.accesskey;"
+                preference="mail.showCondensedAddresses"/>
 
       <separator class="thin"/>
 
       <vbox>
         <hbox>
           <checkbox id="automaticallyMarkAsRead"
                     preference="mailnews.mark_message_read.auto"
                     label="&autoMarkAsRead.label;"
@@ -133,25 +145,27 @@
             </label>
           </hbox>
         </radiogroup>
       </vbox>
     </groupbox>
 
     <groupbox>
       <caption label="&displayPlainText.caption;"/>
-      <label value="&plainTextFont.label;" control="mailFixedWidthMessages"/>
-      <hbox class="indent" align="center">
-        <radiogroup id="mailFixedWidthMessages" orient="horizontal"
-                    preference="mail.fixed_width_messages">
-          <radio value="true" label="&fixedWidth.label;"
-                 accesskey="&fixedWidth.accesskey;"/>
-          <radio value="false" label="&variableWidth.label;"
-                 accesskey="&variableWidth.accesskey;"/>
-        </radiogroup>
+      <hbox align="center">
+        <label value="&fontPlainText.label;"
+               accesskey="&fontPlainText.accesskey;"
+               control="mailFixedWidthMessages"/>
+        <menulist id="mailFixedWidthMessages"
+                  preference="mail.fixed_width_messages">
+          <menupopup>
+            <menuitem value="true" label="&fontFixedWidth.label;"/>
+            <menuitem value="false" label="&fontVarWidth.label;"/>
+          </menupopup>
+        </menulist>
       </hbox>
 
       <separator class="thin"/>
 
       <vbox align="start">
         <checkbox id="wrapLongLines" label="&wrapInMsg.label;"
                   accesskey="&wrapInMsg.accesskey;"
                   preference="mail.wrap_long_lines"/>
--- a/mailnews/base/resources/content/msgHdrViewOverlay.js
+++ b/mailnews/base/resources/content/msgHdrViewOverlay.js
@@ -47,18 +47,20 @@
 // mscott@netscape.com. It's critical that the code in here for displaying
 // the message headers for a selected message remain as fast as possible. In particular, 
 // right now, we only introduce one reflow per message. i.e. if you click on a message in the thread
 // pane, we batch up all the changes for displaying the header pane (to, cc, attachements button, etc.) 
 // and we make a single pass to display them. It's critical that we maintain this one reflow per message
 // view in the message header pane. 
 ////////////////////////////////////////////////////////////////////////////////////
 
-var msgHeaderParserContractID		   = "@mozilla.org/messenger/headerparser;1";
-var abAddressCollectorContractID	 = "@mozilla.org/addressbook/services/addressCollecter;1";
+const msgHeaderParserContractID      = "@mozilla.org/messenger/headerparser;1";
+const abAddressCollectorContractID   = "@mozilla.org/addressbook/services/addressCollecter;1";
+const kPersonalAddressbookUri        = "moz-abmdbdirectory://abook.mab";
+const kRDFServiceContractID          = "@mozilla.org/rdf/rdf-service;1";
 
 var gViewAllHeaders = false;
 var gShowOrganization = false;
 var gShowUserAgent = false;
 var gShowReferences = false;
 var gShowMessageId = false;
 var gCollectIncoming = false;
 var gCollectOutgoing = false;
@@ -70,16 +72,20 @@ var gBuildAttachmentsForCurrentMsg = fal
 var gBuildAttachmentPopupForCurrentMsg = true;
 var gBuiltExpandedView = false;
 var gBuiltCollapsedView = false;
 var gMessengerBundle;
 var gProfileDirURL;
 var gIOService;
 var gFileHandler;
 var gExtraExpandedHeaders;
+// Show the friendly display names for people I know, instead of the name + email address.
+var gShowCondensedEmailAddresses;
+// Used for determining if we want to show just the display name in email address nodes.
+var gPersonalAddressBookDirectory;
 
 var msgHeaderParser = Components.classes[msgHeaderParserContractID].getService(Components.interfaces.nsIMsgHeaderParser);
 var abAddressCollector = null;
 
 // other components may listen to on start header & on end header notifications for each message we display
 // to do that you need to add yourself to our gMessageListeners array with object that has two properties:
 // onStartHeaders and onEndHeaders.
 var gMessageListeners = new Array;
@@ -242,44 +248,66 @@ function OnLoadMsgHeaderPane()
 
   document.loadBindingDocument('chrome://messenger/content/mailWidgets.xml');
   
   // load any preferences that at are global with regards to 
   // displaying a message...
   gCollectIncoming = pref.getBoolPref("mail.collect_email_address_incoming");
   gCollectNewsgroup = pref.getBoolPref("mail.collect_email_address_newsgroup");
   gCollectOutgoing = pref.getBoolPref("mail.collect_email_address_outgoing");
+  gShowCondensedEmailAddresses = pref.getBoolPref("mail.showCondensedAddresses");
   gShowUserAgent = pref.getBoolPref("mailnews.headers.showUserAgent");
   gShowOrganization = pref.getBoolPref("mailnews.headers.showOrganization");
   gShowReferences = pref.getBoolPref("mailnews.headers.showReferences");
   gShowMessageId = pref.getBoolPref("mailnews.headers.showMessageId");
   gExtraExpandedHeaders = pref.getCharPref("mailnews.headers.extraExpandedHeaders");
+
+  pref.addObserver("mail.showCondensedAddresses", MsgHdrViewObserver, false);
+
   initializeHeaderViewTables();
 
   var toggleHeaderView = document.getElementById("msgHeaderView");
   var initialCollapsedSetting = toggleHeaderView.getAttribute("state");
   if (initialCollapsedSetting == "true")
     gCollapsedHeaderViewMode = true;   
 
   // dispatch an event letting any listeners know that we have loaded the message pane
   var event = document.createEvent('Events');
   event.initEvent('messagepane-loaded', false, true);
   var headerViewElement = document.getElementById("msgHeaderView");
   headerViewElement.dispatchEvent(event);
 }
 
 function OnUnloadMsgHeaderPane()
 {
+  pref.removeObserver("mail.showCondensedAddresses", MsgHdrViewObserver);
+
   // 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);
 }
 
+const MsgHdrViewObserver =
+{
+  observe: function(subject, topic, prefName)
+  {
+    // verify that we're changing the mail pane config pref
+    if (topic == "nsPref:changed")
+    {
+      if (prefName == "mail.showCondensedAddresses")
+      {
+        gShowCondensedEmailAddresses = pref.getBoolPref("mail.showCondensedAddresses");
+        MsgReload();
+      }
+    }
+  }
+};
+
 // The messageHeaderSink is the class that gets notified of a message's headers as we display the message
 // through our mime converter. 
 
 var messageHeaderSink = {
     onStartHeaders: function()
     {
       this.mSaveHdr = null;
       // clear out any pending collected address timers...
@@ -914,19 +942,19 @@ function OutputMessageIds(headerEntry, h
   headerEntry.enclosingBox.clearHeaderValues();
   for (var i = 0; i < messageIdArray.length; i++)
     headerEntry.enclosingBox.addMessageIdView(messageIdArray[i]);
 
   headerEntry.enclosingBox.fillMessageIdNodes();
 }
 
 // OutputEmailAddresses --> knows how to take a comma separated list of email addresses,
-// extracts them one by one, linkifying each email address into a mailto url. 
-// Then we add the link'ified email address to the parentDiv passed in.
-// 
+// extracts them one by one, linkifying each email address into a mailto url.
+// Then we add the link-ified email address to the parentDiv passed in.
+//
 // emailAddresses --> comma separated list of the addresses for this header field
 
 function OutputEmailAddresses(headerEntry, emailAddresses)
 {
   if (!emailAddresses)
     return;
 
   if (msgHeaderParser)
@@ -1016,23 +1044,73 @@ function setFromBuddyIcon(email)
      //dump("ex = " + ex + "\n");
    }
    fromBuddyIcon.setAttribute("src", "");
 }
 
 function updateEmailAddressNode(emailAddressNode, address)
 {
   emailAddressNode.setAttribute("label", address.fullAddress || address.displayName);
-  emailAddressNode.removeAttribute("tooltiptext");
   emailAddressNode.setAttribute("emailAddress", address.emailAddress);
   emailAddressNode.setAttribute("fullAddress", address.fullAddress);
   emailAddressNode.setAttribute("displayName", address.displayName);
-  
-  if ("AddExtraAddressProcessing" in this)
-    AddExtraAddressProcessing(address.emailAddress, emailAddressNode);
+  emailAddressNode.removeAttribute("tooltiptext");
+
+  AddExtraAddressProcessing(address.emailAddress, emailAddressNode);
+}
+
+function AddExtraAddressProcessing(emailAddress, addressNode)
+{
+  if (!gShowCondensedEmailAddresses)
+    return;
+
+  const displayName = addressNode.getAttribute("displayName");
+  if (!(displayName && useDisplayNameForAddress(emailAddress)))
+    return;
+
+  // Don't condense the address for the from and reply-to fields.
+  const parentElementId = addressNode.parentNode.id;
+  if (parentElementId == "expandedfromBox" ||
+      parentElementId == "expandedreply-toBox")
+    return;
+
+  addressNode.setAttribute("label", displayName);
+  addressNode.setAttribute("tooltiptext", emailAddress);
+}
+
+function fillEmailAddressPopup(emailAddressNode)
+{
+  document.getElementById("emailAddressPlaceHolder")
+          .setAttribute("label", emailAddressNode.getAttribute("emailAddress"));
+}
+
+// returns true if we should use the display name for this address
+// otherwise returns false
+function useDisplayNameForAddress(emailAddress)
+{
+  // For now, if the email address is in the personal address book, then
+  // consider this user a 'known' user and use the display name. I could
+  // eventually see our rules enlarged to include other local ABs, replicated
+  // LDAP directories, and maybe even domain matches (i.e. any email from
+  // someone in my company should use the friendly display name).
+
+  if (!gPersonalAddressBookDirectory)
+  {
+    gPersonalAddressBookDirectory =
+      Components.classes[kRDFServiceContractID]
+                .getService(Components.interfaces.nsIRDFService)
+                .GetResource(kPersonalAddressbookUri)
+                .QueryInterface(Components.interfaces.nsIAbMDBDirectory);
+
+    if (!gPersonalAddressBookDirectory)
+      return false;
+  }
+
+  // look up the email address in the database
+  return gPersonalAddressBookDirectory.cardForEmailAddress(emailAddress);
 }
 
 // createnewAttachmentInfo --> constructor method for creating new attachment object which goes into the
 // data attachment array.
 function createNewAttachmentInfo(contentType, url, displayName, uri, isExternalAttachment)
 {
   this.contentType = contentType;
   this.url = url;
@@ -1246,17 +1324,17 @@ function displayAttachmentsForExpandedVi
     {
       var attachment = currentAttachments[index];
 
       // create a listitem for the attachment listbox
       var displayName = createAttachmentDisplayName(attachment);
       var item = attachmentList.appendItem(displayName, "");
       item.setAttribute("crop", "center");
       item.setAttribute("class", "listitem-iconic attachment-item"); 
-      item.setAttribute("tooltip", "attachmentListTooltip");
+      item.setAttribute("tooltiptext", attachment.displayName);
       item.attachment = attachment;
       item.setAttribute("attachmentUrl", attachment.url);
       item.setAttribute("attachmentContentType", attachment.contentType);
       item.setAttribute("attachmentUri", attachment.uri);
       if (attachment.contentType == "text/x-moz-deleted")
         item.setAttribute('disabled', 'true');
       else
         setApplicationIconForAttachment(attachment, item);
@@ -1279,25 +1357,16 @@ function setApplicationIconForAttachment
 
 function displayAttachmentsForCollapsedView()
 {
   var numAttachments = currentAttachments.length;
   var attachmentNode = document.getElementById('collapsedAttachmentBox');
   attachmentNode.collapsed = numAttachments <= 0; // make sure the attachment button is visible
 }
 
-// Public method called to generate a tooltip over an attachment
-function FillInAttachmentTooltip(cellNode)
-{
-  var attachmentName = cellNode.getAttribute("label");
-  var tooltipNode = document.getElementById("attachmentListTooltip");
-  tooltipNode.setAttribute("label", attachmentName);
-  return true;
-}
-
 // Public method called when we create the attachments file menu
 function FillAttachmentListPopup(popup)
 {
   // the FE sometimes call this routine TWICE...I haven't been able to figure out why yet...
   // protect against it...
 
   if (!gBuildAttachmentPopupForCurrentMsg) return; 
 
--- a/mailnews/base/resources/content/msgHdrViewOverlay.xul
+++ b/mailnews/base/resources/content/msgHdrViewOverlay.xul
@@ -70,17 +70,20 @@
             oncommand="var messageId = GetMessageIdFromNode(document.popupNode, true);
                        OpenBrowserWithMessageId(messageId)"/>
   <menuitem label="&CopyMessageId.label;"
             oncommand="var messageId = GetMessageIdFromNode(document.popupNode, false);
                        CopyString(messageId);"/>
 </popup>
 
 <popup id="emailAddressPopup" popupanchor="bottomleft"
-       onpopupshowing="goUpdateCommand('cmd_createFilterFromPopup');">
+       onpopupshowing="fillEmailAddressPopup(document.popupNode);
+                       goUpdateCommand('cmd_createFilterFromPopup');">
+  <menuitem id="emailAddressPlaceHolder" label="" disabled="true"/>
+  <menuseparator/>
   <menuitem label="&SendMailTo.label;"
             accesskey="&SendMailTo.accesskey;"
             oncommand="SendMailToNode(document.popupNode)"/>
   <menuitem label="&CreateFilterFrom.label;"
             accesskey="&CreateFilterFrom.accesskey;"
             command="cmd_createFilterFromPopup"/>
   <menuitem label="&AddToAddressBook.label;"
             accesskey="&AddToAddressBook.accesskey;"
@@ -116,19 +119,16 @@
   <menuitem id="file-saveAllAttachments" label="&saveAllAttachmentsCmd.label;" 
     accesskey="&saveAllAttachmentsCmd.accesskey;" oncommand="HandleMultipleAttachments('saveAttachment', currentAttachments);"/>
   <menuitem id="file-detachAllAttachments" label="&detachAllAttachmentsCmd.label;" 
     accesskey="&detachAllAttachmentsCmd.accesskey;" oncommand="HandleMultipleAttachments('detachAttachment', currentAttachments);" />
   <menuitem id="file-deleteAllAttachments" label="&deleteAllAttachmentsCmd.label;" 
     accesskey="&deleteAllAttachmentsCmd.accesskey;" oncommand="HandleMultipleAttachments('deleteAttachment', currentAttachments);" />
 </popup>
 
-<tooltip id="attachmentListTooltip"
-         onpopupshowing="return FillInAttachmentTooltip(document.tooltipNode);"/> 
-
 <hbox id="msgHeaderView" keywordrelated="true" originalclass="none" persist="state">
 
 <grid id="collapsedHeaderView" class="header-part1" keywordrelated="true" originalclass="header-part1" flex="1" collapsed="true">
   <rows>
     <row flex="1"/>
   </rows>
   <columns>
     <column class="collapsedToggleHdrBox">
--- a/mailnews/mailnews.js
+++ b/mailnews/mailnews.js
@@ -197,16 +197,18 @@ pref("mail.pane_config.dynamic",        
 pref("mail.addr_book.mapit_url.format", "chrome://messenger-region/locale/region.properties");
 #ifdef MOZ_SUITE
 pref("mailnews.start_page.url", "chrome://messenger-region/locale/region.properties");
 pref("mail.addr_book.im.onlineCheckAllowed", false);
 pref("messenger.throbber.url", "chrome://messenger-region/locale/region.properties");
 pref("compose.throbber.url", "chrome://messenger-region/locale/region.properties");
 pref("addressbook.throbber.url", "chrome://messenger-region/locale/region.properties");
 pref("mail.accountwizard.deferstorage", false);
+// |false|: Show both name and address, even for people in my addressbook.
+pref("mail.showCondensedAddresses", false);
 #endif
 
 // the format for "mail.addr_book.quicksearchquery.format" is:
 // @V == the escaped value typed in the quick search bar in the addressbook
 //
 // note, changing this might require a change to SearchNameOrEmail.label
 // in messenger.dtd
 pref("mail.addr_book.quicksearchquery.format", "chrome://messenger/locale/messenger.properties");
--- a/suite/locales/en-US/chrome/mailnews/pref/pref-viewing_messages.dtd
+++ b/suite/locales/en-US/chrome/mailnews/pref/pref-viewing_messages.dtd
@@ -45,40 +45,39 @@
 <!ENTITY boldItalic.label                 "Bold Italic">
 <!ENTITY size.label                       "Size:">
 <!ENTITY size.accesskey                   "z">
 <!ENTITY bigger.label                     "Bigger">
 <!ENTITY smaller.label                    "Smaller">
 <!ENTITY color.label                      "Color:">
 <!ENTITY color.accesskey                  "C">
 <!ENTITY displayPlainText.caption         "Plain text messages">
-<!ENTITY plainTextFont.label              "Use the following font width:">
+<!ENTITY fontPlainText.label              "Font:">
+<!ENTITY fontPlainText.accesskey          "F">
 <!ENTITY displayQuoted.label              "Settings for quoted messages:">
-<!ENTITY fixedWidth.label                 "Fixed">
-<!ENTITY fixedWidth.accesskey             "F">
-<!ENTITY variableWidth.label              "Variable">
-<!ENTITY variableWidth.accesskey          "V">
 <!ENTITY readingMessagesHeader.label      "For incoming messages">
 <!ENTITY messageWrapping.label            "Message Wrapping">
 <!ENTITY wrapInMsg.label                  "Wrap text to fit window width">
-<!ENTITY wrapInMsg.accesskey              "t">
+<!ENTITY wrapInMsg.accesskey              "W">
 <!-- LOCALIZATION NOTE : (convertEmoticons.label) 'Emoticons' are also known as 'Smileys', e.g. :-)   -->
 <!ENTITY convertEmoticons.label           "Display emoticons as graphics">
 <!ENTITY convertEmoticons.accesskey       "D">
 <!ENTITY generalMessageDisplay.caption    "General">
 <!ENTITY autoMarkAsRead.label             "Automatically mark messages as read">
 <!ENTITY autoMarkAsRead.accesskey         "A">
 <!ENTITY markAsReadNoDelay.label          "Immediately on display">
-<!ENTITY markAsReadNoDelay.accesskey      "d">
+<!ENTITY markAsReadNoDelay.accesskey      "m">
 <!-- LOCALIZATION NOTE (markAsReadDelay.label): This will concatenate to
      "After displaying for [___] seconds",
      using (markAsReadDelay.label) and a number (secondsLabel.label). -->
 <!ENTITY markAsReadDelay.label            "After displaying for">
-<!ENTITY markAsReadDelay.accesskey        "e">
+<!ENTITY markAsReadDelay.accesskey        "t">
 <!ENTITY secondsLabel.label               "seconds">
 
 <!ENTITY openingMessages.label            "When opening messages, display them in:">
 <!ENTITY newWindowRadio.label             "A new message window">
 <!ENTITY newWindowRadio.accesskey         "n">
 <!ENTITY existingWindowRadio.label        "An existing message window">
 <!ENTITY existingWindowRadio.accesskey    "e">
 <!ENTITY disableContent.label             "Block images and other content from remote sources">
 <!ENTITY disableContent.accesskey         "B">
+<!ENTITY showCondensedAddresses.label     "Show only display name for people in my address book">
+<!ENTITY showCondensedAddresses.accesskey "o">