From ff26bc2426b0d1705bff9da6ebec54ffb2bf1941 Mon Sep 17 00:00:00 2001 From: "mkmelin+mozilla%iki.fi" Date: Thu, 5 Jul 2007 18:06:42 +0000 Subject: [PATCH] =?UTF-8?q?Bug=20358909=20=EF=BF=BD=EF=BF=BD=EF=BF=BD=20Me?= =?UTF-8?q?ssage=20filter=20"Age"=20only=20allows=20positive=20values.=20T?= =?UTF-8?q?he=20fix=20enables=20searching/filtering=20out=20messages=20wit?= =?UTF-8?q?h=20date=20in=20the=20future.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit r+sr=bienvenu --- .../base/search/public/nsIMsgSearchValue.idl | 4 +- .../base/search/public/nsMsgSearchCore.idl | 8 ++-- .../base/search/src/nsMsgSearchAdapter.cpp | 40 +++++++++++-------- mailnews/base/search/src/nsMsgSearchTerm.cpp | 25 +++++++----- mailnews/base/search/src/nsMsgSearchValue.cpp | 2 +- 5 files changed, 45 insertions(+), 34 deletions(-) diff --git a/mailnews/base/search/public/nsIMsgSearchValue.idl b/mailnews/base/search/public/nsIMsgSearchValue.idl index 2854e5db6b3..448d54fc741 100644 --- a/mailnews/base/search/public/nsIMsgSearchValue.idl +++ b/mailnews/base/search/public/nsIMsgSearchValue.idl @@ -40,7 +40,7 @@ interface nsIMsgFolder; -[scriptable, uuid(124C7DEB-5BDE-4367-8CD2-19616FFF8F0D)] +[scriptable, uuid(86293830-06e4-4f08-8f2c-e74ef45ceddf)] interface nsIMsgSearchValue : nsISupports { // type of object attribute nsMsgSearchAttribValue attrib; @@ -53,7 +53,7 @@ interface nsIMsgSearchValue : nsISupports { attribute unsigned long status; // see MSG_FLAG in msgcom.h attribute unsigned long size; attribute nsMsgKey msgKey; - attribute unsigned long age; // in days + attribute long age; // in days attribute nsIMsgFolder folder; attribute nsMsgLabelValue label; attribute nsMsgJunkStatus junkStatus; diff --git a/mailnews/base/search/public/nsMsgSearchCore.idl b/mailnews/base/search/public/nsMsgSearchCore.idl index 14192601e05..6e9dde60244 100644 --- a/mailnews/base/search/public/nsMsgSearchCore.idl +++ b/mailnews/base/search/public/nsMsgSearchCore.idl @@ -198,10 +198,10 @@ typedef struct nsMsgSearchValue PRUint32 msgStatus; /* see MSG_FLAG in msgcom.h */ PRUint32 size; nsMsgKey key; - PRUint32 age; /* in days */ - nsIMsgFolder *folder; - nsMsgLabelValue label; - PRUint32 junkStatus; + PRInt32 age; /* in days */ + nsIMsgFolder *folder; + nsMsgLabelValue label; + PRUint32 junkStatus; } u; char *string; } nsMsgSearchValue; diff --git a/mailnews/base/search/src/nsMsgSearchAdapter.cpp b/mailnews/base/search/src/nsMsgSearchAdapter.cpp index bba4a61c680..1a54858a7dd 100644 --- a/mailnews/base/search/src/nsMsgSearchAdapter.cpp +++ b/mailnews/base/search/src/nsMsgSearchAdapter.cpp @@ -356,20 +356,28 @@ nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool real case nsMsgSearchAttrib::AgeInDays: // added for searching online for age in days... // for AgeInDays, we are actually going to perform a search by date, so convert the operations for age // to the IMAP mnemonics that we would use for date! - switch (op) { - case nsMsgSearchOp::IsGreaterThan: - whichMnemonic = m_kImapBefore; - break; - case nsMsgSearchOp::IsLessThan: - whichMnemonic = m_kImapSince; - break; - case nsMsgSearchOp::Is: - whichMnemonic = m_kImapSentOn; - break; - default: - NS_ASSERTION(PR_FALSE, "invalid search operator"); - return NS_ERROR_INVALID_ARG; + // If we have a future date, the > and < are reversed. + // e.g. ageInDays > 2 means more than 2 days old ("date before X") whereas + // ageInDays > -2 should be more than 2 days in the future ("date after X") + PRInt32 ageInDays; + searchValue->GetAge(&ageInDays); + PRBool dateInFuture = (ageInDays < 0); + switch (op) + { + case nsMsgSearchOp::IsGreaterThan: + whichMnemonic = (!dateInFuture) ? m_kImapBefore : m_kImapSince; + break; + case nsMsgSearchOp::IsLessThan: + whichMnemonic = (!dateInFuture) ? m_kImapSince : m_kImapBefore; + break; + case nsMsgSearchOp::Is: + whichMnemonic = m_kImapSentOn; + break; + default: + NS_ASSERTION(PR_FALSE, "invalid search operator"); + return NS_ERROR_INVALID_ARG; + } } break; case nsMsgSearchAttrib::Size: @@ -499,7 +507,7 @@ 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; + PRInt32 ageInDays; searchValue->GetAge(&ageInDays); @@ -509,7 +517,7 @@ nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool real PRInt64 microSecondsPerSecond, secondsInDays, microSecondsInDay; LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC); - LL_UI2L(secondsInDays, 60 * 60 * 24 * ageInDays); + LL_I2L(secondsInDays, 60 * 60 * 24 * ageInDays); LL_MUL(microSecondsInDay, secondsInDays, microSecondsPerSecond); LL_SUB(matchDay, now, microSecondsInDay); // = now - term->m_value.u.age * 60 * 60 * 24; @@ -1066,8 +1074,6 @@ nsMsgSearchValidityManager::SetOtherHeadersInTable (nsIMsgSearchValidityTable *a PRUint32 numHeaders=0; if (customHeadersLength) { - char *headersString = strdup(customHeaders); - nsCAutoString hdrStr(customHeaders); hdrStr.StripWhitespace(); //remove whitespace before parsing char *newStr = hdrStr.BeginWriting(); diff --git a/mailnews/base/search/src/nsMsgSearchTerm.cpp b/mailnews/base/search/src/nsMsgSearchTerm.cpp index 221124dd2b0..19ef2d7deda 100644 --- a/mailnews/base/search/src/nsMsgSearchTerm.cpp +++ b/mailnews/base/search/src/nsMsgSearchTerm.cpp @@ -1136,22 +1136,27 @@ nsresult nsMsgSearchTerm::MatchAge (PRTime msgDate, PRBool *pResult) PRTime cutOffDay; PRInt64 microSecondsPerSecond, secondsInDays, microSecondsInDays; - - LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC); - LL_UI2L(secondsInDays, 60 * 60 * 24 * m_value.u.age); - LL_MUL(microSecondsInDays, secondsInDays, microSecondsPerSecond); - LL_SUB(cutOffDay, now, microSecondsInDays); // = now - term->m_value.u.age * 60 * 60 * 24; - // so now cutOffDay is the PRTime cut-off point. Any msg with a time less than that will be past the age . + LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC); + LL_I2L(secondsInDays, 60 * 60 * 24 * m_value.u.age); + LL_MUL(microSecondsInDays, secondsInDays, microSecondsPerSecond); + LL_SUB(cutOffDay, now, microSecondsInDays); // = now - term->m_value.u.age * 60 * 60 * 24; + + PRBool cutOffDayInTheFuture = LL_CMP(m_value.u.age, <, 0); + + // So now cutOffDay is the PRTime cut-off point. + // Any msg with a time less than that will be past the age. switch (m_operator) { - case nsMsgSearchOp::IsGreaterThan: // is older than - if (LL_CMP(msgDate, <, cutOffDay)) + case nsMsgSearchOp::IsGreaterThan: // is older than, or more in the future + if ((!cutOffDayInTheFuture && LL_CMP(msgDate, <, cutOffDay)) || + (cutOffDayInTheFuture && LL_CMP(msgDate, >, cutOffDay))) result = PR_TRUE; break; - case nsMsgSearchOp::IsLessThan: // is younger than - if (LL_CMP(msgDate, >, cutOffDay)) + case nsMsgSearchOp::IsLessThan: // is younger than, or less in the future + if ((!cutOffDayInTheFuture && LL_CMP(msgDate, >, cutOffDay)) || + (cutOffDayInTheFuture && LL_CMP(msgDate, <, cutOffDay))) result = PR_TRUE; break; case nsMsgSearchOp::Is: diff --git a/mailnews/base/search/src/nsMsgSearchValue.cpp b/mailnews/base/search/src/nsMsgSearchValue.cpp index 3423a62a550..16213c9bd46 100644 --- a/mailnews/base/search/src/nsMsgSearchValue.cpp +++ b/mailnews/base/search/src/nsMsgSearchValue.cpp @@ -62,7 +62,7 @@ NS_IMPL_GETSET(nsMsgSearchValueImpl, Priority, nsMsgPriorityValue, mValue.u.prio NS_IMPL_GETSET(nsMsgSearchValueImpl, Status, PRUint32, mValue.u.msgStatus) NS_IMPL_GETSET(nsMsgSearchValueImpl, Size, PRUint32, mValue.u.size) NS_IMPL_GETSET(nsMsgSearchValueImpl, MsgKey, nsMsgKey, mValue.u.key) -NS_IMPL_GETSET(nsMsgSearchValueImpl, Age, PRUint32, mValue.u.age) +NS_IMPL_GETSET(nsMsgSearchValueImpl, Age, PRInt32, mValue.u.age) NS_IMPL_GETSET(nsMsgSearchValueImpl, Date, PRTime, mValue.u.date) NS_IMPL_GETSET(nsMsgSearchValueImpl, Attrib, nsMsgSearchAttribValue, mValue.attribute) NS_IMPL_GETSET(nsMsgSearchValueImpl, Label, nsMsgLabelValue, mValue.u.label)