From e2491daa68799aa509c729cf4373d892b678ab6b Mon Sep 17 00:00:00 2001 From: "bienvenu%nventure.com" Date: Thu, 24 Jun 2004 16:11:51 +0000 Subject: [PATCH] fix 243625 imap search on non-7bit ascii chars git-svn-id: svn://10.0.0.236/branches/AVIARY_1_0_20040515_BRANCH@158412 18797224-902f-48f8-a5cc-f745e15eee43 --- .../base/search/src/nsMsgImapSearch.cpp | 62 +++++++++---------- .../base/search/src/nsMsgSearchAdapter.cpp | 43 ++++++++----- mozilla/mailnews/imap/src/nsImapProtocol.cpp | 17 ++++- 3 files changed, 73 insertions(+), 49 deletions(-) diff --git a/mozilla/mailnews/base/search/src/nsMsgImapSearch.cpp b/mozilla/mailnews/base/search/src/nsMsgImapSearch.cpp index f54baa27aba..fbdf4f84e9c 100644 --- a/mozilla/mailnews/base/search/src/nsMsgImapSearch.cpp +++ b/mozilla/mailnews/base/search/src/nsMsgImapSearch.cpp @@ -111,55 +111,55 @@ nsresult nsMsgSearchOnlineMail::Encode (nsCString& pEncoding, nsISupportsArray *searchTerms, const PRUnichar *destCharset) { - nsXPIDLCString imapTerms; - - //check if searchTerms are ascii only - PRBool asciiOnly = PR_TRUE; + nsXPIDLCString imapTerms; + + //check if searchTerms are ascii only + PRBool asciiOnly = PR_TRUE; // ### what's this mean in the NWO????? - - if (PR_TRUE) // !(srcCharset & CODESET_MASK == STATEFUL || srcCharset & CODESET_MASK == WIDECHAR) ) //assume all single/multiple bytes charset has ascii as subset - { - PRUint32 termCount; + + if (PR_TRUE) // !(srcCharset & CODESET_MASK == STATEFUL || srcCharset & CODESET_MASK == WIDECHAR) ) //assume all single/multiple bytes charset has ascii as subset + { + PRUint32 termCount; searchTerms->Count(&termCount); - PRUint32 i = 0; - - for (i = 0; i < termCount && asciiOnly; i++) - { + PRUint32 i = 0; + + for (i = 0; i < termCount && asciiOnly; i++) + { nsCOMPtr pTerm; searchTerms->QueryElementAt(i, NS_GET_IID(nsIMsgSearchTerm), - (void **)getter_AddRefs(pTerm)); - + (void **)getter_AddRefs(pTerm)); + nsMsgSearchAttribValue attribute; pTerm->GetAttrib(&attribute); - if (IsStringAttribute(attribute)) - { + if (IsStringAttribute(attribute)) + { nsXPIDLString pchar; nsCOMPtr searchValue; - + nsresult rv = pTerm->GetValue(getter_AddRefs(searchValue)); if (NS_FAILED(rv) || !searchValue) continue; - - + + rv = searchValue->GetStr(getter_Copies(pchar)); - if (NS_FAILED(rv) || !pchar) - continue; + if (NS_FAILED(rv) || !pchar) + continue; asciiOnly = nsCRT::IsAscii(pchar.get()); - } - } - } - else - asciiOnly = PR_FALSE; - + } + } + } + else + asciiOnly = PR_FALSE; + nsAutoString usAsciiCharSet(NS_LITERAL_STRING("us-ascii")); - // 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.get() : destCharset); - + // We do not need "srcCharset" since the search term in always unicode. // I just pass destCharset for both src and dest charset instead of removing srcCharst from the arguemnt. nsresult err = nsMsgSearchAdapter::EncodeImap (getter_Copies(imapTerms), searchTerms, - asciiOnly ? usAsciiCharSet.get(): destCharset, - asciiOnly ? usAsciiCharSet.get(): destCharset, PR_FALSE); + asciiOnly ? usAsciiCharSet.get(): destCharset, + asciiOnly ? usAsciiCharSet.get(): destCharset, PR_FALSE); if (NS_SUCCEEDED(err)) { pEncoding.Append("SEARCH"); diff --git a/mozilla/mailnews/base/search/src/nsMsgSearchAdapter.cpp b/mozilla/mailnews/base/search/src/nsMsgSearchAdapter.cpp index cb479ec689d..64865d61219 100644 --- a/mozilla/mailnews/base/search/src/nsMsgSearchAdapter.cpp +++ b/mozilla/mailnews/base/search/src/nsMsgSearchAdapter.cpp @@ -641,7 +641,7 @@ nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool real int len = strlen(whichMnemonic) + strlen(value) + (useNot ? strlen(m_kImapNot) : 0) + (useQuotes ? 2 : 0) + strlen(m_kImapHeader) + (orHeaderMnemonic ? (strlen(m_kImapHeader) + strlen(m_kImapOr) + (useNot ? strlen(m_kImapNot) : 0) + - strlen(orHeaderMnemonic) + strlen(value) + 2 /*""*/) : 0) + 1; + strlen(orHeaderMnemonic) + strlen(value) + 2 /*""*/) : 0) + 10; char *encoding = new char[len]; if (encoding) { @@ -687,24 +687,33 @@ nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool real nsresult nsMsgSearchAdapter::EncodeImapValue(char *encoding, const char *value, PRBool useQuotes, PRBool reallyDredd) { - // By NNTP RFC, SEARCH HEADER SUBJECT "" is legal and means 'find messages without a subject header' - if (!reallyDredd) - { - // By IMAP RFC, SEARCH HEADER SUBJECT "" is illegal and will generate an error from the server - if (!value || !value[0]) - return NS_ERROR_NULL_POINTER; - } - - if (useQuotes) - PL_strcat(encoding, "\""); - PL_strcat (encoding, value); - if (useQuotes) - PL_strcat(encoding, "\""); - - return NS_OK; + // By NNTP RFC, SEARCH HEADER SUBJECT "" is legal and means 'find messages without a subject header' + if (!reallyDredd) + { + // By IMAP RFC, SEARCH HEADER SUBJECT "" is illegal and will generate an error from the server + if (!value || !value[0]) + return NS_ERROR_NULL_POINTER; + } + + if (!nsCRT::IsAscii(value)) + { + nsCAutoString lengthStr; + PL_strcat(encoding, "{"); + lengthStr.AppendInt((PRInt32) strlen(value)); + PL_strcat(encoding, lengthStr.get()); + PL_strcat(encoding, "}"CRLF); + PL_strcat(encoding, value); + return NS_OK; + } + if (useQuotes) + PL_strcat(encoding, "\""); + PL_strcat (encoding, value); + if (useQuotes) + PL_strcat(encoding, "\""); + + return NS_OK; } - nsresult nsMsgSearchAdapter::EncodeImap (char **ppOutEncoding, nsISupportsArray *searchTerms, const PRUnichar *srcCharset, const PRUnichar *destCharset, PRBool reallyDredd) { // i've left the old code (before using CBoolExpression for debugging purposes to make sure that diff --git a/mozilla/mailnews/imap/src/nsImapProtocol.cpp b/mozilla/mailnews/imap/src/nsImapProtocol.cpp index 091bd958321..b1e4574d9d9 100644 --- a/mozilla/mailnews/imap/src/nsImapProtocol.cpp +++ b/mozilla/mailnews/imap/src/nsImapProtocol.cpp @@ -6860,9 +6860,24 @@ void nsImapProtocol::Search(const char * searchCriteria, protocolString.Append(" uid"); protocolString.Append(" "); protocolString.Append(searchCriteria); + // the search criteria can contain string literals, which means we + // need to break up the protocol string by CRLF's, and after sending CRLF, + // wait for the server to respond OK before sending more data + nsresult rv; + PRInt32 crlfIndex; + while (crlfIndex = protocolString.Find(CRLF), crlfIndex != kNotFound && !DeathSignalReceived()) + { + nsCAutoString tempProtocolString; + protocolString.Left(tempProtocolString, crlfIndex + 2); + rv = SendData(tempProtocolString.get()); + if (NS_FAILED(rv)) + return; + ParseIMAPandCheckForNewMail(); + protocolString.Cut(0, crlfIndex + 2); + } protocolString.Append(CRLF); - nsresult rv = SendData(protocolString.get()); + rv = SendData(protocolString.get()); if (NS_SUCCEEDED(rv)) ParseIMAPandCheckForNewMail(); }