Bug 358909 ��� Message filter "Age" only allows positive values.

The fix enables searching/filtering out messages with date in the future.

r+sr=bienvenu
This commit is contained in:
mkmelin+mozilla%iki.fi 2007-07-05 18:06:42 +00:00
Родитель 37a103da30
Коммит ff26bc2426
5 изменённых файлов: 45 добавлений и 34 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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();

Просмотреть файл

@ -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:

Просмотреть файл

@ -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)