Bug 2856 - [review] report_safe_copy_headers should preserve header order correctly for Received
Summary: [review] report_safe_copy_headers should preserve header order correctly for ...
Status: RESOLVED FIXED
Alias: None
Product: Spamassassin
Classification: Unclassified
Component: spamassassin (show other bugs)
Version: 2.61
Hardware: Other other
: P5 normal
Target Milestone: 2.62
Assignee: Theo Van Dinter
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-12-18 23:00 UTC by Gary Funck
Modified: 2004-01-08 06:45 UTC (History)
1 user (show)



Attachment Type Modified Status Actions Submitter/CLA Status
suggested patch patch None Theo Van Dinter [HasCLA]

Note You need to log in before you can comment on or make changes to this bug.
Description Gary Funck 2003-12-18 23:00:32 UTC
Given,

report_safe 1
 
# Copy the Received lines into the containing report header.
report_safe_copy_headers Received


The received headers of the resulting spam report message look like this;

Received: from localhost [127.0.0.1] by screamer
	with SpamAssassin (2.61 1.212.2.1-2003-12-09-exp);
	Thu, 18 Dec 2003 22:30:41 -0800
Received: from 61.104.127.124 by lw9fd.law9.hotmail.msn.com with HTTP;
	Fri, 19 Dec 2003 06:30:17 GMT
Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC;
	 Thu, 18 Dec 2003 22:30:17 -0800
Received: from hotmail.com (law9-f123.law9.hotmail.com [64.4.9.123])
	by intrepid.intrepid.com (8.12.8/8.12.8) with ESMTP id hBJ6UG1K019722
	for <gary@intrepid.com>; Thu, 18 Dec 2003 22:30:16 -0800
Received: from intrepid.intrepid.com (intrepid.intrepid.com [192.195.190.1])
	by screamer.intrepid.com (8.12.8/8.12.8) with ESMTP id hBJ6UGhE008956
	for <gary@screamer.intrepid.com>; Thu, 18 Dec 2003 22:30:16 -0800

In the case of Received heders in particular, the order of appearance has some
relevance. They would make more sense if the first line (showing with 
SpamAssassin) was instead appended to the end of the Received headers that were 
copied into the message header. The final result would appear as follows:

Received: from 61.104.127.124 by lw9fd.law9.hotmail.msn.com with HTTP;
	Fri, 19 Dec 2003 06:30:17 GMT
Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC;
	 Thu, 18 Dec 2003 22:30:17 -0800
Received: from hotmail.com (law9-f123.law9.hotmail.com [64.4.9.123])
	by intrepid.intrepid.com (8.12.8/8.12.8) with ESMTP id hBJ6UG1K019722
	for <gary@intrepid.com>; Thu, 18 Dec 2003 22:30:16 -0800
Received: from intrepid.intrepid.com (intrepid.intrepid.com [192.195.190.1])
	by screamer.intrepid.com (8.12.8/8.12.8) with ESMTP id hBJ6UGhE008956
	for <gary@screamer.intrepid.com>; Thu, 18 Dec 2003 22:30:16 -0800
Received: from localhost [127.0.0.1] by screamer
	with SpamAssassin (2.61 1.212.2.1-2003-12-09-exp);
	Thu, 18 Dec 2003 22:30:41 -0800

In fact, I wonder if this additional SA header is needed at all in the
case that that the Received headers were designated to be copied into
the header?
Comment 1 Theo Van Dinter 2003-12-19 06:33:49 UTC
Subject: Re: [SAdev]  New: safe copy of Received header should append the SA header

On Thu, Dec 18, 2003 at 11:55:53PM -0800, bugzilla-daemon@bugzilla.spamassassin.org wrote:
> In the case of Received heders in particular, the order of appearance has some
> relevance. They would make more sense if the first line (showing with 
> SpamAssassin) was instead appended to the end of the Received headers that were 
> copied into the message header. The final result would appear as follows:

Except that the most recent Received header needs to be at the top of the list.

> In fact, I wonder if this additional SA header is needed at all in the
> case that that the Received headers were designated to be copied into
> the header?

That's a valid question.  I would personally say no, but ...  I'm open
for suggestions from other devs.

Comment 2 Gary Funck 2003-12-19 07:34:05 UTC
Theo replied:
> Except that the most recent Received header needs to be at the top of the 
list.

Taking a second look at what's going on -- it looks as if safe_copy_header
has *reversed* the order of occurrence of the received headers. The original
message headers appear as follows:

Received: from intrepid.intrepid.com (intrepid.intrepid.com [192.195.190.1])
	by screamer.intrepid.com (8.12.8/8.12.8) with ESMTP id hBJ6UGhE008956
	for <gary@screamer.intrepid.com>; Thu, 18 Dec 2003 22:30:16 -0800
Received: from hotmail.com (law9-f123.law9.hotmail.com [64.4.9.123])
	by intrepid.intrepid.com (8.12.8/8.12.8) with ESMTP id hBJ6UG1K019722
	for <gary@intrepid.com>; Thu, 18 Dec 2003 22:30:16 -0800
Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC;
	 Thu, 18 Dec 2003 22:30:17 -0800
Received: from 61.104.127.124 by lw9fd.law9.hotmail.msn.com with HTTP;
	Fri, 19 Dec 2003 06:30:17 GMT

Which are ordered most recent first, as expected. But the copied headers
appear as follows:

Received: from localhost [127.0.0.1] by screamer
	with SpamAssassin (2.61 1.212.2.1-2003-12-09-exp);
	Thu, 18 Dec 2003 22:30:41 -0800
Received: from 61.104.127.124 by lw9fd.law9.hotmail.msn.com with HTTP;
	Fri, 19 Dec 2003 06:30:17 GMT
Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC;
	 Thu, 18 Dec 2003 22:30:17 -0800
Received: from hotmail.com (law9-f123.law9.hotmail.com [64.4.9.123])
	by intrepid.intrepid.com (8.12.8/8.12.8) with ESMTP id hBJ6UG1K019722
	for <gary@intrepid.com>; Thu, 18 Dec 2003 22:30:16 -0800
Received: from intrepid.intrepid.com (intrepid.intrepid.com [192.195.190.1])
	by screamer.intrepid.com (8.12.8/8.12.8) with ESMTP id hBJ6UGhE008956
	for <gary@screamer.intrepid.com>; Thu, 18 Dec 2003 22:30:16 -0800

where all copy headers have been reversed in order of occurrence. Therefore,
the header added by SA, which is at the top as it is supposed to be is out
of chronological order with the respect to the others. The copying of the SA
header remains optional. Perhaps it needs to be there because a new message
(the containing report) is being constructed.

Thus, it seems the bug summary should be restated that safe_copy_headers should
preserve the order of the headers that it is copying.

Comment 3 Justin Mason 2003-12-19 11:16:34 UTC
agreed, this is a bug.

>In fact, I wonder if this additional SA header is needed at all in the
>case that that the Received headers were designated to be copied into
>the header?

IMO, it should be kept.
Comment 4 Theo Van Dinter 2003-12-19 11:44:43 UTC
The bug, BTW, is here:

      foreach ( @hdrtext ) {
        if ( lc $hdr eq "received" ) { # add Received at the top ...
          $newmsg = "$hdr: $_$newmsg";
        }
        else { # if not Received, add at the bottom ...
          $newmsg .= "$hdr: $_";
        }
      }

not sure how to go about this without making a "pre" variable which Received will go into specially, 
then it's added later or something.  hrm.
Comment 5 Theo Van Dinter 2003-12-20 04:58:44 UTC
moving to 2.62
Comment 6 Theo Van Dinter 2003-12-20 05:00:08 UTC
taking the ticket.
Comment 7 Theo Van Dinter 2003-12-20 06:48:51 UTC
Created attachment 1629 [details]
suggested patch

patch fixes the ordering of the copied Received header, also disables the
addition of the SpamAssassin Received header if we copied the original one
over.
Comment 8 Theo Van Dinter 2003-12-20 06:49:34 UTC
fyi: patch not applied to 2.70 due to cvs freeze
Comment 9 Theo Van Dinter 2003-12-25 20:31:46 UTC
fyi, Justin thought the SA Received header should always be added.

imo, if we restore the Received header via config, then we shouldn't add a non-consecutive header.  
but I'd like to hear other's thoughts before we go yes or no here.
Comment 10 Gary Funck 2003-12-26 16:23:36 UTC
I don't have any strong opinions on this, but can see some merit in adding the 
SA line so that it is clear that the received trail was tweaked by SA. It is 
easy enough to ignore.

That said, since those received lines are copies of the original, I suppose a 
case could be made for renaming the copied headers into X-Received-Copy, and 
then add the SA Received as an actual Received header. Sufficiently 
complicated? <g>
Comment 11 Theo Van Dinter 2003-12-28 19:23:29 UTC
Subject: Re:  [review] report_safe_copy_headers should preserve header order correctly for Received

On Fri, Dec 26, 2003 at 05:18:48PM -0800, bugzilla-daemon@bugzilla.spamassassin.org wrote:
> That said, since those received lines are copies of the original, I suppose a 
> case could be made for renaming the copied headers into X-Received-Copy, and 
> then add the SA Received as an actual Received header. Sufficiently 
> complicated? <g>

Well, that would break the meaning of the config option.  Special cases
should be avoided if possible.

Comment 12 Justin Mason 2004-01-07 16:54:24 UTC
+1 -- although I would prefer if the SA-generated Received header were to be
prepended to the list...
Comment 13 Theo Van Dinter 2004-01-08 15:45:13 UTC
committed to head and 2.62