diff --git a/mailnews/addrbook/src/nsAbBSDirectory.cpp b/mailnews/addrbook/src/nsAbBSDirectory.cpp index 5ce83b0074..f94e6880d6 100644 --- a/mailnews/addrbook/src/nsAbBSDirectory.cpp +++ b/mailnews/addrbook/src/nsAbBSDirectory.cpp @@ -64,9 +64,13 @@ nsresult nsAbBSDirectory::CreateDirectoriesFromFactory(const nsACString &aURI, nsCOMPtr childDir = do_QueryInterface(newDirSupports, &rv); if (NS_FAILED(rv)) continue; - // Define a relationship between the preference - // entry and the directory - mServers.Put(aURI, aServer); + // In some cases (LDAP) the actual URI of the directory may differ from + // aURI. Use the URI of the directory. + nsCString uri; + childDir->GetURI(uri); + + // Define a relationship between the preference entry and the directory. + mServers.Put(uri, aServer); mSubDirectories.AppendObject(childDir); diff --git a/mailnews/addrbook/test/unit/test_ldap1.js b/mailnews/addrbook/test/unit/test_ldap1.js index 2c3fbf048e..8588323b60 100644 --- a/mailnews/addrbook/test/unit/test_ldap1.js +++ b/mailnews/addrbook/test/unit/test_ldap1.js @@ -14,6 +14,8 @@ function run_test() { return; } + let abCountBeforeStart = [...MailServices.ab.directories].length; + // Test - Create an LDAP directory let abUri = MailServices.ab.newAddressBook( "test", @@ -21,6 +23,9 @@ function run_test() { kLDAPDirectory ); + let abCountAfterCreate = [...MailServices.ab.directories].length; + Assert.equal(abCountAfterCreate, abCountBeforeStart + 1); + // Test - Check we have the directory. let abDir = MailServices.ab .getDirectory(kLDAPUriPrefix + abUri) @@ -193,4 +198,9 @@ function run_test() { } localAcTests.forEach(checkAc); + + MailServices.ab.deleteAddressBook(abDir.URI); + + let abCountAfterDelete = [...MailServices.ab.directories].length; + Assert.equal(abCountAfterDelete, abCountBeforeStart); }