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.
pgpZ9K2TCOPt6.pgp
Description: PGP signature