From 6c20b3710dd56d9764f55d4015add4f820b2be0d Mon Sep 17 00:00:00 2001 From: "bienvenu%netscape.com" Date: Tue, 6 Jun 2000 23:28:17 +0000 Subject: [PATCH] more work on search backend, r=alecf,jefft 33100 --- .../search/public/nsIMsgSearchSession.idl | 5 +++ .../public/nsIMsgSearchValidityTable.idl | 9 +---- .../base/search/public/nsMsgSearchArray.h | 6 --- mailnews/base/search/src/nsMsgBodyHandler.cpp | 2 +- mailnews/base/search/src/nsMsgImapSearch.cpp | 7 +++- mailnews/base/search/src/nsMsgLocalSearch.cpp | 3 ++ .../base/search/src/nsMsgSearchAdapter.cpp | 39 ++++++++++++++++--- mailnews/base/search/src/nsMsgSearchNews.cpp | 1 + .../base/search/src/nsMsgSearchSession.cpp | 20 +++++++++- 9 files changed, 70 insertions(+), 22 deletions(-) diff --git a/mailnews/base/search/public/nsIMsgSearchSession.idl b/mailnews/base/search/public/nsIMsgSearchSession.idl index 0fce443f529..e268a152f75 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 b67e8e79c88..a39176499a8 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 687fdc69f2d..7879f9c69a8 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 5178ae6c65f..4fa01780d34 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 6ca15769949..b6e92a98aa9 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 3528619c16a..4964855716c 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 3a1478976c7..243bf573783 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 626ff22c8c7..d01c9517c07 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 a76d3df8817..759a080f8e9 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()