зеркало из https://github.com/mozilla/pjs.git
parse Received: header and prefer the date there to the sender's Date: header, which is less reliable, also handle date for imap messages with neither header, sr=mscott 166254
This commit is contained in:
Родитель
a5d78b3840
Коммит
4f91a53ec4
|
@ -526,6 +526,7 @@ NS_IMETHODIMP nsParseMailMessageState::Clear()
|
|||
ClearAggregateHeader (m_ccList);
|
||||
m_headers.ResetWritePos();
|
||||
m_envelope.ResetWritePos();
|
||||
m_receivedTime = LL_ZERO;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -852,7 +853,8 @@ int nsParseMailMessageState::ParseHeaders ()
|
|||
char *end;
|
||||
char *value = 0;
|
||||
struct message_header *header = 0;
|
||||
|
||||
struct message_header receivedBy;
|
||||
|
||||
if (! colon)
|
||||
break;
|
||||
|
||||
|
@ -905,6 +907,11 @@ int nsParseMailMessageState::ParseHeaders ()
|
|||
header = &m_mdn_dnt;
|
||||
else if (!nsCRT::strncasecmp("Reply-To", buf, end - buf))
|
||||
header = &m_replyTo;
|
||||
else if (!nsCRT::strncasecmp("Received", buf, end - buf))
|
||||
{
|
||||
header = &receivedBy;
|
||||
header->length = 0;
|
||||
}
|
||||
break;
|
||||
case 'S': case 's':
|
||||
if (!nsCRT::strncasecmp ("Subject", buf, end - buf))
|
||||
|
@ -993,9 +1000,26 @@ SEARCH_NEWLINE:
|
|||
while (header->length > 0 &&
|
||||
IS_SPACE (header->value [header->length - 1]))
|
||||
((char *) header->value) [--header->length] = 0;
|
||||
}
|
||||
if (header == &receivedBy && LL_IS_ZERO(m_receivedTime))
|
||||
{
|
||||
// parse Received: header for date.
|
||||
// We trust the first header as that is closest to recipient,
|
||||
// and less likely to be spoofed.
|
||||
nsCAutoString receivedHdr(header->value, header->length);
|
||||
PRInt32 lastSemicolon = receivedHdr.RFindChar(';');
|
||||
if (lastSemicolon != kNotFound)
|
||||
{
|
||||
nsCAutoString receivedDate;
|
||||
receivedHdr.Right(receivedDate, receivedHdr.Length() - lastSemicolon - 1);
|
||||
receivedDate.Trim(" \t\b\r\n");
|
||||
PRTime resultTime;
|
||||
if (PR_ParseTimeString (receivedDate.get(), PR_FALSE, &resultTime) == PR_SUCCESS)
|
||||
m_receivedTime = resultTime;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nsParseMailMessageState::ParseEnvelope (const char *line, PRUint32 line_size)
|
||||
|
@ -1376,11 +1400,19 @@ int nsParseMailMessageState::FinalizeHeaders()
|
|||
else if (inReplyTo != nsnull)
|
||||
m_newMsgHdr->SetReferences(inReplyTo->value);
|
||||
|
||||
if (date) {
|
||||
PRTime resultTime;
|
||||
PRStatus timeStatus = PR_ParseTimeString (date->value, PR_FALSE, &resultTime);
|
||||
if (PR_SUCCESS == timeStatus)
|
||||
m_newMsgHdr->SetDate(resultTime);
|
||||
if (!LL_IS_ZERO(m_receivedTime))
|
||||
m_newMsgHdr->SetDate(m_receivedTime);
|
||||
else
|
||||
{
|
||||
// if there's no date, or it's mal-formed, use now as the time.
|
||||
// PR_ParseTimeString won't touch resultTime unless it succeeds.
|
||||
// (this doesn't affect local messages, because we use the envelope
|
||||
// date if there's no Date: header, but it would affect IMAP msgs
|
||||
// w/o a Date: hdr or Received: headers)
|
||||
PRTime resultTime = PR_Now();
|
||||
if (date)
|
||||
PR_ParseTimeString (date->value, PR_FALSE, &resultTime);
|
||||
m_newMsgHdr->SetDate(resultTime);
|
||||
}
|
||||
if (priority)
|
||||
m_newMsgHdr->SetPriorityString(priority->value);
|
||||
|
|
|
@ -145,7 +145,8 @@ public:
|
|||
struct message_header m_mdn_original_recipient;
|
||||
struct message_header m_return_path;
|
||||
struct message_header m_mdn_dnt; /* MDN Disposition-Notification-To: header */
|
||||
|
||||
|
||||
PRTime m_receivedTime;
|
||||
PRUint16 m_body_lines;
|
||||
|
||||
PRBool m_IgnoreXMozillaStatus;
|
||||
|
|
Загрузка…
Ссылка в новой задаче