fix for #57151. r=bienvenu, sr=mscott. properly migrate the users addressbook

when they are non-ascii.
This commit is contained in:
sspitzer%netscape.com 2000-10-26 03:39:24 +00:00
Родитель 6b78ed1b12
Коммит 3995a26e5b
3 изменённых файлов: 30 добавлений и 0 удалений

Просмотреть файл

@ -28,4 +28,5 @@ interface nsIAbUpgrader : nsISupports {
void StartUpgrade4xAddrBook(in nsIFileSpec sourceAddrBook, in nsIFileSpec destAddrBook);
void ContinueExport(out boolean done);
attribute string currentCharset;
};

Просмотреть файл

@ -1495,6 +1495,14 @@ NS_IMETHODIMP nsAddressBook::ImportAddressBook()
// check to see that that file doesn't exist.
// what if there are colision?
// set the current charset to "", so later we'll use the system charset
//
// when importing .na2 files from disk, we really
// have no idea what the charset was (it's in the 4.x prefs file)
// so we just guess that it is the system charset.
rv = abUpgrader->SetCurrentCharset("");
if (NS_FAILED(rv)) return rv;
rv = ConvertNA2toLDIF(fileSpec, tmpLDIFFile);
if (NS_FAILED(rv)) return rv;

Просмотреть файл

@ -1737,6 +1737,7 @@ static PRBool charEndsWith(const char *str, const char *endStr)
#define ADDRESSBOOK_PREF_NAME_ROOT "ldap_2.servers."
#define ADDRESSBOOK_PREF_NAME_SUFFIX ".filename"
#define ADDRESSBOOK_PREF_CSID_SUFFIX ".csid"
#define ADDRESSBOOK_PREF_VALUE_4x_SUFFIX ".na2"
#define ADDRESSBOOK_PREF_VALUE_5x_SUFFIX ".mab"
#define TEMP_LDIF_FILE_SUFFIX ".ldif"
@ -1826,6 +1827,26 @@ nsMessengerMigrator::migrateAddressBookPrefEnum(const char *aPref, void *aClosur
if (NS_FAILED(rv)) return;
}
// get the csid from the prefs
nsCAutoString csidPrefName;
csidPrefName = ADDRESSBOOK_PREF_NAME_ROOT;
csidPrefName += abName;
csidPrefName += ADDRESSBOOK_PREF_CSID_SUFFIX;
nsXPIDLCString csidPrefValue;
rv = prefs->CopyCharPref((const char *)csidPrefName,getter_Copies(csidPrefValue));
if (NS_FAILED(rv)) {
// if we fail to get the pref value, set it to "", which will
// later cause us to use the system charset
*((char **)getter_Copies(csidPrefValue)) = nsXPIDLCString::Copy("");
}
nsCOMPtr <nsIAbUpgrader> abUpgrader = do_GetService(NS_AB4xUPGRADER_CONTRACTID, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv) && abUpgrader, "failed to get upgrader");
if (NS_FAILED(rv) || !abUpgrader) return;
rv = abUpgrader->SetCurrentCharset((const char *)csidPrefValue);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to set the current char set");
if (NS_FAILED(rv)) return;
// HACK: I need to rename pab.ldif -> abook.ldif, because a bunch of places are hacked to point to abook.mab, and when I import abook.ldif it will create abook.mab. this is a temporary hack and will go away soon.
if (!PL_strcmp((const char *)abName,"pab")) {
abName = "abook";