You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Robert Nicholson <ro...@elastica.com> on 2006/07/19 07:09:13 UTC
get_pristine_header in an array context
If i'm suppose to get back one header per element why do I get back
the following?
that is not one header per element is it?
DB<3> x @header
0 "Status: R\cJX-Status: \cJX-Keywords:\cJFrom: \"Suphannika\" <ann
\@elastica.com>\cJTo: \"Robert Nicholson\" <ro...@elastica.com>
\cJSubject: want to AOL?\cJDate: Sat, 1 Jul 2000 06:31:21 -0700
\cJMIME-Version: 1.0\cJContent-Type: text/html;\cJ\cIcharset=
\"iso-8859-1\"\cJContent-Transfer-Encoding: quoted-printable\cJX-
Priority: 3\cJX-MSMail-Priority: Normal\cJX-MimeOLE: Produced By
Microsoft MimeOLE V6.00.2600.0000\cJ\cJ"
Re: get_pristine_header in an array context
Posted by Theo Van Dinter <fe...@apache.org>.
On Wed, Jul 19, 2006 at 12:53:49AM -0500, Robert Nicholson wrote:
> secondly I see in the SA code that in order to get one per array
> element you have to use split /^/ the documentation for
> get_pristine_header doesn't appear to be correct.
Sure it does.
-----
Returns pristine headers of the message. If no specific header name
is given as a parameter (case-insensitive), then all headers will be
returned as a scalar, including the blank line at the end of the headers.
-----
You're not passing in a header name, so you get all the headers returned
as a scalar.
> secondly why must I remove the blank line myself?
See the above get_pristine_header() doc quote. :)
The slightly longer answer is that tracking the header/body separator
seperately didn't seem useful, and this is nice and easy:
sub get_pristine {
my ($self) = @_;
return $self->{pristine_headers} . $self->{pristine_body};
}
Keep in mind too, btw, that there may not be a header/body separator if the
incoming message doesn't have one.
> $header = $mail->get_pristine_header;
> # remove the last new line
> $header =~ s/\s$//g;
>
> my $header = $check_mail->get_pristine_header;
> $header =~ s/\s$//g;
> $header .= "\cJ";
>
> my @header = split /^/m, $header;
> my $body = $check_mail->get_pristine_body;
> my @body = split /^/m, $body;
>
> push @header, "X-Accept-Flag: Sender in Whitelist\n";
> my @lines;
> push @lines, @header, "\n", @body;
Is there a reason you want an array? I'd do a couple of things to make this
simpler:
1) just prepend your header to the top of the pristine header. I do this ala:
my $msg = Mail::SpamAssassin::Message->new({ 'message' => $ptr, 'parsenow' => 0 });
$ptr = join('',
"X-TVD-header1: $header1".$msg->{'line_ending'},
"X-TVD-header2: $header2".$msg->{'line_ending'},
$msg->get_pristine_header(),
$msg->get_pristine_body(),
);
2) things like "$header =~ s/\s$//g;" can just be written "$header =~ s/\s+$//;'
3) doing #2 and then tacking on a newline (just use \n instead of \cJ btw) is
simpler via: "$header =~ s/\s+$/\n/".
4) make sure you keep the line endings the same for your headers. you don't
want some to be "\r\n" and others to be just "\n". #2 and #3 could be
better written as "$header =~ s/\n\r?\n$/\n/" to just trim out the
separator.
5) since there may not be a separator, I wouldn't put one in. if you really
want to append your headers, I'd consider pulling off the separator if it
exists, then adding it back in later.
--
Randomly Generated Tagline:
There are two things in life one should always remember:
1. Never tell everything you know.
Re: get_pristine_header in an array context
Posted by Robert Nicholson <ro...@elastica.com>.
secondly I see in the SA code that in order to get one per array
element you have to use split /^/ the documentation for
get_pristine_header doesn't appear to be correct.
secondly why must I remove the blank line myself?
$header = $mail->get_pristine_header;
# remove the last new line
$header =~ s/\s$//g;
just how reliable is this going to be?
my $header = $check_mail->get_pristine_header;
$header =~ s/\s$//g;
$header .= "\cJ";
my @header = split /^/m, $header;
my $body = $check_mail->get_pristine_body;
my @body = split /^/m, $body;
push @header, "X-Accept-Flag: Sender in Whitelist\n";
my @lines;
push @lines, @header, "\n", @body;
On Jul 19, 2006, at 12:09 AM, Robert Nicholson wrote:
> If i'm suppose to get back one header per element why do I get back
> the following?
>
> that is not one header per element is it?
>
> DB<3> x @header
> 0 "Status: R\cJX-Status: \cJX-Keywords:\cJFrom: \"Suphannika\" <ann
> \@elastica.com>\cJTo: \"Robert Nicholson\" <ro...@elastica.com>
> \cJSubject: want to AOL?\cJDate: Sat, 1 Jul 2000 06:31:21 -0700
> \cJMIME-Version: 1.0\cJContent-Type: text/html;\cJ\cIcharset=
> \"iso-8859-1\"\cJContent-Transfer-Encoding: quoted-printable\cJX-
> Priority: 3\cJX-MSMail-Priority: Normal\cJX-MimeOLE: Produced By
> Microsoft MimeOLE V6.00.2600.0000\cJ\cJ"