From e53ff1b4f2b5a71b3f24c391754b399ce082b3cb Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Thu, 26 Jul 2007 05:31:35 +0000 Subject: [PATCH] Show global spam delivery, if configured --- filter/CHANGELOG | 2 ++ filter/config | 1 + filter/config.info | 1 + filter/filter-lib.pl | 48 ++++++++++++++++++++++++++++++++++++++++++-- filter/index.cgi | 40 ++++++++++++++++++++++++++++++++++-- filter/lang/en | 4 +++- 6 files changed, 91 insertions(+), 5 deletions(-) diff --git a/filter/CHANGELOG b/filter/CHANGELOG index 86e13b463..d3b73e280 100644 --- a/filter/CHANGELOG +++ b/filter/CHANGELOG @@ -7,3 +7,5 @@ Added an option to set the date range for which autoreplies are sent. ---- Changes since 1.290 ---- Added a simple page for setting up an email autoresponder. Display a warning if /etc/procmailrc is setup to always deliver to the inbox, which would prevent user-defined filters from working. +If email classified as spam is delivered to some folder by a global Procmail configuration (either in /etc/procmailrc or a Virtualmin per-domain setting), display this on the list of filters. +Changed the module name to Filter and Forward Mail. diff --git a/filter/config b/filter/config index 85cb76d9b..22ac27e68 100644 --- a/filter/config +++ b/filter/config @@ -1,3 +1,4 @@ virtualmin_spam=/etc/webmin/virtual-server/lookup-domain.pl warn_procmail=1 alias_files=/etc/aliases /etc/postfix/aliases /etc/mail/aliases +virtualmin_config=/etc/webmin/virtual-server diff --git a/filter/config.info b/filter/config.info index 060df215f..ff33eda98 100644 --- a/filter/config.info +++ b/filter/config.info @@ -1,3 +1,4 @@ virtualmin_spam=Full path to Virtualmin spam user lookup program,3,Not installed,40 +virtualmin_config=Full path to Virtualmin config directory,3,Not installed warn_procmail=Show warning if Procmail is not installed?,1,1-Yes,0-No alias_files=Full path to global alias files,9,40,3,\t diff --git a/filter/filter-lib.pl b/filter/filter-lib.pl index fc794ae91..f48e5e695 100644 --- a/filter/filter-lib.pl +++ b/filter/filter-lib.pl @@ -12,9 +12,11 @@ if (&get_product_name() eq 'usermin') { # enabled before switching away from root if ($config{'virtualmin_spam'} && -x $config{'virtualmin_spam'}) { local $out = `$config{'virtualmin_spam'} $remote_user /dev/null`; + $out =~ s/\r|\n//g; if ($out =~ /\d/) { # Yes - we can show the user this $global_spamassassin = 2; + $virtualmin_domain_id = $out; } } @@ -256,12 +258,12 @@ local ($filter1, $filter2) = @_; &procmail::swap_recipes($filter1->{'recipe'}, $filter2->{'recipe'}); } -# file_to_folder(file, &folders, [homedir]) +# file_to_folder(file, &folders, [homedir], [fake-if-missing]) # Given a path like mail/foo or ~/mail/foo or $HOME/mail/foo or # /home/bob/mail/foo, returns the folder object for it. sub file_to_folder { -local ($file, $folders, $home) = @_; +local ($file, $folders, $home, $fake) = @_; $home ||= $remote_user_info[7]; $file =~ s/^\~/$home/; $file =~ s/^\$HOME/$home/; @@ -270,6 +272,21 @@ if ($file !~ /^\//) { } local ($folder) = grep { $_->{'file'} eq $file || $_->{'file'}.'/' eq $file } @$folders; +if (!$folder && $fake) { + # Create a fake folder object to match + $folder = { 'file' => $file, + 'type' => 1, + 'fake' => 1 }; + if ($folder->{'file'} =~ s/\/$//) { + $folder->{'type'} = 2; + } + $folder->{'file'} =~ /\/\.?([^\/]+)$/; + $folder->{'name'} = $1; + if (lc($folder->{'name'}) eq 'spam') { + $folder->{'spam'} = 1; + $folder->{'name'} = "Spam"; + } + } return $folder; } @@ -283,6 +300,33 @@ local @recipes = &procmail::parse_procmail_file( return &spam::find_spam_recipe(\@recipes) ? 1 : 0; } +# get_global_spam_path() +# Returns the global path to which spam is delivered, typically by a +# Virtualmin per-domain procmail file +sub get_global_spam_path +{ +if ($virtualmin_domain_id) { + # Read the Virtualmin procmailrc for the domain + local $vmpmrc = "$config{'virtualmin_config'}/procmail/". + $virtualmin_domain_id; + local @vmrecipes = &procmail::parse_procmail_file($vmpmrc); + local $spamrec = &spam::find_file_recipe(\@vmrecipes); + if ($spamrec) { + return $spamrec->{'action'}; + } + } +# Also check the global /etc/procmailrc +local @recipes = &procmail::parse_procmail_file( + $spam::config{'global_procmailrc'}); +local $spamrec = &spam::find_file_recipe(\@recipes); +if ($spamrec) { + return $spamrec->{'action'}; + } +else { + return undef; + } +} + sub has_spamassassin { return &foreign_installed("spam"); diff --git a/filter/index.cgi b/filter/index.cgi index 11273003d..17388ec98 100755 --- a/filter/index.cgi +++ b/filter/index.cgi @@ -58,12 +58,30 @@ if (@filters) { @filters > 1 ? ( $text{'index_move'} ) : ( ), ], 100, 0, \@tds); - # Add a magic non-editable row for global spamassassin run + # Add a magic non-editable row(s) for global spamassassin run if (&get_global_spamassassin()) { print &ui_columns_row( [ "", $text{'index_calways'}, $text{'index_aspam'}, @filters > 1 ? ( "" ) : ( ) ], \@tds); + $spamfile = &get_global_spam_path(); + if ($spamfile) { + $folder = &file_to_folder($spamfile, \@folders, 0, 1); + $id = &mailbox::folder_name($folder); + if ($folder->{'fake'}) { + $sflink = "$folder->{'name'}"; + } + else { + $sflink = + "". + "$folder->{'name'}"; + } + print &ui_columns_row( + [ "", $text{'index_cspam'}, + &text('index_afolder', $sflink), + @filters > 1 ? ( "" ) : ( ) ], + \@tds); + } } # Show editable rows @@ -120,7 +138,25 @@ else { print "$text{'index_none2'}

\n"; } elsif (&get_global_spamassassin()) { - print "$text{'index_none3'}

\n"; + $spamfile = &get_global_spam_path(); + if ($spamfile) { + $folder = &file_to_folder($spamfile, \@folders, 0, 1); + print ""; + $id = &mailbox::folder_name($folder); + if ($folder->{'fake'}) { + print &text('index_none4', + "$folder->{'name'}"); + } + else { + print &text('index_none4', + "". + "$folder->{'name'}"); + } + print "

\n"; + } + else { + print "$text{'index_none3'}

\n"; + } } else { print "$text{'index_none'}

\n"; diff --git a/filter/lang/en b/filter/lang/en index 1104174ec..4557a2eec 100644 --- a/filter/lang/en +++ b/filter/lang/en @@ -4,7 +4,9 @@ index_action=Filter action index_move=Move index_none=You do not have any mail filters defined yet. All email will be delivered to your Inbox. index_none2=None of your existing Procmail rules are simple enough to display here. -index_none3=You do not have any mail filters defined yet. All email will be delivered to your Inbox, after spam filtering. +index_none3=You do not have any mail filters defined yet. All email will be delivered to your Inbox, after spam classification. +index_none4=You do not have any mail filters defined yet. All email will be deliverted to your Inbox, except spam which will be sent to the folder $1. +index_none5=You do not have any mail filters defined yet. All email will be deliverted to your Inbox, except spam which will be sent to the file $1. index_add=Add a new email filter. index_addauto=Quick automatic reply setup. index_cspam=Email is spam