зеркало из https://github.com/mozilla/gecko-dev.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:
Родитель
6c2b808fd8
Коммит
1e05e6fb96
|
@ -526,6 +526,7 @@ NS_IMETHODIMP nsParseMailMessageState::Clear()
|
||||||
ClearAggregateHeader (m_ccList);
|
ClearAggregateHeader (m_ccList);
|
||||||
m_headers.ResetWritePos();
|
m_headers.ResetWritePos();
|
||||||
m_envelope.ResetWritePos();
|
m_envelope.ResetWritePos();
|
||||||
|
m_receivedTime = LL_ZERO;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -852,7 +853,8 @@ int nsParseMailMessageState::ParseHeaders ()
|
||||||
char *end;
|
char *end;
|
||||||
char *value = 0;
|
char *value = 0;
|
||||||
struct message_header *header = 0;
|
struct message_header *header = 0;
|
||||||
|
struct message_header receivedBy;
|
||||||
|
|
||||||
if (! colon)
|
if (! colon)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -905,6 +907,11 @@ int nsParseMailMessageState::ParseHeaders ()
|
||||||
header = &m_mdn_dnt;
|
header = &m_mdn_dnt;
|
||||||
else if (!nsCRT::strncasecmp("Reply-To", buf, end - buf))
|
else if (!nsCRT::strncasecmp("Reply-To", buf, end - buf))
|
||||||
header = &m_replyTo;
|
header = &m_replyTo;
|
||||||
|
else if (!nsCRT::strncasecmp("Received", buf, end - buf))
|
||||||
|
{
|
||||||
|
header = &receivedBy;
|
||||||
|
header->length = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'S': case 's':
|
case 'S': case 's':
|
||||||
if (!nsCRT::strncasecmp ("Subject", buf, end - buf))
|
if (!nsCRT::strncasecmp ("Subject", buf, end - buf))
|
||||||
|
@ -993,9 +1000,26 @@ SEARCH_NEWLINE:
|
||||||
while (header->length > 0 &&
|
while (header->length > 0 &&
|
||||||
IS_SPACE (header->value [header->length - 1]))
|
IS_SPACE (header->value [header->length - 1]))
|
||||||
((char *) header->value) [--header->length] = 0;
|
((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)
|
int nsParseMailMessageState::ParseEnvelope (const char *line, PRUint32 line_size)
|
||||||
|
@ -1376,11 +1400,19 @@ int nsParseMailMessageState::FinalizeHeaders()
|
||||||
else if (inReplyTo != nsnull)
|
else if (inReplyTo != nsnull)
|
||||||
m_newMsgHdr->SetReferences(inReplyTo->value);
|
m_newMsgHdr->SetReferences(inReplyTo->value);
|
||||||
|
|
||||||
if (date) {
|
if (!LL_IS_ZERO(m_receivedTime))
|
||||||
PRTime resultTime;
|
m_newMsgHdr->SetDate(m_receivedTime);
|
||||||
PRStatus timeStatus = PR_ParseTimeString (date->value, PR_FALSE, &resultTime);
|
else
|
||||||
if (PR_SUCCESS == timeStatus)
|
{
|
||||||
m_newMsgHdr->SetDate(resultTime);
|
// 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)
|
if (priority)
|
||||||
m_newMsgHdr->SetPriorityString(priority->value);
|
m_newMsgHdr->SetPriorityString(priority->value);
|
||||||
|
|
|
@ -145,7 +145,8 @@ public:
|
||||||
struct message_header m_mdn_original_recipient;
|
struct message_header m_mdn_original_recipient;
|
||||||
struct message_header m_return_path;
|
struct message_header m_return_path;
|
||||||
struct message_header m_mdn_dnt; /* MDN Disposition-Notification-To: header */
|
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;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче