From 16a527d0a8435fee9449e85349447726d73fdb31 Mon Sep 17 00:00:00 2001 From: "nhotta%netscape.com" Date: Sat, 1 Dec 2001 17:36:35 +0000 Subject: [PATCH] For search, cache default charset to the class. For eudora, changed to get a pref directly, bug 110127, r=naving, sr=bienvenu. --- .../base/search/public/nsMsgSearchAdapter.h | 2 ++ .../base/search/src/nsMsgSearchAdapter.cpp | 35 +++++++++---------- mailnews/import/eudora/src/makefile.win | 1 + .../import/eudora/src/nsEudoraCompose.cpp | 9 +++-- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/mailnews/base/search/public/nsMsgSearchAdapter.h b/mailnews/base/search/public/nsMsgSearchAdapter.h index 629008b85e6c..b8304f451e47 100644 --- a/mailnews/base/search/public/nsMsgSearchAdapter.h +++ b/mailnews/base/search/public/nsMsgSearchAdapter.h @@ -79,6 +79,8 @@ public: nsCOMPtr m_searchTerms; /* linked list of criteria terms */ PRBool m_abortCalled; + nsXPIDLString m_defaultCharset; + PRBool m_forceAsciiSearch; static nsresult EncodeImap (char **ppEncoding, nsISupportsArray *searchTerms, diff --git a/mailnews/base/search/src/nsMsgSearchAdapter.cpp b/mailnews/base/search/src/nsMsgSearchAdapter.cpp index 210454238a2c..18b8098d0182 100644 --- a/mailnews/base/search/src/nsMsgSearchAdapter.cpp +++ b/mailnews/base/search/src/nsMsgSearchAdapter.cpp @@ -78,7 +78,6 @@ const char *nsMsgSearchAdapter::m_kImapNotSeen = " UNSEEN "; const char *nsMsgSearchAdapter::m_kImapNotAnswered = " UNANSWERED "; const char *nsMsgSearchAdapter::m_kImapCharset = " CHARSET "; -static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #define PREF_CUSTOM_HEADERS "mailnews.customHeaders" @@ -321,13 +320,20 @@ char *nsMsgSearchAdapter::UnEscapeSearchUrl (const char *commandSpecificData) void nsMsgSearchAdapter::GetSearchCharsets(nsString &srcCharset, nsString& dstCharset) { - nsresult rv; - nsAutoString defaultCharset; - char *search_charset = nsMsgI18NGetDefaultMailCharset(); - defaultCharset.AssignWithConversion(search_charset); - PR_Free((void *)search_charset); - srcCharset = defaultCharset; - dstCharset = defaultCharset; + nsresult rv; + if (m_defaultCharset.IsEmpty()) + { + m_forceAsciiSearch = PR_FALSE; // set the default value in case of error + nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv)) + { + rv = prefs->GetLocalizedUnicharPref("mailnews.view_default_charset", getter_Copies(m_defaultCharset)); + rv = prefs->GetBoolPref("mailnews.force_ascii_search", &m_forceAsciiSearch); + } + } + srcCharset.Assign(m_defaultCharset.IsEmpty() ? + NS_LITERAL_STRING("ISO-8859-1") : m_defaultCharset); + dstCharset = srcCharset; if (m_scope) { @@ -351,19 +357,10 @@ nsMsgSearchAdapter::GetSearchCharsets(nsString &srcCharset, nsString& dstCharset // the source. (CS_DEFAULT is an indication that the charset // was undefined or unavailable.) // ### well, it's not really anymore. Is there an equivalent? - if (!nsCRT::strcmp(dstCharset.get(), defaultCharset.get())) + if (!nsCRT::strcmp(dstCharset.get(), m_defaultCharset.get())) dstCharset = srcCharset; - PRBool forceAscii = PR_FALSE; - - nsCOMPtr prefs(do_GetService(kPrefServiceCID, &rv)); - - if (NS_SUCCEEDED(rv)) - { - rv = prefs->GetBoolPref("mailnews.force_ascii_search", &forceAscii); - } - - if (forceAscii) + if (m_forceAsciiSearch) { // Special cases to use in order to force US-ASCII searching with Latin1 // or MacRoman text. Eurgh. This only has to happen because IMAP diff --git a/mailnews/import/eudora/src/makefile.win b/mailnews/import/eudora/src/makefile.win index c066a6fba49d..33dfc141881a 100644 --- a/mailnews/import/eudora/src/makefile.win +++ b/mailnews/import/eudora/src/makefile.win @@ -36,6 +36,7 @@ REQUIRES = xpcom \ msglocal \ mimetype \ unicharutil \ + pref \ $(NULL) LIBRARY_NAME = $(MODULE) META_COMPONENT = mail diff --git a/mailnews/import/eudora/src/nsEudoraCompose.cpp b/mailnews/import/eudora/src/nsEudoraCompose.cpp index 28ec3ae34542..5815e055f434 100644 --- a/mailnews/import/eudora/src/nsEudoraCompose.cpp +++ b/mailnews/import/eudora/src/nsEudoraCompose.cpp @@ -47,6 +47,7 @@ #include "EudoraDebugLog.h" #include "nsMimeTypes.h" +#include "nsIPref.h" static NS_DEFINE_CID( kMsgSendCID, NS_MSGSEND_CID); static NS_DEFINE_CID( kMsgCompFieldsCID, NS_MSGCOMPFIELDS_CID); @@ -619,9 +620,11 @@ nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg) { // last resort if (!m_defCharset.Length()) { - char *pSet = nsMsgI18NGetDefaultMailCharset(); - m_defCharset.AssignWithConversion(pSet); - nsCRT::free( pSet); + nsXPIDLString defaultCharset; + nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv)) + rv = prefs->GetLocalizedUnicharPref("mailnews.view_default_charset", getter_Copies(defaultCharset)); + m_defCharset.Assign(defaultCharset ? defaultCharset.get() : NS_LITERAL_STRING("ISO-8859-1").get()); } headerVal = m_defCharset; }