166517 r=cavin sr=bienvenu Handle invalid custom headers in rules.dat and parse custom header pref in such

a way that strtok and split(js) return same tokens. fixes some corruption issues
This commit is contained in:
naving%netscape.com 2002-09-11 02:00:54 +00:00
parent 2add13be13
commit a969ff0630
7 changed files with 48 additions and 16 deletions

View File

@ -158,6 +158,8 @@ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_MAILNEWS, value)
conflict, I reserve values between 12500 and 12999 for it.
*/
#define NS_MSG_CUSTOM_HEADERS_OVERFLOW NS_MSG_GENERATE_FAILURE(28) //when num of custom headers exceeds 50
#define NS_MSG_INVALID_CUSTOM_HEADER NS_MSG_GENERATE_FAILURE(29) //when custom header has invalid characters (as per rfc 2822)
#define NS_MSGCOMP_ERROR_BEGIN 12500
/* NS_ERROR_NNTP_NO_CROSS_POSTING lives here, and not in nsMsgComposeStringBundle.h, because it is used in news and compose. */
#define NS_ERROR_NNTP_NO_CROSS_POSTING NS_MSG_GENERATE_FAILURE(12554)

View File

@ -422,7 +422,13 @@
}
var hdrsArray = new Array;
if (hdrs)
hdrsArray = hdrs.split(": ");
{
hdrs = hdrs.replace(/\s+/g,''); //remove white spaces before splitting
hdrsArray = hdrs.split(":");
for (var i = 0; i< hdrsArray.length; i++)
if (!hdrsArray[i])
hdrsArray.splice(i,1); //remove any null elements
}
var bundle = this.stringBundle;
var j=0;
for (var i=0; i<ids.length; i++)

View File

@ -65,7 +65,11 @@ function initializeDialog(hdrs)
{
if (hdrs)
{
gArrayHdrs = hdrs.split(": ");
hdrs = hdrs.replace(/\s+/g,''); //remove white spaces before splitting
gArrayHdrs = hdrs.split(":");
for (var i = 0; i< gArrayHdrs.length; i++)
if (!gArrayHdrs[i])
gArrayHdrs.splice(i,1); //remove any null elements
initializeRows();
}
}
@ -101,7 +105,11 @@ function onOk()
{
if (gArrayHdrs.length)
{
var hdrs = gArrayHdrs.join(": ");
var hdrs;
if (gArrayHdrs.length == 1)
hdrs = gArrayHdrs;
else
hdrs = gArrayHdrs.join(": ");
gPrefs.setCharPref("mailnews.customHeaders", hdrs);
// flush prefs to disk, in case we crash, to avoid dataloss and problems with filters that use the custom headers
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);

View File

@ -12,3 +12,4 @@ untitledFilterName=untitled filter
filterListBackUpMsg=Your filters do not work because the rules.dat file, which contains your filters, could not be read. A new rules.dat file will be created and a backup of the old file, called rulesbackup.dat, will be created in the same directory.
customHeaderOverflow=You've exceeded the limit of 50 custom headers. Please remove one or more custom headers and try again.
filterCustomHeaderOverflow=Your filters have exceeded the limit of 50 custom headers. Please edit the rules.dat file, which contains your filters, to use fewer custom headers.
invalidCustomHeader=One of your filters uses a custom header that contains an invalid character, such as ':', a non-printable character, a non-ascii character, or an eight-bit ascii character. Please edit the rules.dat file, which contains your filters, to remove invalid characters from your custom headers.

View File

@ -111,6 +111,8 @@ NS_IMETHODIMP nsMsgFilterService::OpenFilterList(nsIFileSpec *filterFile, nsIMsg
}
else if(ret == NS_MSG_CUSTOM_HEADERS_OVERFLOW && aMsgWindow)
ThrowAlertMsg("filterCustomHeaderOverflow", aMsgWindow);
else if(ret == NS_MSG_INVALID_CUSTOM_HEADER && aMsgWindow)
ThrowAlertMsg("invalidCustomHeader", aMsgWindow);
}
return ret;
}

View File

@ -1112,19 +1112,27 @@ nsMsgSearchValidityManager::SetOtherHeadersInTable (nsIMsgSearchValidityTable *a
{
PRUint32 customHeadersLength = strlen(customHeaders);
PRUint32 numHeaders=0;
PRUint32 i=0;
if (customHeadersLength)
{
for (i=0;i <customHeadersLength; i++)
if (customHeaders[i] == ':')
numHeaders++;
numHeaders++;
char *headersString = nsCRT::strdup(customHeaders);
nsCAutoString hdrStr;
hdrStr.Adopt(headersString);
hdrStr.StripWhitespace(); //remove whitespace before parsing
char *newStr=nsnull;
char *token = nsCRT::strtok(headersString,":", &newStr);
while(token)
{
numHeaders++;
token = nsCRT::strtok(newStr,":", &newStr);
}
}
NS_ASSERTION(nsMsgSearchAttrib::OtherHeader + numHeaders < nsMsgSearchAttrib::kNumMsgSearchAttributes, "more headers than the table can hold");
PRUint32 maxHdrs= PR_MIN(nsMsgSearchAttrib::OtherHeader + numHeaders+1, nsMsgSearchAttrib::kNumMsgSearchAttributes);
for (i=nsMsgSearchAttrib::OtherHeader+1;i< maxHdrs;i++)
for (PRUint32 i=nsMsgSearchAttrib::OtherHeader+1;i< maxHdrs;i++)
{
aTable->SetAvailable (i, nsMsgSearchOp::Contains, 1); // added for arbitrary headers
aTable->SetEnabled (i, nsMsgSearchOp::Contains, 1);

View File

@ -108,6 +108,10 @@ nsresult NS_MsgGetAttributeFromString(const char *string, PRInt16 *attrib)
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.
*attrib = nsMsgSearchAttrib::OtherHeader+1;
@ -124,32 +128,33 @@ nsresult NS_MsgGetAttributeFromString(const char *string, PRInt16 *attrib)
if (!headers.IsEmpty())
{
char *headersString = ToNewCString(headers);
nsCAutoString hdrStr;
hdrStr.Adopt(headersString);
hdrStr.StripWhitespace(); //remove whitespace before parsing
char *newStr=nsnull;
char *token = nsCRT::strtok(headersString,": ", &newStr);
char *token = nsCRT::strtok(headersString,":", &newStr);
PRUint32 i=0;
while (token)
{
if (nsCRT::strcasecmp(token, string) == 0)
{
*attrib += i;
nsMemory::Free(headersString); //we found custom header in the pref
*attrib += i; //we found custom header in the pref
return NS_OK;
}
token = nsCRT::strtok(newStr,": ", &newStr);
token = nsCRT::strtok(newStr,":", &newStr);
i++;
//we know we can have a max of 50 custom headers
if ( nsMsgSearchAttrib::OtherHeader + i >= nsMsgSearchAttrib::kNumMsgSearchAttributes -1)
{
nsMemory::Free(headersString);
NS_ASSERTION(0, "pref has more headers than the table can hold");
return NS_MSG_CUSTOM_HEADERS_OVERFLOW;
}
}
*attrib += i; //this is *attrib for the new custom header
nsMemory::Free(headersString);
headers.Append(": "); //Adding additonal header to the pref so append the separator
}