Improve X-Priority support b=146075 p=sgautherie.bz@free.fr r=me sr=bienvenu

This commit is contained in:
neil%parkwaycc.co.uk 2006-10-10 09:28:26 +00:00
Родитель ea4e625f11
Коммит 04bf002b25
7 изменённых файлов: 167 добавлений и 110 удалений

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

@ -746,11 +746,10 @@ nsresult nsMsgFilter::SaveRule(nsIOFileStream *aStream)
{
nsMsgPriorityValue priorityValue;
action->GetPriority(&priorityValue);
nsAutoString priority;
NS_MsgGetUntranslatedPriorityName (priorityValue, &priority);
nsCAutoString cStr;
cStr.AssignWithConversion(priority);
err = filterList->WriteStrAttr(nsIMsgFilterList::attribActionValue, cStr.get(), aStream);
nsCAutoString priority;
NS_MsgGetUntranslatedPriorityName(priorityValue, priority);
err = filterList->WriteStrAttr(
nsIMsgFilterList::attribActionValue, priority.get(), aStream);
}
break;
case nsMsgFilterAction::Label:

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

@ -69,7 +69,10 @@ nsMsgFilterList::nsMsgFilterList() :
m_fileVersion(0)
{
// I don't know how we're going to report this error if we failed to create the isupports array...
nsresult rv = NS_NewISupportsArray(getter_AddRefs(m_filters));
#ifdef DEBUG
nsresult rv =
#endif
NS_NewISupportsArray(getter_AddRefs(m_filters));
NS_ASSERTION(NS_SUCCEEDED(rv), "Fixme bug 180312: NS_NewISupportsArray() failed");
m_loggingEnabled = PR_FALSE;
@ -159,10 +162,14 @@ NS_IMETHODIMP nsMsgFilterList::ClearLog()
// disable logging while clearing
m_loggingEnabled = PR_FALSE;
nsresult rv = TruncateLog();
#ifdef DEBUG
nsresult rv =
#endif
TruncateLog();
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to truncate filter log");
m_loggingEnabled = loggingEnabled;
return NS_OK;
}
@ -678,7 +685,7 @@ nsresult nsMsgFilterList::LoadTextFilters(nsIOFileStream *aStream)
else if (type == nsMsgFilterAction::ChangePriority)
{
nsMsgPriorityValue outPriority;
nsresult res = NS_MsgGetPriorityFromString(value.get(), &outPriority);
nsresult res = NS_MsgGetPriorityFromString(value.get(), outPriority);
if (NS_SUCCEEDED(res))
currentFilterAction->SetPriority(outPriority);
else

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

@ -469,10 +469,9 @@ nsresult nsMsgSearchTerm::OutputValue(nsCString &outputStr)
}
case nsMsgSearchAttrib::Priority:
{
nsAutoString priority;
NS_MsgGetUntranslatedPriorityName( m_value.u.priority,
&priority);
outputStr.AppendWithConversion(priority);
nsCAutoString priority;
NS_MsgGetUntranslatedPriorityName(m_value.u.priority, priority);
outputStr += priority;
break;
}
case nsMsgSearchAttrib::HasAttachmentStatus:
@ -564,7 +563,7 @@ nsresult nsMsgSearchTerm::ParseValue(char *inStream)
m_value.u.msgStatus = NS_MsgGetStatusValueFromName(inStream);
break;
case nsMsgSearchAttrib::Priority:
NS_MsgGetPriorityFromString(inStream, &m_value.u.priority);
NS_MsgGetPriorityFromString(inStream, m_value.u.priority);
break;
case nsMsgSearchAttrib::AgeInDays:
m_value.u.age = atoi(inStream);

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

@ -172,76 +172,119 @@ nsresult CreateStartupUrl(const char *uri, nsIURI** aUrl)
}
// Where should this live? It's a utility used to convert a string priority, e.g., "High, Low, Normal" to an enum.
// Perhaps we should have an interface that groups together all these utilities...
nsresult NS_MsgGetPriorityFromString(const char *priority, nsMsgPriorityValue *outPriority)
// Where should this live? It's a utility used to convert a string priority,
// e.g., "High, Low, Normal" to an enum.
// Perhaps we should have an interface that groups together all these
// utilities...
nsresult NS_MsgGetPriorityFromString(
const char * const priority,
nsMsgPriorityValue & outPriority)
{
if (!outPriority)
if (!priority)
return NS_ERROR_NULL_POINTER;
nsMsgPriorityValue retPriority = nsMsgPriority::normal;
if (PL_strcasestr(priority, "Normal") != NULL)
retPriority = nsMsgPriority::normal;
else if (PL_strcasestr(priority, "Lowest") != NULL)
retPriority = nsMsgPriority::lowest;
else if (PL_strcasestr(priority, "Highest") != NULL)
retPriority = nsMsgPriority::highest;
else if (PL_strcasestr(priority, "High") != NULL ||
PL_strcasestr(priority, "Urgent") != NULL)
retPriority = nsMsgPriority::high;
else if (PL_strcasestr(priority, "Low") != NULL ||
PL_strcasestr(priority, "Non-urgent") != NULL)
retPriority = nsMsgPriority::low;
else if (PL_strcasestr(priority, "1") != NULL)
retPriority = nsMsgPriority::highest;
else if (PL_strcasestr(priority, "2") != NULL)
retPriority = nsMsgPriority::high;
else if (PL_strcasestr(priority, "3") != NULL)
retPriority = nsMsgPriority::normal;
else if (PL_strcasestr(priority, "4") != NULL)
retPriority = nsMsgPriority::low;
else if (PL_strcasestr(priority, "5") != NULL)
retPriority = nsMsgPriority::lowest;
// Note: Checking the values separately and _before_ the names,
// hoping for a much faster match;
// Only _drawback_, as "priority" handling is not truly specified:
// some softwares may have the number meanings reversed (1=Lowest) !?
if (PL_strchr(priority, '1'))
outPriority = nsMsgPriority::highest;
else if (PL_strchr(priority, '2'))
outPriority = nsMsgPriority::high;
else if (PL_strchr(priority, '3'))
outPriority = nsMsgPriority::normal;
else if (PL_strchr(priority, '4'))
outPriority = nsMsgPriority::low;
else if (PL_strchr(priority, '5'))
outPriority = nsMsgPriority::lowest;
else if (PL_strcasestr(priority, "Highest"))
outPriority = nsMsgPriority::highest;
// Important: "High" must be tested after "Highest" !
else if (PL_strcasestr(priority, "High") ||
PL_strcasestr(priority, "Urgent"))
outPriority = nsMsgPriority::high;
else if (PL_strcasestr(priority, "Normal"))
outPriority = nsMsgPriority::normal;
else if (PL_strcasestr(priority, "Lowest"))
outPriority = nsMsgPriority::lowest;
// Important: "Low" must be tested after "Lowest" !
else if (PL_strcasestr(priority, "Low") ||
PL_strcasestr(priority, "Non-urgent"))
outPriority = nsMsgPriority::low;
else
retPriority = nsMsgPriority::normal;
*outPriority = retPriority;
// "Default" case gets default value.
outPriority = nsMsgPriority::Default;
return NS_OK;
//return nsMsgNoPriority;
}
nsresult NS_MsgGetUntranslatedPriorityName (nsMsgPriorityValue p, nsString *outName)
nsresult NS_MsgGetPriorityValueString(
const nsMsgPriorityValue p,
nsACString & outValueString)
{
if (!outName)
return NS_ERROR_NULL_POINTER;
switch (p)
{
case nsMsgPriority::notSet:
case nsMsgPriority::none:
outName->AssignLiteral("None");
break;
case nsMsgPriority::lowest:
outName->AssignLiteral("Lowest");
break;
case nsMsgPriority::low:
outName->AssignLiteral("Low");
break;
case nsMsgPriority::normal:
outName->AssignLiteral("Normal");
case nsMsgPriority::highest:
outValueString.AssignLiteral("1");
break;
case nsMsgPriority::high:
outName->AssignLiteral("High");
outValueString.AssignLiteral("2");
break;
case nsMsgPriority::highest:
outName->AssignLiteral("Highest");
case nsMsgPriority::normal:
outValueString.AssignLiteral("3");
break;
case nsMsgPriority::low:
outValueString.AssignLiteral("4");
break;
case nsMsgPriority::lowest:
outValueString.AssignLiteral("5");
break;
case nsMsgPriority::none:
case nsMsgPriority::notSet:
// Note: '0' is a "fake" value; we expect to never be in this case.
outValueString.AssignLiteral("0");
break;
default:
NS_ASSERTION(PR_FALSE, "invalid priority value");
}
return NS_OK;
}
nsresult NS_MsgGetUntranslatedPriorityName(
const nsMsgPriorityValue p,
nsACString & outName)
{
switch (p)
{
case nsMsgPriority::highest:
outName.AssignLiteral("Highest");
break;
case nsMsgPriority::high:
outName.AssignLiteral("High");
break;
case nsMsgPriority::normal:
outName.AssignLiteral("Normal");
break;
case nsMsgPriority::low:
outName.AssignLiteral("Low");
break;
case nsMsgPriority::lowest:
outName.AssignLiteral("Lowest");
break;
case nsMsgPriority::none:
case nsMsgPriority::notSet:
// Note: 'None' is a "fake" value; we expect to never be in this case.
outName.AssignLiteral("None");
break;
default:
NS_ASSERTION(PR_FALSE, "invalid priority value");
}
return NS_OK;
}
/* this used to be XP_StringHash2 from xp_hash.c */
/* phong's linear congruential hash */
static PRUint32 StringHash(const char *ubuf, PRInt32 len = -1)

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

@ -64,9 +64,17 @@ NS_MSG_BASE nsresult GetMsgDBHdrFromURI(const char *uri, nsIMsgDBHdr **msgHdr);
NS_MSG_BASE nsresult CreateStartupUrl(const char *uri, nsIURI** aUrl);
NS_MSG_BASE nsresult NS_MsgGetPriorityFromString(const char *priority, nsMsgPriorityValue *outPriority);
NS_MSG_BASE nsresult NS_MsgGetPriorityFromString(
const char * const priority,
nsMsgPriorityValue & outPriority);
NS_MSG_BASE nsresult NS_MsgGetUntranslatedPriorityName (nsMsgPriorityValue p, nsString *outName);
NS_MSG_BASE nsresult NS_MsgGetPriorityValueString(
const nsMsgPriorityValue p,
nsACString & outValueString);
NS_MSG_BASE nsresult NS_MsgGetUntranslatedPriorityName(
const nsMsgPriorityValue p,
nsACString & outName);
NS_MSG_BASE nsresult NS_MsgHashIfNecessary(nsAutoString &name);
NS_MSG_BASE nsresult NS_MsgHashIfNecessary(nsCAutoString &name);

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

@ -392,16 +392,13 @@ mime_generate_headers (nsMsgCompFields *fields,
// nsIMsgMdnGenerator::eDntType = MDN Disposition-Notification-To: ;
// nsIMsgMdnGenerator::eRrtType = Return-Receipt-To: ;
// nsIMsgMdnGenerator::eDntRrtType = both MDN DNT & RRT headers
if (receipt_header_type == nsIMsgMdnGenerator::eRrtType) {
RRT_HEADER:
ENCODE_AND_PUSH("Return-Receipt-To: ", PR_TRUE, pFrom, charset, usemime);
}
else {
ENCODE_AND_PUSH("Disposition-Notification-To: ", PR_TRUE, pFrom, charset, usemime);
if (receipt_header_type == nsIMsgMdnGenerator::eDntRrtType)
goto RRT_HEADER;
}
// nsIMsgMdnGenerator::eDntRrtType = both MDN DNT and RRT headers .
if (receipt_header_type != nsIMsgMdnGenerator::eRrtType)
ENCODE_AND_PUSH(
"Disposition-Notification-To: ", PR_TRUE, pFrom, charset, usemime);
if (receipt_header_type != nsIMsgMdnGenerator::eDntType)
ENCODE_AND_PUSH(
"Return-Receipt-To: ", PR_TRUE, pFrom, charset, usemime);
}
#ifdef SUPPORT_X_TEMPLATE_NAME
@ -696,24 +693,28 @@ RRT_HEADER:
ENCODE_AND_PUSH("Subject: ", PR_FALSE, pSubject, charset, usemime);
}
if (pPriority && *pPriority)
if (!PL_strcasestr(pPriority, "normal")) {
PUSH_STRING ("X-Priority: ");
/* Important: do not change the order of the
* following if statements
*/
if (PL_strcasestr (pPriority, "highest"))
PUSH_STRING("1 (");
else if (PL_strcasestr(pPriority, "high"))
PUSH_STRING("2 (");
else if (PL_strcasestr(pPriority, "lowest"))
PUSH_STRING("5 (");
else if (PL_strcasestr(pPriority, "low"))
PUSH_STRING("4 (");
// Skip no or empty priority.
if (pPriority && *pPriority) {
nsMsgPriorityValue priorityValue;
PUSH_STRING (pPriority);
NS_MsgGetPriorityFromString(pPriority, priorityValue);
// Skip default priority.
if (priorityValue != nsMsgPriority::Default) {
nsCAutoString priorityName;
nsCAutoString priorityValueString;
NS_MsgGetPriorityValueString(priorityValue, priorityValueString);
NS_MsgGetUntranslatedPriorityName(priorityValue, priorityName);
// Output format: [X-Priority: <pValue> (<pName>)]
PUSH_STRING("X-Priority: ");
PUSH_STRING(priorityValueString.get());
PUSH_STRING(" (");
PUSH_STRING(priorityName.get());
PUSH_STRING(")");
PUSH_NEWLINE ();
PUSH_NEWLINE();
}
}
if (pReference && *pReference) {

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

@ -634,12 +634,12 @@ NS_IMETHODIMP nsMsgHdr::GetLineCount(PRUint32 *result)
NS_IMETHODIMP nsMsgHdr::SetPriorityString(const char *priority)
{
nsMsgPriorityValue priorityVal = nsMsgPriority::normal;
nsMsgPriorityValue priorityVal = nsMsgPriority::Default;
// We can ignore |NS_MsgGetPriorityFromString()| return value,
// since we set a default value for |priorityVal|.
NS_MsgGetPriorityFromString(priority, priorityVal);
// NS_MsgGetPriorityFromString will return normal in case of error,
// so we can ignore return value.
nsresult res;
res = NS_MsgGetPriorityFromString(priority, &priorityVal);
return SetPriority(priorityVal);
}