=head1 NAME
HeadersToBody - Add header content to message body.
=head1 SYNOPSIS
loadplugin Mail::SpamAssassin::Plugin::HeadersToBody /usr/local/etc/mail/spamassassin.plugins/HeadersToBody.pm
header_to_body From
header_to_body X-HTTP-UserAgent
header_to_body Organization
=head1 DESCRIPTION
This modules copies the (decoded) content of specified headers to the
decoded/rendered body of a the message object.
=head1 CONFIGURATION
=head2 Options
=over
=item header_to_body
Specifies one or more headers (separated by ",", ";" or space) that should
be copied to a new body part.
The contents of the specified headers (if present) is copied decoded to a
text/plain part.
=back
=cut
package Mail::SpamAssassin::Plugin::HeadersToBody;
# $Id: HeadersToBody.pm,v 1.3 2008/06/16 12:36:26 jonas Exp $
use strict;
use Mail::SpamAssassin::Message::Node;
use base 'Mail::SpamAssassin::Plugin';
sub dbg {
my $msg = shift;
Mail::SpamAssassin::Plugin::dbg(sprintf("h2b: $msg",@_));
return 1;
}
sub new {
my ($class,$mailsa) = @_;
$class = ref($class) || $class;
my $self = $class->SUPER::new($mailsa);
bless($self,$class);
return $self;
}
sub parse_config {
my ($self,$pars) = @_;
return 0 unless ($pars->{key} eq 'header_to_body' && defined($pars->{value}) && $pars->{value} !~ /^\s*$/);
dbg('config %s %s',$pars->{key},$pars->{value});
foreach my $hdr (split(/[\s,;]+/,$pars->{value})) {
$hdr =~ s/:$//;
$hdr =~ s/[^-_:a-zA-Z0-9]+//g;
next if ($hdr eq '');
$self->{main}->{conf}->{header_to_body}->{$hdr} = 1;
}
$self->inhibit_further_callbacks();
return 1;
}
sub extract_metadata {
my ($self,$opt) = @_;
#my $pms = $opt->{permsgstatus};
#return 1 unless ($pms);
#my $msg = $pms->get_message;
my $msg = $opt->{msg};
return 1 unless ($msg);
return 1 unless ($self->{main}->{conf}->{header_to_body});
my @txt = ();
foreach my $hdr (keys %{$self->{main}->{conf}->{header_to_body}}) {
foreach my $l ($msg->header($hdr)) {
$l =~ s/^[\s\r\n]+//;
$l =~ s/[\s\r\n]+$//;
next unless ($l);
dbg('%s: "%s"',$hdr,$l);
push @txt, "$l\n";
}
}
return 1 unless (@txt);
dbg('add %u lines',scalar @txt);
$msg->get_decoded_body_text_array() unless (defined($msg->{text_decoded}));
push @{$msg->{text_decoded}}, @txt if (defined($msg->{text_decoded}));
$msg->get_rendered_body_text_array() unless (defined($msg->{text_rendered}));
push @{$msg->{text_rendered}}, @txt if (defined($msg->{text_rendered}));
$msg->get_visible_rendered_body_text_array() unless (defined($msg->{text_visible_rendered}));
push @{$msg->{text_visible_rendered}}, @txt if (defined($msg->{text_visible_rendered}));
#$msg->get_invisible_rendered_body_text_array() unless (defined($msg->{text_invisible_rendered}));
#push @{$self->{text_invisible_rendered}}, @txt if (defined($self->{text_invisible_rendered}));
#foreach my $l (@{$msg->{text_decoded}}) { dbg('D %s',$l); }
#foreach my $l (@{$msg->{text_rendered}}) { dbg('R %s',$l); }
#foreach my $l (@{$msg->{text_visible_rendered}}) { dbg('V %s',$l); }
return 1;
}
1;
(2008-06-16)