DIR_ForceFlag(server, DIR_LDAP_VERSION3, PR_TRUE);
nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, const char * uri, int maxHits, const char * authDn, DirectoryType dirType, DIR_Server** pServer){  DIR_Server * server = (DIR_Server *) PR_Malloc(sizeof(DIR_Server));  DIR_InitServerWithType (server, dirType);  if (!dir_ServerList)    DIR_GetDirServers();  if (dir_ServerList)  {    PRInt32 count = dir_ServerList->Count();        NS_ConvertUCS2toUTF8 utf8str(dirName);    server->description = ToNewCString(utf8str);    server->position = count + 1;        if (fileName)      server->fileName = nsCRT::strdup(fileName);    else      DIR_SetFileName(&server->fileName, kPersonalAddressbook);    if (dirType == LDAPDirectory) {      // We don't actually allow the password to be saved in the preferences;      // this preference is (effectively) ignored by the current code base.        // It's here because versions of Mozilla 1.0 and earlier (maybe 1.1alpha      // too?) would blow away the .auth.dn preference if .auth.savePassword      // is not set.  To avoid trashing things for users who switch between      // versions, we'll set it.  Once the versions in question become       // obsolete enough, this workaround can be gotten rid of.      server->savePassword = PR_TRUE;      if (uri)        server->uri = nsCRT::strdup(uri);      if (authDn)        server->authDn = nsCRT::strdup(authDn);    }    if (maxHits)      server->maxHits = maxHits;        dir_ServerList->AppendElement(server);    if (!migrating) {      DIR_SavePrefsForOneServer(server);     }    else if (!server->prefName)    {      // Need to return pref names here so the caller will be able to get the      // right directory properties. For migration, pref names were already      // created so no need to get unique ones via DIR_CreateServerPrefName().      if (!strcmp(server->fileName, kPersonalAddressbook))        server->prefName = nsCRT::strdup("ldap_2.servers.pab");      else if (!strcmp(server->fileName, kCollectedAddressbook))        server->prefName = nsCRT::strdup("ldap_2.servers.history");      else      {        char * leafName = dir_ConvertDescriptionToPrefName (server);        if (leafName)          server->prefName = PR_smprintf(PREF_LDAP_SERVER_TREE_NAME".%s", leafName);      }    }#ifdef DEBUG_sspitzer    else {      printf("don't set the prefs, they are already set since this ab was migrated\n");    }#endif    *pServer = server;        // save new address book into pref file     nsresult rv = NS_OK;    nsCOMPtr<nsIPref> pPref(do_GetService(NS_PREF_CONTRACTID, &rv));     if (NS_FAILED(rv) || !pPref)       return NS_ERROR_FAILURE;    pPref->SavePrefFile(nsnull);        return NS_OK;  }  return NS_ERROR_FAILURE;}