fix #78289. if special folder prefs are not set, we can crash on saving

drafts and templates.

if those aren't set, we use the default values specified in mailnews.js

fix by cavin@netscape.com, r/sr=sspitzer@netscape.com
This commit is contained in:
sspitzer%netscape.com 2001-05-03 00:31:36 +00:00
Родитель de64ebfaec
Коммит dc22cd49d9
2 изменённых файлов: 23 добавлений и 6 удалений

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

@ -425,15 +425,29 @@ NS_IMPL_IDPREF_STR (BccList, "bcc_other_list");
NS_IMPL_FOLDERPREF_STR (DraftFolder, "draft_folder");
NS_IMPL_FOLDERPREF_STR (StationeryFolder, "stationery_folder");
NS_IMPL_IDPREF_STR (JunkMailFolder, "spam_folder");
NS_IMPL_FOLDERPREF_STR (JunkMailFolder, "spam_folder");
NS_IMPL_IDPREF_BOOL(ShowSaveMsgDlg, "showSaveMsgDlg");
NS_IMPL_IDPREF_BOOL(Valid, "valid");
nsresult
nsMsgIdentity::getFolderPref(const char *prefname, char **retval)
nsMsgIdentity::getFolderPref(const char *prefname, char **retval, PRBool mustHaveDefault)
{
return getCharPref(prefname, retval);
nsresult rv = getCharPref(prefname, retval);
if (!mustHaveDefault) return rv;
// Use default value if fail to get or not set
if (NS_FAILED(rv) || !*retval || !nsCRT::strlen(*retval))
{
PR_FREEIF(*retval); // free the empty string
rv = getDefaultCharPref(prefname, retval);
if (NS_SUCCEEDED(rv) && *retval)
{
rv = setFolderPref(prefname, (const char *)*retval);
}
}
return rv;
}
nsresult
@ -455,7 +469,8 @@ nsMsgIdentity::setFolderPref(const char *prefname, const char *value)
else
return NS_ERROR_FAILURE;
rv = getFolderPref(prefname, getter_Copies(oldpref));
// get the old folder, and clear the special folder flag on it
rv = getFolderPref(prefname, getter_Copies(oldpref), PR_FALSE);
if (NS_SUCCEEDED(rv) && (const char*)oldpref)
{
rv = rdf->GetResource(oldpref, getter_AddRefs(res));
@ -466,6 +481,8 @@ nsMsgIdentity::setFolderPref(const char *prefname, const char *value)
rv = folder->ClearFlag(folderflag);
}
}
// set the new folder, and set the special folder flags on it
rv = setCharPref(prefname, value);
if (NS_SUCCEEDED(rv))
{

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

@ -67,7 +67,7 @@ protected:
nsresult getDefaultIntPref(const char *pref, PRInt32 *);
nsresult setIntPref(const char *pref, PRInt32);
nsresult getFolderPref(const char *pref, char **);
nsresult getFolderPref(const char *pref, char **, PRBool);
nsresult setFolderPref(const char *pref, const char *);
private:
@ -131,7 +131,7 @@ nsMsgIdentity::Set##_postfix(PRInt32 value) \
NS_IMETHODIMP \
nsMsgIdentity::Get##_postfix(char **retval) \
{ \
return getFolderPref(_prefname, retval); \
return getFolderPref(_prefname, retval, PR_TRUE); \
} \
NS_IMETHODIMP \
nsMsgIdentity::Set##_postfix(const char *value) \