Skip to content

Instantly share code, notes, and snippets.

@andyjones
Last active August 29, 2015 14:02
Show Gist options
  • Save andyjones/0d53aa404e2336bdb514 to your computer and use it in GitHub Desktop.
Save andyjones/0d53aa404e2336bdb514 to your computer and use it in GitHub Desktop.
Mail::SpamAssassin patch to install into a local::lib. Install AAAA::Mail::SpamAssassin first. Works with v 3.2.5
diff --git a/Makefile.PL b/Makefile.PL
index e47a76d..c7c4dcb 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -219,6 +219,8 @@ my %makefile = (
'Sys::Hostname' => 0,
'Time::Local' => 0,
'Errno' => 0,
+ 'Net::IP' => 0,
+ 'NetAddr::IP' => 0,
},
'dist' => {
diff --git a/README b/README
index 0fe065c..94f73a3 100644
--- a/README
+++ b/README
@@ -1,3 +1,27 @@
+ ===========================================
+ *** Unofficial fork of Mail::SpamAssassin 3.2.5 ***
+ ===========================================
+
+Some SpamAssassin tests run under taint mode and fail if they
+are run in a local::lib.
+
+This git repo contains a bunch of commits to fix those tests.
+
+[![Build Status](http://private.broadbean.net:40801/buildStatus/icon?job=pinto-mail-spam-assassin)](http://private.broadbean.net:40801/job/pinto-mail-spam-assassin/)
+
+I use this repo to generate a patch:
+
+ * `git diff bcfae7d17af1cafedab5528af7ec5d2704d0602d > my.patch`
+
+I host the patch using github's gists. Jenkins downloads the patch,
+applies it to Mail::SpamAssassin, builds the distribution and
+pushes it to our Pinto repository.
+
+You may also have trouble installing dependencies. Installing
+AAAA::Mail::SpamAssassin helps considerably.
+
+ ***
+
Welcome to SpamAssassin!
------------------------
diff --git a/lib/Mail/SpamAssassin/Dns.pm b/lib/Mail/SpamAssassin/Dns.pm
index d4b6297..9c7a38a 100644
--- a/lib/Mail/SpamAssassin/Dns.pm
+++ b/lib/Mail/SpamAssassin/Dns.pm
@@ -759,12 +759,11 @@ sub enter_helper_run_mode {
dbg("info: entering helper-app run mode");
$self->{old_slash} = $/; # Razor pollutes this
%{$self->{old_env}} = ();
- if ( defined %ENV ) {
- # undefined values in %ENV can result due to autovivification elsewhere,
- # this prevents later possible warnings when we restore %ENV
- while (my ($key, $value) = each %ENV) {
- $self->{old_env}->{$key} = $value if defined $value;
- }
+
+ # undefined values in %ENV can result due to autovivification elsewhere,
+ # this prevents later possible warnings when we restore %ENV
+ while (my ($key, $value) = each %ENV) {
+ $self->{old_env}->{$key} = $value if defined $value;
}
Mail::SpamAssassin::Util::clean_path_in_taint_mode();
diff --git a/lib/Mail/SpamAssassin/Plugin/Check.pm b/lib/Mail/SpamAssassin/Plugin/Check.pm
index f7f69bc..07742ff 100644
--- a/lib/Mail/SpamAssassin/Plugin/Check.pm
+++ b/lib/Mail/SpamAssassin/Plugin/Check.pm
@@ -234,11 +234,7 @@ sub run_generic_tests {
my $methodname = $package_name."::_".$ruletype."_tests_".$clean_priority;
if (defined &{$methodname} && !$doing_user_rules) {
- no strict "refs";
-run_compiled_method:
- $methodname->($pms, @{$opts{args}});
- use strict "refs";
- return;
+ return $self->run_compiled_method($methodname, $pms, $opts{args});
}
# build up the eval string...
@@ -298,10 +294,18 @@ EOT
}
else {
dbg("rules: compiled ".$ruletype." tests");
- goto run_compiled_method;
+ return $self->run_compiled_method($methodname, $pms, $opts{args});
}
}
+sub run_compiled_method {
+ my ($self, $method, $pms, $args) = @_;
+ no strict "refs";
+ $method->($pms, @$args);
+ use strict "refs";
+ return;
+}
+
sub add_evalstr {
my ($self, $str) = @_;
$self->{evalstr} .= $str;
diff --git a/lib/Mail/SpamAssassin/Plugin/MIMEEval.pm b/lib/Mail/SpamAssassin/Plugin/MIMEEval.pm
index 6ef249c..59ae662 100644
--- a/lib/Mail/SpamAssassin/Plugin/MIMEEval.pm
+++ b/lib/Mail/SpamAssassin/Plugin/MIMEEval.pm
@@ -496,7 +496,7 @@ sub _check_base64_length {
# perhaps just limit to test, and image?
next if ($ctype eq 'application/ics');
- my $cte = lc $p->get_header('content-transfer-encoding') || '';
+ my $cte = lc($p->get_header('content-transfer-encoding') || '');
next if ($cte !~ /^base64$/);
foreach my $l ( @{$p->raw()} ) {
my $len = length $l;
diff --git a/spamd/spamd.raw b/spamd/spamd.raw
index e67d1f1..05943c4 100755
--- a/spamd/spamd.raw
+++ b/spamd/spamd.raw
@@ -22,14 +22,44 @@ my $LOCAL_RULES_DIR = '@@LOCAL_RULES_DIR@@'; # substituted at 'make' time
my $LOCAL_STATE_DIR = '@@LOCAL_STATE_DIR@@'; # substituted at 'make' time
use lib '@@INSTALLSITELIB@@'; # substituted at 'make' time
+sub _untaint_scalar {
+ local ($_) = @_;
+ return undef unless defined;
+
+ /^(.*)$/s;
+ return $1;
+}
+
+sub load_local_lib {
+ my $local_lib_root = shift;
+
+ # see if local::lib has been installed into system perl
+ if ( eval { require local::lib; } ) {
+ return;
+ }
+
+ # otherwise they could be using a perlbrew lib, we need to find it!
+ unshift @INC, "$local_lib_root/lib/perl5";
+ return require local::lib;
+}
+
# added by jm for use inside the distro
# This is disabled during the "make install" process.
BEGIN {
- if ( -e '../blib/lib/Mail/SpamAssassin.pm' ) { # REMOVEFORINST
- unshift ( @INC, '../blib/lib' ); # REMOVEFORINST
- } else { # REMOVEFORINST
- unshift ( @INC, '../lib' ); # REMOVEFORINST
- } # REMOVEFORINST
+ if ( -e '../blib/lib/Mail/SpamAssassin.pm' ) { # REMOVEFORINST
+ unshift ( @INC, '../blib/lib' ); # REMOVEFORINST
+ } else { # REMOVEFORINST
+ unshift ( @INC, '../lib' ); # REMOVEFORINST
+ } # REMOVEFORINST
+ # REMOVEFORINST
+ my $local_lib = _untaint_scalar( # REMOVEFORINST
+ $ENV{PERL_LOCAL_LIB_ROOT} || '', # REMOVEFORINST
+ ); # REMOVEFORINST
+ if ( $local_lib ) { # REMOVEFORINST
+ delete $ENV{PERL_LOCAL_LIB_ROOT}; # REMOVEFORINST
+ load_local_lib($local_lib); # REMOVEFORINST
+ local::lib->new->activate($local_lib)->setup_local_lib; # REMOVEFORINST
+ } # REMOVEFORINST
}
use strict;
diff --git a/t/SATest.pm b/t/SATest.pm
index 77d0aa8..9c5186d 100644
--- a/t/SATest.pm
+++ b/t/SATest.pm
@@ -52,6 +52,14 @@ sub sa_t_init {
$perl_cmd .= " -T" if !defined($ENV{'TEST_PERL_TAINT'}) or $ENV{'TEST_PERL_TAINT'} ne 'no';
$perl_cmd .= " -w" if !defined($ENV{'TEST_PERL_WARN'}) or $ENV{'TEST_PERL_WARN'} ne 'no';
+ # ensure we retain the perl5lib eg. when installing into local::lib
+ if ( $ENV{PERL_LOCAL_LIB_ROOT} ) {
+ my $perl5lib = join ' ',
+ map { "-I$_" }
+ @INC;
+ $perl_cmd .= " $perl5lib";
+ }
+
$scr = $ENV{'SCRIPT'};
$scr ||= "$perl_cmd ../spamassassin.raw";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment