Bug 1209565 - Always show the e-mail address when name is in addressbook and the display name is not preferred. r=mkmelin a=rkent THUNDERBIRD450b3_2016032415_RELBRANCH
authorJorg K
Fri, 19 Feb 2016 22:10:42 +0100
branchTHUNDERBIRD450b3_2016032415_RELBRANCH
changeset 26846 8142e791c20fdf14b02f0b62a7b7ffd9700d6734
parent 26845 cd2c5c7d3089b22be01296eeea5a2878d80daf08
child 26847 905e10d4b8d8342e05ae083171442d7bcf8eb76e
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, rkent
bugs1209565
Bug 1209565 - Always show the e-mail address when name is in addressbook and the display name is not preferred. r=mkmelin a=rkent
mail/base/modules/displayNameUtils.js
mail/test/mozmill/folder-display/test-summarization.js
mail/test/mozmill/multiple-identities/test-display-names.js
--- a/mail/base/modules/displayNameUtils.js
+++ b/mail/base/modules/displayNameUtils.js
@@ -55,17 +55,19 @@ function _getIdentityForAddress(aEmailAd
 
 /**
  * Take an email address and compose a sensible display name based on the
  * header display name and/or the display name from the address book. If no
  * appropriate name can be made (e.g. there is no card for this address),
  * returns |null|.
  *
  * @param aEmailAddress      The email address to format.
- * @param aHeaderDisplayName The display name from the header, if any.
+ * @param aHeaderDisplayName The display name from the header, if any
+ *                           (unused, maintained for add-ons, previously used
+ *                           as a fallback).
  * @param aContext           The field being formatted (e.g. "to", "from").
  * @param aCard              The address book card, if any.
  * @return The formatted display name, or null.
  */
 function FormatDisplayName(aEmailAddress, aHeaderDisplayName, aContext, aCard)
 {
   var displayName = null;
   var identity = _getIdentityForAddress(aEmailAddress);
@@ -86,22 +88,22 @@ function FormatDisplayName(aEmailAddress
     if (MailServices.accounts.allIdentities.length > 1)
       displayName += " <" + identity.email + ">";
   }
 
   // If we don't have a card, refuse to generate a display name. Places calling
   // this are then responsible for falling back to something else (e.g. the
   // value from the message header).
   if (card) {
-    if (!displayName && aHeaderDisplayName)
-      displayName = aHeaderDisplayName;
+    // getProperty may return a "1" or "0" string, we want a boolean
+    if (card.getProperty("PreferDisplayName", true) != false)
+      displayName = card.displayName || null;
 
-    // getProperty may return a "1" or "0" string, we want a boolean
-    if (!displayName || card.getProperty("PreferDisplayName", true) != false)
-      displayName = card.displayName || null;
+    // Note: aHeaderDisplayName is not used as a fallback as confusion could be
+    // caused by a collected address using an e-mail address as display name.
   }
 
   return displayName;
 }
 
 /**
  * Format the display name from a list of addresses. First, try using
  * FormatDisplayName, then fall back to the header's display name or the
@@ -109,16 +111,23 @@ function FormatDisplayName(aEmailAddress
  *
  * @param aHeaderValue  The decoded header value (e.g. mime2DecodedAuthor).
  * @param aContext      The context of the header field (e.g. "to", "from").
  * @return The formatted display name.
  */
 function FormatDisplayNameList(aHeaderValue, aContext) {
   let addresses = MailServices.headerParser.parseDecodedHeader(aHeaderValue);
   if (addresses.length > 0) {
-    return FormatDisplayName(addresses[0].email, addresses[0].name, aContext) ||
-      addresses[0].name || addresses[0].email;
+    let displayName = FormatDisplayName(addresses[0].email, addresses[0].name, aContext);
+    if (displayName)
+      return displayName;
+
+    // Construct default display.
+    if (addresses[0].email) {
+      return addresses[0].name ?
+             addresses[0].name + " <" + addresses[0].email + ">" :
+             addresses[0].email;
+    }
   }
-  else {
-    // Something strange happened, just return the raw header value.
-    return aHeaderValue;
-  }
+
+  // Something strange happened, just return the raw header value.
+  return aHeaderValue;
 }
--- a/mail/test/mozmill/folder-display/test-summarization.js
+++ b/mail/test/mozmill/folder-display/test-summarization.js
@@ -330,17 +330,18 @@ function test_display_name_no_abook()
   be_in_folder(folder);
 
   let address = extract_first_address(thread1);
   ensure_no_card_exists(address.email);
 
   collapse_all_threads();
   select_click_row(thread1);
 
-  check_address_name(address.name);
+  // No address book entry, we display name and e-mail address.
+  check_address_name(address.name + " <" + address.email + ">");
 }
 
 function test_display_name_abook()
 {
   be_in_folder(folder);
 
   let address = extract_first_address(thread1);
   ensure_card_exists(address.email, "My Friend", true);
@@ -356,10 +357,12 @@ function test_display_name_abook_no_pdn(
   be_in_folder(folder);
 
   let address = extract_first_address(thread1);
   ensure_card_exists(address.email, "My Friend", false);
 
   collapse_all_threads();
   select_click_row(thread1);
 
-  check_address_name(address.name);
+  // With address book entry but display name not preferred, we display name and
+  // e-mail address.
+  check_address_name(address.name + " <" + address.email + ">");
 }
--- a/mail/test/mozmill/multiple-identities/test-display-names.js
+++ b/mail/test/mozmill/multiple-identities/test-display-names.js
@@ -149,17 +149,19 @@ function test_no_header_name_in_abook() 
   ensure_card_exists(friendEmail, "My Buddy", true);
   ensure_single_identity();
   help_test_display_name(1, "from", "My Buddy");
 }
 
 function test_no_header_name_in_abook_no_pdn() {
   ensure_card_exists(friendEmail, "My Buddy");
   ensure_single_identity();
-  help_test_display_name(1, "from", "My Buddy");
+  // With address book entry but display name not preferred, we display name and
+  // e-mail address or only the e-mail address if no name exists.
+  help_test_display_name(1, "from", "carl@sagan.invalid");
 }
 
 
 
 function test_header_name() {
   ensure_no_card_exists(friendEmail);
   ensure_single_identity();
   help_test_display_name(2, "from", friendName+" <"+friendEmail+">");
@@ -169,10 +171,12 @@ function test_header_name_in_abook() {
   ensure_card_exists(friendEmail, "My Buddy", true);
   ensure_single_identity();
   help_test_display_name(2, "from", "My Buddy");
 }
 
 function test_header_name_in_abook_no_pdn() {
   ensure_card_exists(friendEmail, "My Buddy");
   ensure_single_identity();
-  help_test_display_name(2, "from", "Carl Sagan");
+  // With address book entry but display name not preferred, we display name and
+  // e-mail address.
+  help_test_display_name(2, "from", "Carl Sagan <carl@sagan.invalid>");
 }