fix for 40346 - make the search term value PRUnichar* to make it i18n friendly

r=bienvenu
This commit is contained in:
alecf%netscape.com 2000-06-06 23:19:32 +00:00
parent c1551a0116
commit 396e8e21e0
10 changed files with 121 additions and 112 deletions

View File

@ -32,7 +32,7 @@ interface nsIMsgSearchValue : nsISupports {
// accessing these will throw an exception if the above // accessing these will throw an exception if the above
// attribute does not match the type! // attribute does not match the type!
attribute string str; attribute wstring str;
attribute nsMsgPriorityValue priority; attribute nsMsgPriorityValue priority;
attribute PRTime date; attribute PRTime date;
attribute unsigned long status; // see MSG_FLAG in msgcom.h attribute unsigned long status; // see MSG_FLAG in msgcom.h

View File

@ -23,11 +23,7 @@
#include "MailNewsTypes2.idl" #include "MailNewsTypes2.idl"
#include "nsIMsgFolder.idl" #include "nsIMsgFolder.idl"
interface nsIMsgHeaderParser; #include "nsIMsgHeaderParser.idl"
%{C++
#include "nsIMsgHeaderParser.h"
%}
interface nsIMsgDatabase; interface nsIMsgDatabase;
interface nsIMsgDBHdr; interface nsIMsgDBHdr;
@ -219,14 +215,3 @@ class nsMsgDIRServer;
[ptr] native nsSearchMenuItem(nsSearchMenuItem); [ptr] native nsSearchMenuItem(nsSearchMenuItem);
%{C++
/* Use this to help build menus in the search dialog. See APIs below */
#define kMsgSearchMenuLength 64
typedef struct nsMsgSearchMenuItem
{
int16 attrib;
char name[kMsgSearchMenuLength];
PRBool isEnabled;
} nsMsgSearchMenuItem;
%}

View File

@ -50,12 +50,8 @@ nsMsgFilterDataSource::nsMsgFilterDataSource()
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
if (mGlobalRefCount == 0) if (mGlobalRefCount++ == 0)
initGlobalObjects(getRDFService()); initGlobalObjects(getRDFService());
mGlobalRefCount++;
/* member initializers and constructor code */
} }
nsMsgFilterDataSource::~nsMsgFilterDataSource() nsMsgFilterDataSource::~nsMsgFilterDataSource()

View File

@ -52,7 +52,7 @@ nsresult nsMsgSearchOnlineMail::ValidateTerms ()
GetSearchCharsets(srcCharset, dstCharset); GetSearchCharsets(srcCharset, dstCharset);
// do IMAP specific validation // do IMAP specific validation
err = Encode (&m_encoding, m_searchTerms, srcCharset.GetUnicode(), dstCharset.GetUnicode()); err = Encode (m_encoding, m_searchTerms, dstCharset.GetUnicode());
NS_ASSERTION(NS_SUCCEEDED(err), "failed to encode imap search"); NS_ASSERTION(NS_SUCCEEDED(err), "failed to encode imap search");
} }
@ -239,9 +239,11 @@ nsresult nsMsgSearchOnlineMail::Search (PRBool *aDone)
} }
nsresult nsMsgSearchOnlineMail::Encode (nsCString *pEncoding, nsISupportsArray *searchTerms, const PRUnichar *srcCharset, const PRUnichar *destCharset) nsresult nsMsgSearchOnlineMail::Encode (nsCString& pEncoding,
nsISupportsArray *searchTerms,
const PRUnichar *destCharset)
{ {
char *imapTerms = nsnull; nsXPIDLCString imapTerms;
//check if searchTerms are ascii only //check if searchTerms are ascii only
PRBool asciiOnly = PR_TRUE; PRBool asciiOnly = PR_TRUE;
@ -263,7 +265,7 @@ nsresult nsMsgSearchOnlineMail::Encode (nsCString *pEncoding, nsISupportsArray *
pTerm->GetAttrib(&attribute); pTerm->GetAttrib(&attribute);
if (IsStringAttribute(attribute)) if (IsStringAttribute(attribute))
{ {
char *pchar; PRUnichar *pchar;
nsCOMPtr <nsIMsgSearchValue> searchValue; nsCOMPtr <nsIMsgSearchValue> searchValue;
nsresult rv = pTerm->GetValue(getter_AddRefs(searchValue)); nsresult rv = pTerm->GetValue(getter_AddRefs(searchValue));
@ -276,7 +278,7 @@ nsresult nsMsgSearchOnlineMail::Encode (nsCString *pEncoding, nsISupportsArray *
continue; continue;
for (; *pchar ; pchar++) for (; *pchar ; pchar++)
{ {
if (*pchar & 0x80) if (*pchar & 0xFF80)
{ {
asciiOnly = PR_FALSE; asciiOnly = PR_FALSE;
break; break;
@ -293,13 +295,13 @@ nsresult nsMsgSearchOnlineMail::Encode (nsCString *pEncoding, nsISupportsArray *
// Get the optional CHARSET parameter, in case we need it. // Get the optional CHARSET parameter, in case we need it.
char *csname = GetImapCharsetParam(asciiOnly ? usAsciiCharSet.GetUnicode() : destCharset); char *csname = GetImapCharsetParam(asciiOnly ? usAsciiCharSet.GetUnicode() : destCharset);
nsresult err = nsMsgSearchAdapter::EncodeImap (&imapTerms, searchTerms, srcCharset, asciiOnly ? usAsciiCharSet.GetUnicode(): destCharset, PR_FALSE); nsresult err = nsMsgSearchAdapter::EncodeImap (getter_Copies(imapTerms), searchTerms, asciiOnly ? usAsciiCharSet.GetUnicode(): destCharset, PR_FALSE);
if (NS_SUCCEEDED(err)) if (NS_SUCCEEDED(err))
{ {
pEncoding->Append("SEARCH"); pEncoding.Append("SEARCH");
if (csname) if (csname)
pEncoding->Append(csname); pEncoding.Append(csname);
pEncoding->Append(imapTerms); pEncoding.Append(imapTerms);
} }
PR_FREEIF(csname); PR_FREEIF(csname);
return err; return err;

View File

@ -21,6 +21,7 @@
*/ */
#include "msgCore.h" #include "msgCore.h"
#include "nsTextFormatter.h"
#include "nsMsgSearchCore.h" #include "nsMsgSearchCore.h"
#include "nsMsgSearchAdapter.h" #include "nsMsgSearchAdapter.h"
#include "nsMsgSearchScopeTerm.h" #include "nsMsgSearchScopeTerm.h"
@ -129,7 +130,9 @@ NS_IMETHODIMP nsMsgSearchAdapter::AddHit(nsMsgKey key)
char * char *
nsMsgSearchAdapter::TryToConvertCharset(const char *sourceStr, const PRUnichar *srcCharset, const PRUnichar * destCharset, PRBool useMime2) nsMsgSearchAdapter::TryToConvertCharset(const PRUnichar *sourceStr,
const PRUnichar * destCharset,
PRBool useMime2)
{ {
char *result = nsnull; char *result = nsnull;
@ -198,23 +201,24 @@ nsMsgSearchAdapter::GetImapCharsetParam(const PRUnichar *destCharset)
return result; return result;
} }
char *nsMsgSearchAdapter::EscapeSearchUrl (const char *nntpCommand) PRUnichar *nsMsgSearchAdapter::EscapeSearchUrl (const PRUnichar *nntpCommand)
{ {
char *result = nsnull; PRUnichar *result = nsnull;
// max escaped length is two extra characters for every character in the cmd. // max escaped length is two extra characters for every character in the cmd.
char *scratchBuf = (char*) PR_Malloc(3*nsCRT::strlen(nntpCommand) + 1); PRUnichar *scratchBuf = (PRUnichar*) PR_Malloc(3*nsCRT::strlen(nntpCommand) + 1);
if (scratchBuf) if (scratchBuf)
{ {
char *scratchPtr = scratchBuf; PRUnichar *scratchPtr = scratchBuf;
while (PR_TRUE) while (PR_TRUE)
{ {
char ch = *nntpCommand++; PRUnichar ch = *nntpCommand++;
if (!ch) if (!ch)
break; break;
if (ch == '#' || ch == '?' || ch == '@' || ch == '\\') if (ch == '#' || ch == '?' || ch == '@' || ch == '\\')
{ {
*scratchPtr++ = '\\'; *scratchPtr++ = '\\';
sprintf (scratchPtr, "%X", ch); nsTextFormatter::snprintf(scratchPtr, 2,
NS_ConvertASCIItoUCS2("%2.2X").GetUnicode(), ch);
/* Reviewed 4.51 safe use of sprintf */ /* Reviewed 4.51 safe use of sprintf */
scratchPtr += 2; scratchPtr += 2;
} }
@ -222,51 +226,55 @@ char *nsMsgSearchAdapter::EscapeSearchUrl (const char *nntpCommand)
*scratchPtr++ = ch; *scratchPtr++ = ch;
} }
*scratchPtr = '\0'; *scratchPtr = '\0';
result = PL_strdup (scratchBuf); // realloc down to smaller size result = nsCRT::strdup (scratchBuf); // realloc down to smaller size
nsCRT::free (scratchBuf); nsCRT::free (scratchBuf);
} }
return result; return result;
} }
char *nsMsgSearchAdapter::EscapeImapSearchProtocol(const char *imapCommand) PRUnichar *
nsMsgSearchAdapter::EscapeImapSearchProtocol(const PRUnichar *imapCommand)
{ {
char *result = nsnull; PRUnichar *result = nsnull;
// max escaped length is one extra character for every character in the cmd. // max escaped length is one extra character for every character in the cmd.
char *scratchBuf = (char*) PR_Malloc (2*nsCRT::strlen(imapCommand) + 1); PRUnichar *scratchBuf =
(PRUnichar*) PR_Malloc (2*nsCRT::strlen(imapCommand) + 1);
if (scratchBuf) if (scratchBuf)
{ {
char *scratchPtr = scratchBuf; PRUnichar *scratchPtr = scratchBuf;
while (1) while (1)
{ {
char ch = *imapCommand++; PRUnichar ch = *imapCommand++;
if (!ch) if (!ch)
break; break;
if (ch == '\\') if (ch == (PRUnichar)'\\')
{ {
*scratchPtr++ = '\\'; *scratchPtr++ = (PRUnichar)'\\';
*scratchPtr++ = '\\'; *scratchPtr++ = (PRUnichar)'\\';
} }
else else
*scratchPtr++ = ch; *scratchPtr++ = ch;
} }
*scratchPtr = '\0'; *scratchPtr = 0;
result = nsCRT::strdup (scratchBuf); // realloc down to smaller size result = nsCRT::strdup (scratchBuf); // realloc down to smaller size
nsCRT::free (scratchBuf); nsCRT::free (scratchBuf);
} }
return result; return result;
} }
char *nsMsgSearchAdapter::EscapeQuoteImapSearchProtocol(const char *imapCommand) PRUnichar *
nsMsgSearchAdapter::EscapeQuoteImapSearchProtocol(const PRUnichar *imapCommand)
{ {
char *result = nsnull; PRUnichar *result = nsnull;
// max escaped length is one extra character for every character in the cmd. // max escaped length is one extra character for every character in the cmd.
char *scratchBuf = (char*) PR_Malloc (2*nsCRT::strlen(imapCommand) + 1); PRUnichar *scratchBuf =
(PRUnichar*) PR_Malloc (2*nsCRT::strlen(imapCommand) + 1);
if (scratchBuf) if (scratchBuf)
{ {
char *scratchPtr = scratchBuf; PRUnichar *scratchPtr = scratchBuf;
while (1) while (1)
{ {
char ch = *imapCommand++; PRUnichar ch = *imapCommand++;
if (!ch) if (!ch)
break; break;
if (ch == '"') if (ch == '"')
@ -556,9 +564,9 @@ nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool real
if (IsStringAttribute(attrib)) if (IsStringAttribute(attrib))
{ {
char *unconvertedValue; // = reallyDredd ? MSG_EscapeSearchUrl (term->m_value.u.string) : msg_EscapeImapSearchProtocol(term->m_value.u.string); PRUnichar *convertedValue; // = reallyDredd ? MSG_EscapeSearchUrl (term->m_value.u.string) : msg_EscapeImapSearchProtocol(term->m_value.u.string);
nsXPIDLCString searchTermValue; nsXPIDLString searchTermValue;
searchValue->GetStr(getter_Copies(searchTermValue)); searchValue->GetStr(getter_Copies(searchTermValue));
// Ugly switch for Korean mail/news charsets. // Ugly switch for Korean mail/news charsets.
// We want to do this here because here is where // We want to do this here because here is where
// we know what charset we want to use. // we know what charset we want to use.
@ -569,25 +577,28 @@ nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool real
dest_csid = INTL_DefaultMailCharSetID(dest_csid); dest_csid = INTL_DefaultMailCharSetID(dest_csid);
#endif #endif
unconvertedValue = TryToConvertCharset((const char *) searchTermValue, // do all sorts of crazy escaping
srcCharset, convertedValue = reallyDredd ? EscapeSearchUrl (searchTermValue) :
destCharset, EscapeImapSearchProtocol(searchTermValue);
reallyDredd);
if (!unconvertedValue)
unconvertedValue = nsCRT::strdup((const char *) searchTermValue); // couldn't convert, send as is
value = reallyDredd ? EscapeSearchUrl (unconvertedValue) : EscapeImapSearchProtocol(unconvertedValue); useQuotes = !reallyDredd ||
PR_Free(unconvertedValue); (nsAutoString(convertedValue).FindChar((PRUnichar)' ') != -1);
valueWasAllocated = PR_TRUE;
useQuotes = !reallyDredd || (PL_strchr(value, ' ') != nsnull);
if (useQuotes) if (useQuotes)
{ {
unconvertedValue = value; PRUnichar *oldConvertedValue = convertedValue;
value = EscapeQuoteImapSearchProtocol(unconvertedValue); convertedValue = EscapeQuoteImapSearchProtocol(convertedValue);
PR_Free(unconvertedValue); nsCRT::free(oldConvertedValue);
} }
// now convert to char*
value = TryToConvertCharset(convertedValue, destCharset, reallyDredd);
// if couldn't convert, send as is
if (!value)
value = NS_ConvertUCS2toUTF8(convertedValue).ToNewCString();
nsCRT::free(convertedValue);
valueWasAllocated = PR_TRUE;
} }
} }

View File

@ -38,7 +38,9 @@ public:
NS_IMETHOD GetEncoding (char **result); NS_IMETHOD GetEncoding (char **result);
NS_IMETHOD AddResultElement (nsIMsgDBHdr *); NS_IMETHOD AddResultElement (nsIMsgDBHdr *);
static nsresult Encode (nsCString *ppEncoding, nsISupportsArray *searchTerms, const PRUnichar *srcCharset, const PRUnichar *destCharset); static nsresult Encode (nsCString& ppEncoding,
nsISupportsArray *searchTerms,
const PRUnichar *destCharset);
protected: protected:

View File

@ -75,30 +75,30 @@ nsresult nsMsgSearchNews::Search (PRBool *aDone)
} }
char *nsMsgSearchNews::EncodeValue (const char *value) PRUnichar *nsMsgSearchNews::EncodeToWildmat (const PRUnichar *value)
{ {
// Here we take advantage of XPAT's use of the wildmat format, which allows // Here we take advantage of XPAT's use of the wildmat format, which allows
// a case-insensitive match by specifying each case possibility for each character // a case-insensitive match by specifying each case possibility for each character
// So, "FooBar" is encoded as "[Ff][Oo][Bb][Aa][Rr]" // So, "FooBar" is encoded as "[Ff][Oo][Bb][Aa][Rr]"
char *caseInsensitiveValue = (char*) PR_Malloc ((4 * nsCRT::strlen(value)) + 1); PRUnichar *caseInsensitiveValue = (PRUnichar*) PR_Malloc ((4 * nsCRT::strlen(value)) + 1);
if (caseInsensitiveValue) if (caseInsensitiveValue)
{ {
char *walkValue = caseInsensitiveValue; PRUnichar *walkValue = caseInsensitiveValue;
while (*value) while (*value)
{ {
if (nsCRT::IsAsciiAlpha(*value)) if (nsCRT::IsAsciiAlpha(*value))
{ {
*walkValue++ = '['; *walkValue++ = (PRUnichar)'[';
*walkValue++ = (char)nsCRT::ToUpper((PRUnichar)*value); *walkValue++ = nsCRT::ToUpper((PRUnichar)*value);
*walkValue++ = (char)nsCRT::ToLower((PRUnichar)*value); *walkValue++ = nsCRT::ToLower((PRUnichar)*value);
*walkValue++ = ']'; *walkValue++ = (PRUnichar)']';
} }
else else
*walkValue++ = *value; *walkValue++ = *value;
value++; value++;
} }
*walkValue = '\0'; *walkValue = 0;
} }
return caseInsensitiveValue; return caseInsensitiveValue;
} }
@ -172,13 +172,12 @@ char *nsMsgSearchNews::EncodeTerm (nsIMsgSearchTerm *term)
return nsnull; return nsnull;
char *intlNonRFC1522Value = nsnull; nsXPIDLString intlNonRFC1522Value;
rv = searchValue->GetStr(&intlNonRFC1522Value); rv = searchValue->GetStr(getter_Copies(intlNonRFC1522Value));
if (!NS_SUCCEEDED(rv) || !intlNonRFC1522Value) if (!NS_SUCCEEDED(rv) || !intlNonRFC1522Value)
return nsnull; return nsnull;
char *caseInsensitiveValue = EncodeValue ((char*)intlNonRFC1522Value); PRUnichar *caseInsensitiveValue = EncodeToWildmat (intlNonRFC1522Value);
nsCRT::free(intlNonRFC1522Value);
if (!caseInsensitiveValue) if (!caseInsensitiveValue)
return nsnull; return nsnull;
@ -187,42 +186,44 @@ char *nsMsgSearchNews::EncodeTerm (nsIMsgSearchTerm *term)
// Need to add the INTL_FormatNNTPXPATInRFC1522Format call after we can do that // Need to add the INTL_FormatNNTPXPATInRFC1522Format call after we can do that
// so we should search a string in either RFC1522 format and non-RFC1522 format // so we should search a string in either RFC1522 format and non-RFC1522 format
char *escapedValue = EscapeSearchUrl (caseInsensitiveValue); PRUnichar *escapedValue = EscapeSearchUrl (caseInsensitiveValue);
nsCRT::free(caseInsensitiveValue); nsCRT::free(caseInsensitiveValue);
if (!escapedValue) if (!escapedValue)
return nsnull; return nsnull;
#if 0
// We also need to apply NET_Escape to it since we have to pass 8-bits data // We also need to apply NET_Escape to it since we have to pass 8-bits data
// And sometimes % in the 7-bit doulbe byte JIS // And sometimes % in the 7-bit doulbe byte JIS
// //
char * urlEncoded = nsEscape((char*)escapedValue, url_Path); PRUnichar * urlEncoded = nsEscape(escapedValue, url_Path);
nsCRT::free(escapedValue); nsCRT::free(escapedValue);
if (! urlEncoded) if (! urlEncoded)
return nsnull; return nsnull;
char *pattern = pattern = new char [nsCRT::strlen(urlEncoded) + overhead]; char *pattern = new char [nsCRT::strlen(urlEncoded) + overhead];
if (!pattern) if (!pattern)
return nsnull; return nsnull;
else else
pattern[0] = '\0'; pattern[0] = '\0';
#else
nsCAutoString pattern;
#endif
if (leadingStar) if (leadingStar)
PL_strcat (pattern, "*"); pattern.Append("*");
PL_strcat (pattern, urlEncoded); pattern.Append(NS_ConvertUCS2toUTF8(escapedValue));
if (trailingStar) if (trailingStar)
PL_strcat (pattern, "*"); pattern.Append("*");
// Combine the XPAT command syntax with the attribute and the pattern to // Combine the XPAT command syntax with the attribute and the pattern to
// form the term encoding // form the term encoding
char *xpatTemplate = "XPAT %s 1- %s"; char *xpatTemplate = "XPAT %s 1- %s";
int termLength = nsCRT::strlen(xpatTemplate) + nsCRT::strlen(attribEncoding) + nsCRT::strlen(pattern) + 1; int termLength = nsCRT::strlen(xpatTemplate) + nsCRT::strlen(attribEncoding) + pattern.Length() + 1;
char *termEncoding = new char [termLength]; char *termEncoding = new char [termLength];
if (termEncoding) if (termEncoding)
PR_snprintf (termEncoding, termLength, xpatTemplate, attribEncoding, pattern); PR_snprintf (termEncoding, termLength, xpatTemplate, attribEncoding, pattern.GetBuffer());
nsCRT::free(urlEncoded);
delete [] pattern;
return termEncoding; return termEncoding;
} }

View File

@ -40,7 +40,7 @@ public:
virtual nsresult Encode (nsCString *outEncoding); virtual nsresult Encode (nsCString *outEncoding);
virtual char *EncodeTerm (nsIMsgSearchTerm *); virtual char *EncodeTerm (nsIMsgSearchTerm *);
char *EncodeValue (const char *); PRUnichar *EncodeToWildmat (const PRUnichar *);
PRBool DuplicateHit(PRUint32 artNum) ; PRBool DuplicateHit(PRUint32 artNum) ;
void CollateHits (); void CollateHits ();

View File

@ -21,6 +21,8 @@
*/ */
#include "msgCore.h" #include "msgCore.h"
#include "nsXPIDLString.h"
#include "nsMsgSearchCore.h" #include "nsMsgSearchCore.h"
#include "nsIMsgSearchSession.h" #include "nsIMsgSearchSession.h"
#include "nsMsgUtils.h" #include "nsMsgUtils.h"
@ -34,6 +36,7 @@
#include "nsMsgLocalSearch.h" #include "nsMsgLocalSearch.h"
#include "nsMsgSearchNews.h" #include "nsMsgSearchNews.h"
#include "nsMsgSearchValue.h" #include "nsMsgSearchValue.h"
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// nsMsgSearchTerm specifies one criterion, e.g. name contains phil // nsMsgSearchTerm specifies one criterion, e.g. name contains phil
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -282,7 +285,7 @@ nsMsgSearchTerm::nsMsgSearchTerm (
nsMsgSearchTerm::~nsMsgSearchTerm () nsMsgSearchTerm::~nsMsgSearchTerm ()
{ {
if (IS_STRING_ATTRIBUTE (m_attribute) && m_value.string) if (IS_STRING_ATTRIBUTE (m_attribute) && m_value.string)
PR_Free(m_value.string); Recycle(m_value.string);
} }
NS_IMPL_ISUPPORTS1(nsMsgSearchTerm, nsIMsgSearchTerm) NS_IMPL_ISUPPORTS1(nsMsgSearchTerm, nsIMsgSearchTerm)
@ -784,7 +787,7 @@ nsresult nsMsgSearchTerm::MatchString (const char *stringToMatch,
if(nsMsgSearchOp::IsEmpty != m_operator) // Save some performance for opIsEmpty if(nsMsgSearchOp::IsEmpty != m_operator) // Save some performance for opIsEmpty
{ {
#ifdef DO_I18N #ifdef DO_I18N
n_str = INTL_GetNormalizeStr(csid , (unsigned char*)m_value.u.string); // Always new buffer unless not enough memory n_str = INTL_GetNormalizeStr(csid , (unsigned char*)m_value.string); // Always new buffer unless not enough memory
if (!body) if (!body)
n_header = INTL_GetNormalizeStrFromRFC1522(csid , stringToMatch); // Always new buffer unless not enough memory n_header = INTL_GetNormalizeStrFromRFC1522(csid , stringToMatch); // Always new buffer unless not enough memory
else else
@ -1460,7 +1463,9 @@ nsresult nsMsgResultElement::AssignValues (nsIMsgSearchValue *src, nsMsgSearchVa
if (dst->attribute < nsMsgSearchAttrib::kNumMsgSearchAttributes) if (dst->attribute < nsMsgSearchAttrib::kNumMsgSearchAttributes)
{ {
NS_ASSERTION(IS_STRING_ATTRIBUTE(dst->attribute), "assigning non-string result"); NS_ASSERTION(IS_STRING_ATTRIBUTE(dst->attribute), "assigning non-string result");
err = src->GetStr(&dst->string); nsXPIDLString unicodeString;
err = src->GetStr(getter_Copies(unicodeString));
dst->string = NS_ConvertUCS2toUTF8(unicodeString).ToNewCString();
} }
else else
err = NS_ERROR_INVALID_ARG; err = NS_ERROR_INVALID_ARG;
@ -1574,7 +1579,7 @@ nsresult nsMsgResultElement::GetPrettyName (nsMsgSearchValue **value)
if (tmp) if (tmp)
{ {
XP_FREE ((*value)->u.string); XP_FREE ((*value)->u.string);
(*value)->u.string = tmp; (*value)->u.utf8SstringZ = tmp;
} }
} }
} }

View File

@ -30,6 +30,8 @@ nsMsgSearchValueImpl::nsMsgSearchValueImpl(nsMsgSearchValue *aInitialValue)
mValue = *aInitialValue; mValue = *aInitialValue;
if (IS_STRING_ATTRIBUTE(aInitialValue->attribute)) if (IS_STRING_ATTRIBUTE(aInitialValue->attribute))
mValue.string = nsCRT::strdup(aInitialValue->string); mValue.string = nsCRT::strdup(aInitialValue->string);
else
mValue.string = 0;
} }
nsMsgSearchValueImpl::~nsMsgSearchValueImpl() nsMsgSearchValueImpl::~nsMsgSearchValueImpl()
@ -42,21 +44,21 @@ nsMsgSearchValueImpl::~nsMsgSearchValueImpl()
NS_IMPL_ISUPPORTS1(nsMsgSearchValueImpl, nsIMsgSearchValue) NS_IMPL_ISUPPORTS1(nsMsgSearchValueImpl, nsIMsgSearchValue)
NS_IMETHODIMP NS_IMETHODIMP
nsMsgSearchValueImpl::GetStr(char** aResult) nsMsgSearchValueImpl::GetStr(PRUnichar** aResult)
{ {
NS_ENSURE_ARG_POINTER(aResult); NS_ENSURE_ARG_POINTER(aResult);
NS_ENSURE_TRUE(IS_STRING_ATTRIBUTE(mValue.attribute), NS_ERROR_ILLEGAL_VALUE); NS_ENSURE_TRUE(IS_STRING_ATTRIBUTE(mValue.attribute), NS_ERROR_ILLEGAL_VALUE);
*aResult = nsCRT::strdup(mValue.string); *aResult = NS_ConvertUTF8toUCS2(mValue.string).ToNewUnicode();
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsMsgSearchValueImpl::SetStr(const char* aValue) nsMsgSearchValueImpl::SetStr(const PRUnichar* aValue)
{ {
NS_ENSURE_TRUE(IS_STRING_ATTRIBUTE(mValue.attribute), NS_ERROR_ILLEGAL_VALUE); NS_ENSURE_TRUE(IS_STRING_ATTRIBUTE(mValue.attribute), NS_ERROR_ILLEGAL_VALUE);
if (mValue.string) if (mValue.string)
nsCRT::free(mValue.string); nsCRT::free(mValue.string);
mValue.string = nsCRT::strdup(aValue); mValue.string = NS_ConvertUCS2toUTF8(aValue).ToNewCString();
return NS_OK; return NS_OK;
} }
@ -199,9 +201,10 @@ nsMsgSearchValueImpl::ToString(PRUnichar **aResult)
{ {
NS_ENSURE_ARG_POINTER(aResult); NS_ENSURE_ARG_POINTER(aResult);
nsAutoString resultStr;
resultStr.AssignWithConversion("[nsIMsgSearchValue: ");
if (IS_STRING_ATTRIBUTE(mValue.attribute)) { if (IS_STRING_ATTRIBUTE(mValue.attribute)) {
nsCAutoString str(mValue.string); resultStr.Append(NS_ConvertUTF8toUCS2(mValue.string));
*aResult = str.ToNewUnicode();
return NS_OK; return NS_OK;
} }
@ -215,11 +218,15 @@ nsMsgSearchValueImpl::ToString(PRUnichar **aResult)
case nsMsgSearchAttrib::Size: case nsMsgSearchAttrib::Size:
case nsMsgSearchAttrib::AgeInDays: case nsMsgSearchAttrib::AgeInDays:
case nsMsgSearchAttrib::FolderInfo: case nsMsgSearchAttrib::FolderInfo:
*aResult = nsnull; resultStr.AppendWithConversion("type=");
resultStr.AppendInt(mValue.attribute);
break; break;
default: default:
NS_ASSERTION(0, "Unknown search value type"); NS_ASSERTION(0, "Unknown search value type");
} }
resultStr.AppendWithConversion("]");
*aResult = resultStr.ToNewUnicode();
return NS_OK; return NS_OK;
} }