fix 404489 mail filters using custom Sender header broken, r=standard8, sr=bienvenu
fix 404489 mail filters using custom Sender header broken, r=standard8, sr=bienvenu
--- a/mailnews/base/search/src/nsMsgSearchTerm.cpp
+++ b/mailnews/base/search/src/nsMsgSearchTerm.cpp
@@ -120,25 +120,33 @@ nsMsgSearchAttribEntry SearchAttribEntry
// Take a string which starts off with an attribute
// return the matching attribute. If the string is not in the table, then we can conclude that it is an arbitrary header
nsresult NS_MsgGetAttributeFromString(const char *string, PRInt16 *attrib)
{
NS_ENSURE_ARG_POINTER(string);
NS_ENSURE_ARG_POINTER(attrib);
PRBool found = PR_FALSE;
- for (int idxAttrib = 0; idxAttrib < (int)(sizeof(SearchAttribEntryTable) / sizeof(nsMsgSearchAttribEntry)); idxAttrib++)
+ // custom headers have a leading quote
+ if (*string != '"')
{
- if (!PL_strcasecmp(string, SearchAttribEntryTable[idxAttrib].attribName))
+ for (int idxAttrib = 0; idxAttrib < (int)(sizeof(SearchAttribEntryTable) /
+ sizeof(nsMsgSearchAttribEntry)); idxAttrib++)
{
- found = PR_TRUE;
- *attrib = SearchAttribEntryTable[idxAttrib].attrib;
- break;
+ if (!PL_strcasecmp(string, SearchAttribEntryTable[idxAttrib].attribName))
+ {
+ found = PR_TRUE;
+ *attrib = SearchAttribEntryTable[idxAttrib].attrib;
+ break;
+ }
}
}
+ else // remove the leading quote
+ string++;
+
if (!found)
{
nsresult rv;
PRBool goodHdr;
IsRFC822HeaderFieldName(string, &goodHdr);
if (!goodHdr)
return NS_MSG_INVALID_CUSTOM_HEADER;
//49 is for showing customize... in ui, headers start from 50 onwards up until 99.
@@ -632,39 +640,41 @@ nsMsgSearchTerm::ParseOperator(char *inS
// find the attribute code for this comma-delimited attribute.
nsresult
nsMsgSearchTerm::ParseAttribute(char *inStream, nsMsgSearchAttribValue *attrib)
{
while (isspace(*inStream))
inStream++;
- // if we are dealing with an arbitrary header, it may be quoted....
+ // if we are dealing with an arbitrary header, it will be quoted....
+ // it seems like a kludge, but to distinguish arbitrary headers from
+ // standard headers with the same name, like "Date", we'll use the
+ // presence of the quote to recognize arbitrary headers. We leave the
+ // leading quote as a flag, but remove the trailing quote.
PRBool quoteVal = PR_FALSE;
if (*inStream == '"')
- {
quoteVal = PR_TRUE;
- inStream++;
- }
- // arbitrary headers are quoted
- char *separator = strchr(inStream, quoteVal ? '"' : ',');
+ // arbitrary headers are quoted. Skip first character, which will be the
+ // first quote for arbitrary headers
+ char *separator = strchr(inStream + 1, quoteVal ? '"' : ',');
if (separator)
*separator = '\0';
PRInt16 attributeVal;
nsresult rv = NS_MsgGetAttributeFromString(inStream, &attributeVal);
NS_ENSURE_SUCCESS(rv, rv);
*attrib = (nsMsgSearchAttribValue) attributeVal;
if (*attrib > nsMsgSearchAttrib::OtherHeader && *attrib < nsMsgSearchAttrib::kNumMsgSearchAttributes) // if we are dealing with an arbitrary header....
{
- m_arbitraryHeader = inStream;
+ m_arbitraryHeader = inStream + 1; // remove the leading quote
ToLowerCaseExceptSpecials(m_arbitraryHeader);
}
return rv;
}
// De stream one search term. If the condition looks like
// condition = "(to or cc, contains, r-thompson) AND (body, doesn't contain, fred)"
// This routine should get called twice, the first time