RE: SpamAssassin integration missing Received: headers
"Carlos Perez" <[email protected]> Tue, 15 Jun 2004 09:48:32 -0600
| Newsgroups | gmane.comp.lang.perl.modules.mail-box,gmane.spam.detected |
|---|---|
| Message-ID | <[email protected]> |
Mark,
I found there was a bug in my previous code-- SpamAssassin apparently calls
get_header expecting an array or scalar, based on looking at NoMailAudit.pm
So here is the latest version (if I find additional bugs, I will e-mail you
off-line).
Thx, Carlos
--- /usr/lib/perl5/site_perl/5.8.0/Mail/Message/Wrapper/SpamAssassin.pm
2004-05-16 07:43:16.000000000 -0600
+++ SpamAssassin.pm 2004-06-14 21:42:55.000000000 -0600
@@ -32,8 +32,39 @@
sub get_header($)
{ my ($self, $name) = @_;
- my $field = $self->get_mail_object->head->get($name);
- defined $field ? $field->unfoldedBody : undef;
+ # Use array context, not scalar.
+ my @fields = $self->get_mail_object->head->get($name);
+ my @lines = ();
+ if (@fields) {
+ foreach my $field (@fields) {
+ my $fieldbody = $field->unfoldedBody;
+ $fieldbody =~ s/\n/ /g; # convert newlines to spaces
+ $fieldbody = _trim($fieldbody); # clean up whitespace
+ push(@lines, $fieldbody);
+ }
+ }
+ if (wantarray) {
+ # array
+ return @lines;
+ } else {
+ # scalar
+ if (@lines) {
+ return $lines[0]; # return only first element
+ } else {
+ return undef;
+ }
+ }
+}
+
+# Trim trailing and leading whitespace.
+# See 1.14 in Perl Cookbook.
+sub _trim {
+ my @out = @_;
+ for (@out) {
+ s/^\s+//;
+ s/\s+$//;
+ }
+ return wantarray ? @out : $out[0];
}
#------------------------------------------