Only show language and character set options where supported
authorJamie Cameron <jcameron@webmin.com>
Sun, 26 Sep 2010 23:54:21 +0000 (16:54 -0700)
committerJamie Cameron <jcameron@webmin.com>
Sun, 26 Sep 2010 23:54:21 +0000 (16:54 -0700)
spam/CHANGELOG
spam/edit_score.cgi
spam/save_score.cgi
spam/spam-lib.pl

index e4818b5..1d1316a 100644 (file)
@@ -20,3 +20,5 @@ Corrected the columns on the auto-whitelist page, to show the message count and
 Improved support for multiple SpamAssassin config files, which can be specified by links into the module from other modules like Virtualmin.
 Converted all pages to use the new Webmin UI library, for a more consistent look.
 Cleaned up the layout of all pages to improve formatted, in particular the Allowed and Denied Addresses page which now uses tabs.
+---- Changes since 1.520 ----
+Don't show language and character set spam classification options unless the TextCat plugin is enabled, as they won't work without it.
index f60726c..7de5fff 100755 (executable)
@@ -8,6 +8,7 @@ require './spam-lib.pl';
 &can_use_check("score");
 &ui_print_header($header_subtext, $text{'score_title'}, "");
 $conf = &get_config();
+@plugins = &list_spamassassin_plugins();
 
 print "$text{'score_desc'}<p>\n";
 &start_form("save_score.cgi", $text{'score_header'});
@@ -53,33 +54,37 @@ $received = &find("num_check_received", $conf);
 print &ui_table_row($text{'score_received'},
        &opt_field("num_check_received", $received, 5, 2));
 
-print &ui_table_hr();
+if (&indexof("Mail::SpamAssassin::Plugin::TextCat", @plugins) >= 0) {
+       print &ui_table_hr();
 
-# Acceptable languages
-@langs = &find_value("ok_languages", $conf);
-%langs = map { $_, 1 } split(/\s+/, join(" ", @langs));
-$lmode = !@langs ? 2 : $langs{'all'} ? 1 : 0;
-delete($langs{'all'});
-print &ui_table_row($text{'score_langs'},
-       &ui_radio("langs_def", $lmode,
-                 [ [ 2, $text{'default'}." (".$text{'score_langsall'}.")" ],
-                   [ 1, $text{'score_langsall'} ],
-                   [ 0, $text{'score_langssel'} ] ])."<br>\n".
-       &ui_select("langs", [ keys %langs ],
-                  [ &list_spamassassin_languages() ], 10, 1, 1));
+       # Acceptable languages
+       @langs = &find_value("ok_languages", $conf);
+       %langs = map { $_, 1 } split(/\s+/, join(" ", @langs));
+       $lmode = !@langs ? 2 : $langs{'all'} ? 1 : 0;
+       delete($langs{'all'});
+       print &ui_table_row($text{'score_langs'},
+               &ui_radio("langs_def", $lmode,
+                         [ [ 2, $text{'default'}.
+                                " (".$text{'score_langsall'}.")" ],
+                           [ 1, $text{'score_langsall'} ],
+                           [ 0, $text{'score_langssel'} ] ])."<br>\n".
+               &ui_select("langs", [ keys %langs ],
+                          [ &list_spamassassin_languages() ], 10, 1, 1));
 
-# Acceptable locales
-@locales = &find_value("ok_locales", $conf);
-%locales = map { $_, 1 } split(/\s+/, join(" ", @locales));
-$lmode = !@locales ? 2 : $locales{'all'} ? 1 : 0;
-delete($locales{'all'});
-print &ui_table_row($text{'score_locales'},
-       &ui_radio("locales_def", $lmode,
-                 [ [ 2, $text{'default'}." (".$text{'score_localesall'}.")" ],
-                   [ 1, $text{'score_localesall'} ],
-                   [ 0, $text{'score_localessel'} ] ])."<br>\n".
-       &ui_select("locales", [ keys %locales ],
-                  [ &list_spamassassin_locales() ], 5, 1, 1));
+       # Acceptable locales
+       @locales = &find_value("ok_locales", $conf);
+       %locales = map { $_, 1 } split(/\s+/, join(" ", @locales));
+       $lmode = !@locales ? 2 : $locales{'all'} ? 1 : 0;
+       delete($locales{'all'});
+       print &ui_table_row($text{'score_locales'},
+               &ui_radio("locales_def", $lmode,
+                         [ [ 2, $text{'default'}.
+                                " (".$text{'score_localesall'}.")" ],
+                           [ 1, $text{'score_localesall'} ],
+                           [ 0, $text{'score_localessel'} ] ])."<br>\n".
+               &ui_select("locales", [ keys %locales ],
+                          [ &list_spamassassin_locales() ], 5, 1, 1));
+       }
 
 &end_form(undef, $text{'save'});
 &ui_print_footer($redirect_url, $text{'index_return'});
index fff9135..7a8af71 100755 (executable)
@@ -21,26 +21,30 @@ $hits_param = &version_atleast(3.0) ? "required_score" : "required_hits";
 &parse_opt($conf, "rbl_timeout", \&timeout_check);
 &parse_opt($conf, "num_check_received", \&received_check);
 
-if ($in{'langs_def'} == 2) {
-       &save_directives($conf, "ok_languages", [ ], 1);
-       }
-elsif ($in{'langs_def'} == 1) {
-       &save_directives($conf, "ok_languages", [ "all" ], 1);
-       }
-else {
-       &save_directives($conf, "ok_languages",
-                        [ join(" ", split(/\0/, $in{'langs'})) ], 1);
+if (defined($in{'langs_def'})) {
+       if ($in{'langs_def'} == 2) {
+               &save_directives($conf, "ok_languages", [ ], 1);
+               }
+       elsif ($in{'langs_def'} == 1) {
+               &save_directives($conf, "ok_languages", [ "all" ], 1);
+               }
+       else {
+               &save_directives($conf, "ok_languages",
+                                [ join(" ", split(/\0/, $in{'langs'})) ], 1);
+               }
        }
 
-if ($in{'locales_def'} == 2) {
-       &save_directives($conf, "ok_locales", [ ], 1);
-       }
-elsif ($in{'locales_def'} == 1) {
-       &save_directives($conf, "ok_locales", [ "all" ], 1);
-       }
-else {
-       &save_directives($conf, "ok_locales",
-                        [ join(" ", split(/\0/, $in{'locales'})) ], 1);
+if (defined($in{'locales_def'})) {
+       if ($in{'locales_def'} == 2) {
+               &save_directives($conf, "ok_locales", [ ], 1);
+               }
+       elsif ($in{'locales_def'} == 1) {
+               &save_directives($conf, "ok_locales", [ "all" ], 1);
+               }
+       else {
+               &save_directives($conf, "ok_locales",
+                                [ join(" ", split(/\0/, $in{'locales'})) ], 1);
+               }
        }
 
 &flush_file_lines();
index 695297e..e89f1ca 100755 (executable)
@@ -104,8 +104,8 @@ if ($include_config_files || $forglobal) {
                closedir(DIR);
                local $f;
                foreach $f (@files) {
-                       if ($f =~ /\.cf$/) {
-                               local $add = &get_config("$file/$f");
+                       if ($f =~ /\.(cf|pre)$/) {
+                               local $add = &get_config("$file/$f",$forglobal);
                                map { $_->{'index'} += scalar(@rv) } @$add;
                                push(@rv, @$add);
                                }
@@ -1086,5 +1086,19 @@ close(LANGS);
 return @rv;
 }
 
+# list_spamassassin_plugins()
+# Returns a list of plugins enabled, both globally and for this user
+sub list_spamassassin_plugins
+{
+my @rv;
+if ($config{'global_cf'}) {
+       my $gconf = &get_config($config{'global_cf'}, 1);
+       push(@rv, &find_value("loadplugin", $gconf));
+       }
+my $conf = &get_config();
+push(@rv, &find_value("loadplugin", $conf));
+return @rv;
+}
+
 1;