Bug 1522453 - Prevent cards without an email address being added to a mailing list. r=mkmelin a=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Sat, 09 Mar 2019 11:15:09 +0100
changeset 32111 710e2086db86f72a57a822235ab6d3a4cb055f6a
parent 32110 82a60dbc0d9521e028dec410908ddb882a8066ce
child 32112 62a9df6d2883f2525162b25acd74d08b4d1d2183
push id162
push usermozilla@jorgk.com
push dateSat, 09 Mar 2019 10:20:28 +0000
treeherdercomm-esr60@62a9df6d2883 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, jorgk
bugs1522453
Bug 1522453 - Prevent cards without an email address being added to a mailing list. r=mkmelin a=jorgk
mailnews/addrbook/src/nsAddrDatabase.cpp
mailnews/addrbook/test/unit/test_bug1522453.js
--- a/mailnews/addrbook/src/nsAddrDatabase.cpp
+++ b/mailnews/addrbook/src/nsAddrDatabase.cpp
@@ -1190,16 +1190,19 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewL
 
   uint32_t count;
   addressList->GetLength(&count);
 
   nsAutoString newEmail;
   rv = newCard->GetPrimaryEmail(newEmail);
   NS_ENSURE_SUCCESS(rv,rv);
 
+  if (newEmail.IsEmpty())
+    return NS_OK;
+
   uint32_t i;
   for (i = 0; i < count; i++) {
     nsCOMPtr<nsIAbCard> currentCard = do_QueryElementAt(addressList, i, &rv);
     NS_ENSURE_SUCCESS(rv,rv);
 
     bool equals;
     rv = newCard->Equals(currentCard, &equals);
     NS_ENSURE_SUCCESS(rv,rv);
--- a/mailnews/addrbook/test/unit/test_bug1522453.js
+++ b/mailnews/addrbook/test/unit/test_bug1522453.js
@@ -43,9 +43,44 @@ function run_test() {
 
   // list.childCards should contain contacts 1 and 3, and crucially, not die at 2.
   let listCards = list.childCards;
   ok(listCards.hasMoreElements());
   equal(contact1.UID, listCards.getNext().QueryInterface(Ci.nsIAbCard).UID);
   ok(listCards.hasMoreElements());
   equal(contact3.UID, listCards.getNext().QueryInterface(Ci.nsIAbCard).UID);
   ok(!listCards.hasMoreElements());
+
+  // list.addressLists should contain contacts 1 and 3.
+  let listEnum = list.addressLists.enumerate();
+  ok(listEnum.hasMoreElements());
+  equal(contact1.UID, listEnum.getNext().QueryInterface(Ci.nsIAbCard).UID);
+  ok(listEnum.hasMoreElements());
+  equal(contact3.UID, listEnum.getNext().QueryInterface(Ci.nsIAbCard).UID);
+  ok(!listEnum.hasMoreElements());
+
+  // Reload the address book manager.
+  Services.obs.notifyObservers(null, "addrbook-reload");
+
+  MailServices.ab.directories;
+  book = MailServices.ab.getDirectory(kPABData.URI);
+
+  // For some unknown reason this is necessary for book.addressLists to be populated.
+  book.QueryInterface(Ci.nsIAbMDBDirectory).database.getMailingListsFromDB(book);
+  equal(1, book.addressLists.Count());
+  list = book.addressLists.GetElementAt(0).QueryInterface(Ci.nsIAbDirectory);
+
+  // list.childCards should contain contacts 1 and 3.
+  listCards = list.childCards;
+  ok(listCards.hasMoreElements());
+  equal(contact1.UID, listCards.getNext().QueryInterface(Ci.nsIAbCard).UID);
+  ok(listCards.hasMoreElements());
+  equal(contact3.UID, listCards.getNext().QueryInterface(Ci.nsIAbCard).UID);
+  ok(!listCards.hasMoreElements());
+
+  // list.addressLists should contain contacts 1 and 3.
+  listEnum = list.addressLists.enumerate();
+  ok(listEnum.hasMoreElements());
+  equal(contact1.UID, listEnum.getNext().QueryInterface(Ci.nsIAbCard).UID);
+  ok(listEnum.hasMoreElements());
+  equal(contact3.UID, listEnum.getNext().QueryInterface(Ci.nsIAbCard).UID);
+  ok(!listEnum.hasMoreElements());
 }