diff --git a/mailnews/base/search/public/nsIMsgSearchSession.idl b/mailnews/base/search/public/nsIMsgSearchSession.idl index 0fce443f5290..e268a152f757 100644 --- a/mailnews/base/search/public/nsIMsgSearchSession.idl +++ b/mailnews/base/search/public/nsIMsgSearchSession.idl @@ -26,6 +26,7 @@ interface nsMsgResultElement; interface nsIMsgSearchAdapter; +interface nsIMsgSearchTerm; ////////////////////////////////////////////////////////////////////////////// // The Msg Search Session is an interface designed to make constructing @@ -42,6 +43,10 @@ interface nsIMsgSearchSession : nsISupports { in boolean BooleanAND, /* set to true if associated boolean operator is AND */ in string arbitraryHeader); /* user defined arbitrary header. ignored unless attrib = attribOtherHeader */ + void AddSearchTermArray (in nsISupportsArray searchTerms); + + void CreateSearchTerm (out nsIMsgSearchTerm searchTerm); + readonly attribute unsigned long numSearchTerms; readonly attribute nsIMsgSearchAdapter runningAdapter; diff --git a/mailnews/base/search/public/nsIMsgSearchValidityTable.idl b/mailnews/base/search/public/nsIMsgSearchValidityTable.idl index b67e8e79c885..a39176499a8c 100644 --- a/mailnews/base/search/public/nsIMsgSearchValidityTable.idl +++ b/mailnews/base/search/public/nsIMsgSearchValidityTable.idl @@ -23,12 +23,7 @@ #include "nsISupports.idl" #include "nsMsgSearchCore.idl" - -[byref] native nsMsgSearchTermArray(nsMsgSearchTermArray&); - -%{C++ -#include "nsMsgSearchArray.h" -%} +interface nsISupportsArray; [scriptable, uuid(b07f1cb6-fae9-4d92-9edb-03f9ad249c66)] interface nsIMsgSearchValidityTable : nsISupports { @@ -47,7 +42,7 @@ interface nsIMsgSearchValidityTable : nsISupports { boolean getValidButNotShown(in nsMsgSearchAttribValue attrib, in nsMsgSearchOpValue op); - [noscript] void validateTerms(in nsMsgSearchTermArray terms); + [noscript] void validateTerms(in nsISupportsArray terms); readonly attribute long numAvailAttribs; diff --git a/mailnews/base/search/public/nsMsgSearchArray.h b/mailnews/base/search/public/nsMsgSearchArray.h index 687fdc69f2d1..7879f9c69a84 100644 --- a/mailnews/base/search/public/nsMsgSearchArray.h +++ b/mailnews/base/search/public/nsMsgSearchArray.h @@ -30,12 +30,6 @@ class nsMsgSearchTerm; class nsMsgSearchScopeTerm; struct nsMsgSearchValue; -class nsMsgSearchTermArray : public nsVoidArray -{ -public: - nsMsgSearchTerm *ElementAt(PRUint32 i) const { return (nsMsgSearchTerm*) nsVoidArray::ElementAt(i); } -}; - class nsMsgSearchValueArray : public nsVoidArray { public: diff --git a/mailnews/base/search/src/nsMsgBodyHandler.cpp b/mailnews/base/search/src/nsMsgBodyHandler.cpp index 5178ae6c65f4..4fa01780d34d 100644 --- a/mailnews/base/search/src/nsMsgBodyHandler.cpp +++ b/mailnews/base/search/src/nsMsgBodyHandler.cpp @@ -126,7 +126,7 @@ void nsMsgBodyHandler::OpenLocalFolder() if (NS_FAILED(rv) || !scopeFileStream) { nsCOMPtr fileSpec; - nsresult rv = m_scope->GetMailPath(getter_AddRefs(fileSpec)); + rv = m_scope->GetMailPath(getter_AddRefs(fileSpec)); if (NS_SUCCEEDED(rv) && fileSpec) { nsFileSpec path; diff --git a/mailnews/base/search/src/nsMsgImapSearch.cpp b/mailnews/base/search/src/nsMsgImapSearch.cpp index 6ca157699497..b6e92a98aa95 100644 --- a/mailnews/base/search/src/nsMsgImapSearch.cpp +++ b/mailnews/base/search/src/nsMsgImapSearch.cpp @@ -135,6 +135,8 @@ NS_IMETHODIMP nsMsgSearchOnlineMail::AddResultElement (nsIMsgDBHdr *pHeaders) err = m_scope->GetFolder(getter_AddRefs(folder)); if (NS_SUCCEEDED(err) && folder) folder->GetName(getter_Copies(folderName)); + pValue->u.folder = folder; + NS_ADDREF(pValue->u.folder); // pValue->u.wString = nsCRT::strdup((const PRUnichar *) folderName); newResult->AddValue (pValue); } @@ -265,7 +267,7 @@ nsresult nsMsgSearchOnlineMail::Encode (nsCString& pEncoding, pTerm->GetAttrib(&attribute); if (IsStringAttribute(attribute)) { - PRUnichar *pchar; + PRUnichar *pchar, *savepChar; nsCOMPtr searchValue; nsresult rv = pTerm->GetValue(getter_AddRefs(searchValue)); @@ -276,6 +278,7 @@ nsresult nsMsgSearchOnlineMail::Encode (nsCString& pEncoding, rv = searchValue->GetStr(&pchar); if (!NS_SUCCEEDED(rv) || !pchar) continue; + savepChar = pchar; for (; *pchar ; pchar++) { if (*pchar & 0xFF80) @@ -284,7 +287,7 @@ nsresult nsMsgSearchOnlineMail::Encode (nsCString& pEncoding, break; } } - nsCRT::free(pchar); + nsCRT::free(savepChar); } } } diff --git a/mailnews/base/search/src/nsMsgLocalSearch.cpp b/mailnews/base/search/src/nsMsgLocalSearch.cpp index 3528619c16ab..4964855716cf 100644 --- a/mailnews/base/search/src/nsMsgLocalSearch.cpp +++ b/mailnews/base/search/src/nsMsgLocalSearch.cpp @@ -785,6 +785,9 @@ NS_IMETHODIMP nsMsgSearchOfflineMail::AddResultElement (nsIMsgDBHdr *pHeaders) if (pValue) { pValue->attribute = nsMsgSearchAttrib::Location; + m_scope->GetFolder(&pValue->u.folder); +// pValue->u.folder = m_scope->m_folder; +// NS_IF_ADDREF(pValue->u.folder); // use nsIMsgFolder, not string #ifdef HAVE_SEARCH_PORT pValue->u.string = PL_strdup(m_scope->m_folder->GetName()); #endif diff --git a/mailnews/base/search/src/nsMsgSearchAdapter.cpp b/mailnews/base/search/src/nsMsgSearchAdapter.cpp index 3a1478976c76..243bf573783a 100644 --- a/mailnews/base/search/src/nsMsgSearchAdapter.cpp +++ b/mailnews/base/search/src/nsMsgSearchAdapter.cpp @@ -395,6 +395,9 @@ nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool real nsCOMPtr searchValue; nsresult rv = term->GetValue(getter_AddRefs(searchValue)); + if (!NS_SUCCEEDED(rv)) + return rv; + nsMsgSearchOpValue op; term->GetOp(&op); @@ -536,7 +539,13 @@ nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool real // we need to adjust the date so we get greater than and not greater than or equal to which // is what the IMAP server wants to search on // won't work on Mac. -// adjustedDate += 60 * 60 * 24; // bump up to the day after this one... + // ack, is this right? is PRTime seconds or microseconds? + PRInt64 microSecondsPerSecond, secondsInDay, microSecondsInDay; + + LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC); + LL_UI2L(secondsInDay, 60 * 60 * 24); + LL_MUL(microSecondsInDay, secondsInDay, microSecondsPerSecond); + LL_ADD(adjustedDate, adjustedDate, microSecondsInDay); // bump up to the day after this one... } PRExplodedTime exploded; @@ -551,9 +560,20 @@ nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool real { // okay, take the current date, subtract off the age in days, then do an appropriate Date search on // the resulting day. + PRUint32 ageInDays; + + searchValue->GetAge(&ageInDays); + PRTime now = PR_Now(); PRTime matchDay; - LL_I2L(matchDay, 0); // = now ; - term->m_value.u.age * 60 * 60 * 24; won't work on the mac + + PRInt64 microSecondsPerSecond, secondsInDays, microSecondsInDay; + + LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC); + LL_UI2L(secondsInDays, 60 * 60 * 24 * ageInDays); + LL_MUL(microSecondsInDay, secondsInDays, microSecondsPerSecond); + + LL_SUB(matchDay, now, microSecondsInDay); // = now - term->m_value.u.age * 60 * 60 * 24; PRExplodedTime exploded; PR_ExplodeTime(matchDay, PR_LocalTimeParameters, &exploded); PR_FormatTimeUSEnglish(dateBuf, sizeof(dateBuf), "%d-%b-%Y", &exploded); @@ -853,13 +873,22 @@ nsMsgSearchValidityTable::GetNumAvailAttribs(PRInt32 *aResult) } nsresult -nsMsgSearchValidityTable::ValidateTerms (nsMsgSearchTermArray &termList) +nsMsgSearchValidityTable::ValidateTerms (nsISupportsArray *searchTerms) { nsresult err = NS_OK; + PRUint32 count; - for (int i = 0; i < termList.Count(); i++) + NS_ENSURE_ARG(searchTerms); + + searchTerms->Count(&count); + for (PRUint32 i = 0; i < count; i++) { - nsMsgSearchTerm *term = termList.ElementAt(i); + nsCOMPtr pTerm; + searchTerms->QueryElementAt(i, NS_GET_IID(nsIMsgSearchTerm), + (void **)getter_AddRefs(pTerm)); + + nsIMsgSearchTerm *iTerm = pTerm; + nsMsgSearchTerm *term = NS_STATIC_CAST(nsMsgSearchTerm *, iTerm); // XP_ASSERT(term->IsValid()); PRBool enabled; PRBool available; diff --git a/mailnews/base/search/src/nsMsgSearchNews.cpp b/mailnews/base/search/src/nsMsgSearchNews.cpp index 626ff22c8c75..d01c9517c07d 100644 --- a/mailnews/base/search/src/nsMsgSearchNews.cpp +++ b/mailnews/base/search/src/nsMsgSearchNews.cpp @@ -424,6 +424,7 @@ void nsMsgSearchNews::ReportHits () } #endif // OLDWAY +// ### this should take an nsIMsgFolder instead of a string location. void nsMsgSearchNews::ReportHit (nsIMsgDBHdr *pHeaders, const char *location) { // this is totally filched from msg_SearchOfflineMail until I decide whether the diff --git a/mailnews/base/search/src/nsMsgSearchSession.cpp b/mailnews/base/search/src/nsMsgSearchSession.cpp index a76d3df88176..759a080f8e96 100644 --- a/mailnews/base/search/src/nsMsgSearchSession.cpp +++ b/mailnews/base/search/src/nsMsgSearchSession.cpp @@ -70,6 +70,24 @@ nsMsgSearchSession::AddSearchTerm(nsMsgSearchAttribValue attrib, return NS_OK; } +NS_IMETHODIMP +nsMsgSearchSession::AddSearchTermArray(nsISupportsArray *searchTerms) +{ + m_termList = searchTerms; + return NS_OK; +} + +NS_IMETHODIMP +nsMsgSearchSession::CreateSearchTerm(nsIMsgSearchTerm **aResult) +{ + nsMsgSearchTerm *term = new nsMsgSearchTerm; + NS_ENSURE_TRUE(term, NS_ERROR_OUT_OF_MEMORY); + + *aResult = NS_STATIC_CAST(nsIMsgSearchTerm*,term); + NS_ADDREF(*aResult); + return NS_OK; +} + /* readonly attribute long numSearchTerms; */ NS_IMETHODIMP nsMsgSearchSession::GetNumSearchTerms(PRUint32 *aNumSearchTerms) { @@ -498,7 +516,7 @@ void nsMsgSearchSession::DestroyScopeList() void nsMsgSearchSession::DestroyTermList () { - m_termList->Clear(); + m_termList = nsnull; // don't really need this now that caller owns term list. } nsMsgSearchScopeTerm *nsMsgSearchSession::GetRunningScope()