allow extensions to customize which headers are stored in the .msf file via a pref, which will help enable custom columns based on msg headers sr=mscott 356860
git-svn-id: svn://10.0.0.236/trunk@214415 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -317,6 +317,7 @@ static PRBool gUseLiteralPlus = PR_TRUE;
|
||||
static PRBool gExpungeAfterDelete = PR_FALSE;
|
||||
static PRBool gCheckDeletedBeforeExpunge = PR_FALSE; //bug 235004
|
||||
static PRInt32 gResponseTimeout = 60;
|
||||
static nsCStringArray gCustomDBHeaders;
|
||||
|
||||
nsresult nsImapProtocol::GlobalInitialization()
|
||||
{
|
||||
@@ -342,6 +343,9 @@ nsresult nsImapProtocol::GlobalInitialization()
|
||||
prefBranch->GetBoolPref("mail.imap.expunge_after_delete", &gExpungeAfterDelete);
|
||||
prefBranch->GetBoolPref("mail.imap.check_deleted_before_expunge", &gCheckDeletedBeforeExpunge);
|
||||
prefBranch->GetIntPref("mailnews.tcptimeout", &gResponseTimeout);
|
||||
nsXPIDLCString customDBHeaders;
|
||||
prefBranch->GetCharPref("mailnews.customDBHeaders", getter_Copies(customDBHeaders));
|
||||
gCustomDBHeaders.ParseString(customDBHeaders, ", ");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -3019,6 +3023,15 @@ nsImapProtocol::FetchMessage(const char * messageIds,
|
||||
const char *dbHeaders = (gUseEnvelopeCmd) ? IMAP_DB_HEADERS : IMAP_ENV_AND_DB_HEADERS;
|
||||
nsXPIDLCString arbitraryHeaders;
|
||||
GetArbitraryHeadersToDownload(getter_Copies(arbitraryHeaders));
|
||||
for (PRInt32 i = 0; i < gCustomDBHeaders.Count(); i++)
|
||||
{
|
||||
if (arbitraryHeaders.Find(* (gCustomDBHeaders[i]), PR_TRUE) == kNotFound)
|
||||
{
|
||||
if (!arbitraryHeaders.IsEmpty())
|
||||
arbitraryHeaders.Append(' ');
|
||||
arbitraryHeaders.Append(gCustomDBHeaders[i]->get());
|
||||
}
|
||||
}
|
||||
if (arbitraryHeaders.IsEmpty())
|
||||
headersToDL = nsCRT::strdup(dbHeaders);
|
||||
else
|
||||
|
||||
@@ -475,6 +475,28 @@ nsParseMailMessageState::nsParseMailMessageState()
|
||||
m_position = 0;
|
||||
m_IgnoreXMozillaStatus = PR_FALSE;
|
||||
m_state = nsIMsgParseMailMsgState::ParseBodyState;
|
||||
|
||||
// setup handling of custom db headers, headers that are added to .msf files
|
||||
// as properties of the nsMsgHdr objects, controlled by the
|
||||
// pref mailnews.customDBHeaders.
|
||||
// E.g., if mailnews.customDBHeaders is "X-Spam-Score", and we're parsing
|
||||
// a mail message with the X-Spam-Score header, we'll set the
|
||||
// "x-spam-score" property of nsMsgHdr to the value of the header.
|
||||
m_customDBHeaderValues = nsnull;
|
||||
nsXPIDLCString customDBHeaders;
|
||||
nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (pPrefBranch)
|
||||
{
|
||||
pPrefBranch->GetCharPref("mailnews.customDBHeaders", getter_Copies(customDBHeaders));
|
||||
ToLowerCase(customDBHeaders);
|
||||
m_customDBHeaders.ParseString(customDBHeaders, ", ");
|
||||
if (m_customDBHeaders.Count())
|
||||
{
|
||||
m_customDBHeaderValues = new struct message_header [m_customDBHeaders.Count()];
|
||||
if (!m_customDBHeaderValues)
|
||||
m_customDBHeaders.Clear();
|
||||
}
|
||||
}
|
||||
Clear();
|
||||
|
||||
m_HeaderAddressParser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID);
|
||||
@@ -484,6 +506,7 @@ nsParseMailMessageState::~nsParseMailMessageState()
|
||||
{
|
||||
ClearAggregateHeader (m_toList);
|
||||
ClearAggregateHeader (m_ccList);
|
||||
delete [] m_customDBHeaderValues;
|
||||
}
|
||||
|
||||
void nsParseMailMessageState::Init(PRUint32 fileposition)
|
||||
@@ -524,6 +547,9 @@ NS_IMETHODIMP nsParseMailMessageState::Clear()
|
||||
m_headers.ResetWritePos();
|
||||
m_envelope.ResetWritePos();
|
||||
m_receivedTime = LL_ZERO;
|
||||
for (PRInt32 i = 0; i < m_customDBHeaders.Count(); i++)
|
||||
m_customDBHeaderValues[i].length = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -946,6 +972,15 @@ int nsParseMailMessageState::ParseHeaders ()
|
||||
header = &m_keywords;
|
||||
break;
|
||||
}
|
||||
if (!header && m_customDBHeaders.Count())
|
||||
{
|
||||
nsDependentCSubstring headerStr(buf, end);
|
||||
|
||||
ToLowerCase(headerStr);
|
||||
PRInt32 customHeaderIndex = m_customDBHeaders.IndexOf(headerStr);
|
||||
if (customHeaderIndex != kNotFound)
|
||||
header = & m_customDBHeaderValues[customHeaderIndex];
|
||||
}
|
||||
|
||||
buf = colon + 1;
|
||||
while (*buf == ' ' || *buf == '\t')
|
||||
@@ -954,6 +989,9 @@ int nsParseMailMessageState::ParseHeaders ()
|
||||
value = buf;
|
||||
if (header)
|
||||
header->value = value;
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
SEARCH_NEWLINE:
|
||||
while (*buf != 0 && *buf != nsCRT::CR && *buf != nsCRT::LF)
|
||||
@@ -1425,6 +1463,11 @@ int nsParseMailMessageState::FinalizeHeaders()
|
||||
m_newMsgHdr->SetPriority(nsMsgPriority::none);
|
||||
if (keywords)
|
||||
m_newMsgHdr->SetStringProperty("keywords", keywords->value);
|
||||
for (PRInt32 i = 0; i < m_customDBHeaders.Count(); i++)
|
||||
{
|
||||
if (m_customDBHeaderValues[i].length)
|
||||
m_newMsgHdr->SetStringProperty((m_customDBHeaders[i])->get(), m_customDBHeaderValues[i].value);
|
||||
}
|
||||
if (content_type)
|
||||
{
|
||||
char *substring = PL_strstr(content_type->value, "charset");
|
||||
|
||||
@@ -148,9 +148,15 @@ public:
|
||||
struct message_header m_mdn_dnt; /* MDN Disposition-Notification-To: header */
|
||||
|
||||
PRTime m_receivedTime;
|
||||
PRUint16 m_body_lines;
|
||||
PRUint16 m_body_lines;
|
||||
|
||||
PRBool m_IgnoreXMozillaStatus;
|
||||
PRBool m_IgnoreXMozillaStatus;
|
||||
|
||||
// this enables extensions to add the values of particular headers to
|
||||
// the .msf file as properties of nsIMsgHdr. It is initialized from a
|
||||
// pref, mailnews.customDBHeaders
|
||||
nsCStringArray m_customDBHeaders;
|
||||
struct message_header *m_customDBHeaderValues;
|
||||
protected:
|
||||
nsCOMPtr<nsIMsgStringService> mStringService;
|
||||
|
||||
|
||||
@@ -368,6 +368,8 @@ pref("ldap_2.prefs_migrated", false);
|
||||
|
||||
pref("mailnews.confirm.moveFoldersToTrash", true);
|
||||
|
||||
pref("mailnews.customDBHeaders", "");
|
||||
|
||||
pref("mailnews.reuse_message_window", true);
|
||||
pref("mailnews.reuse_thread_window2", false);
|
||||
pref("mailnews.open_window_warning", 10); // warn user if they attempt to open more than this many messages at once
|
||||
|
||||
Reference in New Issue
Block a user