Bug 1270651 - fix deletion of AB cards after search. r=rkent a=jorgk
authoraceman <acelists@atlas.sk>
Fri, 13 May 2016 07:20:40 +0200
changeset 27183 83d52c8dc8a6f61833a649ba2dcf8d64cc5d4745
parent 27182 1800cce8869a1d8e21e2977577682bd0d33c7930
child 27184 c238dd759028670d36dbf7250f42c292168e1463
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)
reviewersrkent, jorgk
bugs1270651
Bug 1270651 - fix deletion of AB cards after search. r=rkent a=jorgk
mailnews/addrbook/src/nsAbMDBDirectory.cpp
--- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp
@@ -48,34 +48,39 @@ NS_IMPL_ISUPPORTS_INHERITED(nsAbMDBDirec
                              nsIAbDirectorySearch,
                              nsIAddrDBListener)
 
 NS_IMETHODIMP nsAbMDBDirectory::Init(const char *aUri)
 {
   // We need to ensure  that the m_DirPrefId is initialized properly
   nsDependentCString uri(aUri);
 
-  if (uri.Find("MailList") != -1)
+  // Find the first ? (of the search params) if there is one.
+  // We know we can start at the end of the moz-abmdbdirectory:// because
+  // that's the URI we should have been passed.
+  int32_t searchCharLocation = uri.FindChar('?', kMDBDirectoryRootLen);
+  nsAutoCString URINoQuery;
+  if (searchCharLocation != kNotFound)
+  {
+    URINoQuery = Substring(uri, 0, searchCharLocation);
+  } else {
+    URINoQuery.Assign(uri);
+  }
+
+  // In the non-query part of the URI, check if we are a mailinglist
+  if (URINoQuery.Find("MailList") != kNotFound)
     m_IsMailList = true;
 
   // Mailing lists don't have their own prefs.
   if (m_DirPrefId.IsEmpty() && !m_IsMailList)
   {
-    // Find the first ? (of the search params) if there is one.
-    // We know we can start at the end of the moz-abmdbdirectory:// because
-    // that's the URI we should have been passed.
-    int32_t searchCharLocation = uri.FindChar('?', kMDBDirectoryRootLen);
-
     nsAutoCString filename;
 
-    // extract the filename from the uri.
-    if (searchCharLocation == -1)
-      filename = Substring(uri, kMDBDirectoryRootLen);
-    else
-      filename = Substring(uri, kMDBDirectoryRootLen, searchCharLocation - kMDBDirectoryRootLen);
+    // Extract the filename from the uri.
+    filename = Substring(URINoQuery, kMDBDirectoryRootLen);
 
     // Get the pref servers and the address book directory branch
     nsresult rv;
     nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIPrefBranch> prefBranch;
     rv = prefService->GetBranch(NS_LITERAL_CSTRING(PREF_LDAP_SERVER_TREE_NAME ".").get(),