diff --git a/spam/index.cgi b/spam/index.cgi index aadc87b0c..8d72070bb 100755 --- a/spam/index.cgi +++ b/spam/index.cgi @@ -62,56 +62,7 @@ elsif ($dberr = &check_spamassassin_db()) { } else { # Work out if SpamAssassin is enabled in procmail - if ($warn_procmail && &foreign_check("procmail")) { - &foreign_require("procmail"); - $spam_enabled = 0; # Found call to spamassassin - $delivery_enabled = 0; # Found X-Spam: header rule - @pmrcs = &get_procmailrc(); - foreach $pmrc (@pmrcs) { - my @recipes = - &procmail::parse_procmail_file($pmrc); - my $isglobal = $pmrc eq - $config{'global_procmailrc'} || - $pmrc eq - $config{'procmailrc'} || - $pmrc eq - $procmail::procmailrc; - if (&find_spam_recipe(\@recipes)) { - $spam_enabled ||= 1; - } - if (&find_file_recipe(\@recipes)) { - if ($isglobal) { - # Enabled globally, and so - # cannot be changed by user - $delivery_enabled ||= -2; - } - else { - $delivery_enabled ||= 1; - } - } - if (&find_virtualmin_recipe(\@recipes)) { - # Controlled by Virtualmin - if ($isglobal && - &find_force_default_receipe( - \@recipes)) { - # User .procmailrc files are - # prevented - $spam_enabled ||= -2; - $delivery_enabled ||= -2; - } - else { - # Users can have a .procmailrc - $spam_enabled ||= -2; - $delivery_enabled ||= 1; - } - } - } - } - else { - # don't know, or checking disabled - $spam_enabled = -1; - $delivery_enabled = -1; - } + ($spam_enabled, $delivery_enabled) = &get_procmail_status(); if ($spam_enabled == 0) { if ($module_info{'usermin'}) { print &ui_alert_box(&text('index_warn_usermin', diff --git a/spam/spam-lib.pl b/spam/spam-lib.pl index cb8577a55..c899d1dc4 100755 --- a/spam/spam-lib.pl +++ b/spam/spam-lib.pl @@ -1142,5 +1142,56 @@ push(@rv, &find_value("loadplugin", $conf)); return @rv; } +# get_procmail_status() +# Returns flags indicating if spamassassin is called, and if delivery based +# on the headers it adds are enabled, based on the procmail config. +sub get_procmail_status +{ +if (!$warn_procmail || !&foreign_check("procmail")) { + # Don't know, or checking disabled + return (-1, -1); + } +&foreign_require("procmail"); +my $spam_enabled = 0; # Found call to spamassassin +my $delivery_enabled = 0; # Found X-Spam: header rule +my @pmrcs = &get_procmailrc(); +foreach my $pmrc (@pmrcs) { + my @recipes = &procmail::parse_procmail_file($pmrc); + my $isglobal = $pmrc eq $config{'global_procmailrc'} || + $pmrc eq $config{'procmailrc'} || + $pmrc eq $procmail::procmailrc; + if (&find_spam_recipe(\@recipes)) { + $spam_enabled ||= 1; + } + if (&find_file_recipe(\@recipes)) { + if ($isglobal) { + # Enabled globally, and so + # cannot be changed by user + $delivery_enabled ||= -2; + } + else { + $delivery_enabled ||= 1; + } + } + if (&find_virtualmin_recipe(\@recipes)) { + # Controlled by Virtualmin + if ($isglobal && + &find_force_default_receipe( + \@recipes)) { + # User .procmailrc files are + # prevented + $spam_enabled ||= -2; + $delivery_enabled ||= -2; + } + else { + # Users can have a .procmailrc + $spam_enabled ||= -2; + $delivery_enabled ||= 1; + } + } + } +return ($spam_enabled, $delivery_enabled); +} + 1;