Bug 1045753 - Compose email LDAP erases text (autocompletes to blank entry when email not set). r=standard8,a=Standard8
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Sun, 26 Oct 2014 13:57:24 +0200
changeset 25559 d8c36ca11fb1df1fe8011d710ce850fcc27af04a
parent 25558 b89d2b3b63094a3b6bad8956872cb40085c95005
child 25560 49d7c18fa0a1b29f60b1d0c3ce26f87fd12403d8
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)
reviewersstandard8, Standard8
bugs1045753
Bug 1045753 - Compose email LDAP erases text (autocompletes to blank entry when email not set). r=standard8,a=Standard8
mailnews/addrbook/src/nsAbAutoCompleteSearch.js
mailnews/addrbook/src/nsAbLDAPAutoCompleteSearch.js
mailnews/addrbook/test/unit/test_nsAbAutoCompleteSearch4.js
--- a/mailnews/addrbook/src/nsAbAutoCompleteSearch.js
+++ b/mailnews/addrbook/src/nsAbAutoCompleteSearch.js
@@ -236,23 +236,25 @@ nsAbAutoCompleteSearch.prototype = {
    * @param directory      The directory that the card is in.
    * @param card           The card being added to the results.
    * @param emailToUse     The email address from the card that should be used
    *                       for this result.
    * @param isPrimaryEmail Is the emailToUse the primary email? Set to true if
    *                       it is the case. For mailing lists set it to true.
    * @param result         The result to add the new entry to.
    */
-  _addToResult: function _addToResult(commentColumn, directory, card,
-                                      emailToUse, isPrimaryEmail, result) {
-    var emailAddress =
-      this._parser.makeMailboxObject(card.displayName,
-                                     card.isMailList ?
-                                     card.getProperty("Notes", "") || card.displayName :
-                                     emailToUse).toString();
+  _addToResult: function(commentColumn, directory, card,
+                         emailToUse, isPrimaryEmail, result) {
+    let mbox = this._parser.makeMailboxObject(card.displayName,
+      card.isMailList ? card.getProperty("Notes", "") || card.displayName :
+                        emailToUse);
+    if (!mbox.email)
+      return;
+
+    let emailAddress = mbox.toString();
 
     // If it is a duplicate, then just return and don't add it. The
     // _checkDuplicate function deals with it all for us.
     if (this._checkDuplicate(directory, card, emailAddress, result))
       return;
 
     result._collectedValues.set(emailAddress.toLocaleLowerCase(), {
       value: emailAddress,
--- a/mailnews/addrbook/src/nsAbLDAPAutoCompleteSearch.js
+++ b/mailnews/addrbook/src/nsAbLDAPAutoCompleteSearch.js
@@ -112,22 +112,24 @@ nsAbLDAPAutoCompleteSearch.prototype = {
   _checkDuplicate: function _checkDuplicate(card, emailAddress) {
     var lcEmailAddress = emailAddress.toLocaleLowerCase();
 
     return this._result._searchResults.some(function(result) {
       return result.value.toLocaleLowerCase() == lcEmailAddress;
     });
   },
 
-  _addToResult: function _addToResult(card) {
-    let emailAddress =
-      this._parser.makeMailboxObject(card.displayName,
-                                     card.isMailList ?
-                                     card.getProperty("Notes", "") || card.displayName :
-                                     card.primaryEmail).toString();
+  _addToResult: function(card) {
+    let mbox = this._parser.makeMailboxObject(card.displayName,
+      card.isMailList ? card.getProperty("Notes", "") || card.displayName :
+                        card.primaryEmail);
+    if (!mbox.email)
+      return;
+
+    let emailAddress = mbox.toString();
 
     // If it is a duplicate, then just return and don't add it. The
     // _checkDuplicate function deals with it all for us.
     if (this._checkDuplicate(card, emailAddress))
       return;
 
     // Find out where to insert the card.
     var insertPosition = 0;
--- a/mailnews/addrbook/test/unit/test_nsAbAutoCompleteSearch4.js
+++ b/mailnews/addrbook/test/unit/test_nsAbAutoCompleteSearch4.js
@@ -27,17 +27,19 @@ const cards = [
   // ensure the order is always consistent.
   { email: "c@test.invalid", secondEmail: "a@test.invalid",
     displayName: "2testsort" },
   { email: "d@test.invalid", secondEmail: "e@test.invalid",
     displayName: "2testsort" },
   { email: "g@test.invalid", secondEmail: "f@test.invalid",
     displayName: "3testsort", popularityIndex: 3 },
   { email: "j@test.invalid", secondEmail: "h@test.invalid",
-    displayName: "3testsort", popularityIndex: 5 }
+    displayName: "3testsort", popularityIndex: 5 },
+  // Add a contact that matches, but has no email. Should not show up.
+  { displayName: "primaryX" }
 ];
 
 // These are for the initial search
 const searches = [ "primary", "second", "firstName", "thename", "sortbasic",
                    "testsort", "2testsort", "3testsort" ];
 
 const expectedResults = [ [ "primary@test.invalid",
                             "second@test.invalid" ], // searching for primary/second returns