diff --git a/mailnews/base/util/nsMsgIdentity.cpp b/mailnews/base/util/nsMsgIdentity.cpp index 30d22e02983e..cd4b241de93b 100644 --- a/mailnews/base/util/nsMsgIdentity.cpp +++ b/mailnews/base/util/nsMsgIdentity.cpp @@ -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)) { diff --git a/mailnews/base/util/nsMsgIdentity.h b/mailnews/base/util/nsMsgIdentity.h index 0dd5e664477f..9daa6b1ddb85 100644 --- a/mailnews/base/util/nsMsgIdentity.h +++ b/mailnews/base/util/nsMsgIdentity.h @@ -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) \