Mailing List Archive

svn commit: r179670 - /spamassassin/trunk/masses/mass-check
Author: duncf
Date: Thu Jun 2 15:54:21 2005
New Revision: 179670

URL: http://svn.apache.org/viewcvs?rev=179670&view=rev
Log:
Add a --lint option to mass-check so that it dies if rules are
invalid. This could perhaps be changed to something like --lint=warn
or --lint=die.
Also, do not require rules.pl unless we are using --reuse.

Modified:
spamassassin/trunk/masses/mass-check

Modified: spamassassin/trunk/masses/mass-check
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/masses/mass-check?rev=179670&r1=179669&r2=179670&view=diff
==============================================================================
--- spamassassin/trunk/masses/mass-check (original)
+++ spamassassin/trunk/masses/mass-check Thu Jun 2 15:54:21 2005
@@ -39,6 +39,7 @@
--deencap=RE Extract SpamAssassin-encapsulated spam mails only if they
were encapsulated by servers matching the regexp RE
(default = extract all SpamAssassin-encapsulated mails)
+ --lint check rules for syntax before running

log options
-o write all logs to stdout
@@ -88,7 +89,7 @@
$opt_mid $opt_net $opt_nosort $opt_progress $opt_showdots
$opt_spamlog $opt_tail $opt_rules $opt_restart $opt_loguris
$opt_logmem $opt_after $opt_before $opt_rewrite $opt_deencap
- $opt_learn $opt_reuse
+ $opt_learn $opt_reuse $opt_lint
$total_messages $statusevery
%reuse);

@@ -114,17 +115,11 @@
$opt_spamlog = "spam.log";
$opt_learn = 0;

-# rules.pl is for the --reuse option, score set doesn't matter
-if (! -f "$FindBin::Bin/tmp/rules.pl") {
- system("cd $FindBin::Bin; perl parse-rules-for-masses -d $opt_c");
-}
-require "rules.pl";
-
GetOptions("c=s", "p=s", "f=s", "j=i", "n", "o", "all", "bayes", "debug:s",
"hamlog=s", "head=i", "loghits", "mh", "mid", "ms", "net",
"progress", "rewrite:s", "showdots", "spamlog=s", "tail=i",
"rules=s", "restart=i", "after=s", "before=s", "loguris",
- "deencap=s", "logmem", "learn=i", "reuse",
+ "deencap=s", "logmem", "learn=i", "reuse", "lint",
"dir" => sub { $opt_format = "dir"; },
"file" => sub { $opt_format = "file"; },
"mbox" => sub { $opt_format = "mbox"; },
@@ -132,6 +127,13 @@
"help" => sub { usage(0); },
'<>' => \&target) or usage(1);

+# rules.pl is for the --reuse option, score set doesn't matter
+if ($opt_reuse && ! -f "$FindBin::Bin/tmp/rules.pl") {
+ system("cd $FindBin::Bin; perl parse-rules-for-masses -d $opt_c");
+}
+
+require "rules.pl" if $opt_reuse;
+
# test messages for the mass-check
my @targets;
if ($opt_f) {
@@ -160,6 +162,39 @@
}
close(PREFS);
}
+
+# --lint
+# In theory we could probably use the same spamtest object as below,
+# but since it's probably not expecting that, and we don't want
+# strange things happening, create a local object.
+
+if ($opt_lint) {
+
+ my $spamlint = new Mail::SpamAssassin ({
+ 'debug' => $opt_debug,
+ 'rules_filename' => $opt_c,
+ 'userprefs_filename' => $user_prefs,
+ 'site_rules_filename' => "$opt_p/local.cf",
+ 'userstate_dir' => "$opt_p",
+ 'save_pattern_hits' => $opt_loghits,
+ 'dont_copy_prefs' => 1,
+ 'local_tests_only' => $opt_net ? 0 : 1,
+ 'only_these_rules' => $opt_rules,
+ 'ignore_safety_expire_timeout' => 1,
+ PREFIX => '',
+ DEF_RULES_DIR => $opt_c,
+ LOCAL_RULES_DIR => '',
+ });
+
+
+ $spamlint->debug_diagnostics();
+ my $res = $spamlint->lint_rules();
+ $spamlint->finish();
+ warn "lint: $res issues detected, please rerun with debug enabled for more information\n" if ($res);
+ exit 1 if $res;
+}
+
+

$spamtest = new Mail::SpamAssassin ({
'debug' => $opt_debug,