Move check for procmail into a separate function to avoid bloating index.cgi

This commit is contained in:
Jamie Cameron
2024-12-18 09:50:45 -08:00
parent 59e97be96c
commit b82c01c4ff
2 changed files with 52 additions and 50 deletions

View File

@ -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',

View File

@ -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;