Changeset 977

Show
Ignore:
Timestamp:
03/29/2006 09:53:27 PM (3 years ago)
Author:
rjl
Message:

Reworked Perl scripts to use /etc/maia.conf for configuration

Location:
trunk/scripts
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/scripts/configtest.pl

    r971 r977  
    1 #!/usr/bin/perl -w 
     1#!/usr/bin/perl 
    22 
    33# $Id$ 
     
    7575######################################################################## 
    7676 
    77     use strict; 
    7877    use DBI; 
    7978 
    80     # CONFIGURE THIS: Location of your database.cfg file 
    81     my $cfg = "/var/amavisd/maia/scripts/database.cfg"; 
    82  
    83 ######################################################################## 
    84 # End of user-configurable portion.  There should be no need to modify # 
    85 # anything below this point.                                           # 
    86 ######################################################################## 
    87  
    88     # Retrieve the string value associated with a key in the database.cfg file. 
    89     sub get_string_key($$) 
    90     { 
    91        my ($file, $key) = @_; 
    92  
    93        if ($file =~ /\n[ \t]*$key[ \t]*=[ \t]*\"(.*)\"/) { 
    94           return ($1); 
    95        } else { 
    96           die ("Maia: [get_string_key] Unable to find $key value in $file\n"); 
    97        } 
    98     } 
    99  
    100  
    101     # Returns the version number of the named module, or undef if the module 
    102     # is not installed. 
    103     sub get_module_version($) { 
    104         my($module) = @_; 
    105  
    106         my $version = `$^X -m$module -e 'print \$${module}::VERSION' 2>/dev/null`; 
    107         $version =~ s/^\s*(.*?)\s*$/$1/; 
    108         return ($version || undef); 
    109     } 
    110  
    111  
    112     # Prints a formatted text message. 
    113     sub print_message($$$) { 
    114         my($module, $version, $message) = @_; 
    115  
    116         printf("%-20s : %8s : %s\n", $module, $version, $message); 
    117     } 
    118  
    119     # Returns true if a string is a valid integer or floating point value. 
    120     sub is_numeric($) { 
    121         my ($string) = @_; 
    122  
    123         return ($string =~ /^([0-9]*\.*[0-9]+)$/); 
    124     } 
    125  
    126     # Convert standard M.mmmttt version numbers to M.m.t format  
    127     # for display purposes. 
    128     sub decode_version_string($) { 
    129         my ($version) = @_; 
    130         my ($major, $minor, $trivial); 
    131  
    132         if ($version =~ /^([0-9]+)\.([0-9]{3})([0-9]{3})$/) { 
    133            $major = int($1); 
    134            $minor = int($2); 
    135            $trivial = int($3); 
    136            return ($major . "." . $minor . "." . $trivial); 
    137         } else { 
    138            return ($version); 
    139         } 
    140     } 
    141  
    142  
    143  
     79    # prototypes 
     80    sub get_module_version($); 
     81    sub print_message($$$); 
     82    sub is_numeric($); 
     83    sub decode_version_string($); 
     84 
     85    # name of this script 
     86    my $script_name = "configtest"; 
     87 
     88    # read configuration file (/etc/maia.conf) 
     89    my $config_file = "/etc/maia.conf"; 
     90    unless (my $rv = do $config_file) { 
     91        die("Maia: [$script_name] Couldn't parse $config_file: $@\n") if $@; 
     92        die("Maia: [$script_name] Couldn't open $config_file\n") if (!defined($rv) || !$rv); 
     93    }; 
    14494 
    14595    my @components = ( 
     
    329279    if ($have_dbi && ($have_dbd_mysql || $have_dbd_pg)) { 
    330280 
    331         # Read the database configuration file into memory once. 
    332         open CONFIGFILE, "<" . $cfg 
    333             or die ("Database DSN test    : SKIPPED (unable to open $cfg)\n\n"); 
    334         my($config) = ""; 
    335         my $line; 
    336         while ($line = <CONFIGFILE>) { 
    337             $config .= $line; 
    338         } 
    339         close CONFIGFILE; 
    340  
    341         # Connect to the database or die trying. 
    342         my $dsn = get_string_key($config, "dsn"); 
    343         my $username = get_string_key($config, "username"); 
    344         my $password = get_string_key($config, "password"); 
    345         my $dbh = DBI->connect($dsn, $username, $password) 
    346                        or die("Database DSN test    : FAILED (can't connect to database)\n\n"); 
     281        my $dbh; 
     282 
     283        # database configuration 
     284        if (defined($dsn) && defined($username) && defined($password)) { 
     285            $dbh = DBI->connect($dsn, $username, $password) 
     286                or die("Database DSN test    : FAILED " . 
     287                       "(verify \$dsn, \$username, and \$password in $config_file)\n\n");                        
     288        } else { 
     289            die("Database DSN test    : FAILED " . 
     290                "(missing \$dsn, \$username, or \$password in $config_file)\n\n"); 
     291        } 
    347292 
    348293        print("Database DSN test    : PASSED\n"); 
     294 
     295        # Disconnect from the database 
     296        $dbh->disconnect; 
    349297 
    350298    } else { 
     
    355303 
    356304    exit; 
     305 
     306 
     307    # Returns the version number of the named module, or undef if the module 
     308    # is not installed. 
     309    sub get_module_version($) { 
     310        my($module) = @_; 
     311 
     312        my $version = `$^X -m$module -e 'print \$${module}::VERSION' 2>/dev/null`; 
     313        $version =~ s/^\s*(.*?)\s*$/$1/; 
     314        return ($version || undef); 
     315    } 
     316 
     317 
     318    # Prints a formatted text message. 
     319    sub print_message($$$) { 
     320        my($module, $version, $message) = @_; 
     321 
     322        printf("%-20s : %8s : %s\n", $module, $version, $message); 
     323    } 
     324 
     325    # Returns true if a string is a valid integer or floating point value. 
     326    sub is_numeric($) { 
     327        my ($string) = @_; 
     328 
     329        return ($string =~ /^([0-9]*\.*[0-9]+)$/); 
     330    } 
     331 
     332    # Convert standard M.mmmttt version numbers to M.m.t format  
     333    # for display purposes. 
     334    sub decode_version_string($) { 
     335        my ($version) = @_; 
     336        my ($major, $minor, $trivial); 
     337 
     338        if ($version =~ /^([0-9]+)\.([0-9]{3})([0-9]{3})$/) { 
     339           $major = int($1); 
     340           $minor = int($2); 
     341           $trivial = int($3); 
     342           return ($major . "." . $minor . "." . $trivial); 
     343        } else { 
     344           return ($version); 
     345        } 
     346    } 
  • trunk/scripts/expire-quarantine-cache.pl

    r968 r977  
    1 #!/usr/bin/perl -T 
     1#!/usr/bin/perl 
    22 
    33# $Id$ 
     
    7575######################################################################## 
    7676 
    77     use strict; 
    7877    use DBI; 
    7978 
    80     # CONFIGURE THIS: Location of your database.cfg file 
    81     my $cfg = "/var/amavisd/maia/scripts/database.cfg"; 
    82  
    83 ######################################################################## 
    84 # End of user-configurable portion.  There should be no need to modify # 
    85 # anything below this point.                                           # 
    86 ######################################################################## 
    87  
    88     # Retrieve the string value associated with a key in the database.cfg file. 
    89     sub get_string_key($$) 
    90     { 
    91        my ($file, $key) = @_; 
    92  
    93        if ($file =~ /\n[ \t]*$key[ \t]*=[ \t]*\"(.*)\"/) { 
    94           return ($1); 
    95        } else { 
    96           die ("Maia: [get_string_key] Unable to find $key value in $file\n"); 
    97        } 
    98     } 
    99  
    100  
    101     # Determine the database type: "mysql", "mysqli", or "pg" 
     79    # prototypes 
     80    sub get_db_type($); 
     81    sub get_config_value($$); 
     82    sub delete_mail_item($$); 
     83    sub delete_mail_references($$$); 
     84    sub expire_quarantine($); 
     85    sub expire_ham_cache($); 
     86    sub expire_orphans($); 
     87    sub expire_strays($); 
     88    sub count_ham_cache($); 
     89    sub count_q_cache($); 
     90    sub expire_tokens($); 
     91    sub update_mail_stats($$$); 
     92    sub recalc_stats($); 
     93 
     94    # name of this script 
     95    my $script_name = "expire-quarantine-cache"; 
     96 
     97    # read configuration file (/etc/maia.conf) 
     98    my $config_file = "/etc/maia.conf"; 
     99    unless (my $rv = do $config_file) { 
     100        die("Maia: [$script_name] Couldn't parse $config_file: $@\n") if $@; 
     101        die("Maia: [$script_name] Couldn't open $config_file\n") if (!defined($rv) || !$rv); 
     102    }; 
     103 
     104    my $dbh; 
     105 
     106    # database configuration 
     107    if (defined($dsn) && defined($username) && defined($password)) { 
     108        $dbh = DBI->connect($dsn, $username, $password) 
     109            or die("Maia: [$script_name] Can't connect to the Maia database " . 
     110                   "(verify \$dsn, \$username, and \$password in maia.conf)\n"); 
     111    } else { 
     112        die("Maia: [$script_name] Can't connect to the Maia database " . 
     113            "(missing \$dsn, \$username, or \$password in maia.conf)\n"); 
     114    } 
     115 
     116    my $qcount = expire_quarantine($dbh); 
     117    my $hcount = expire_ham_cache($dbh); 
     118    my $cleanup = expire_orphans($dbh); 
     119    my $strayclean = expire_strays($dbh); 
     120    recalc_stats($dbh) if ($qcount + $hcount + $cleanup + $strayclean > 0); 
     121 
     122    my $curhamcount = count_ham_cache($dbh); 
     123    my $curqcount = count_q_cache($dbh); 
     124    expire_tokens($dbh); 
     125 
     126    print $qcount . " quarantined items expired\n"; 
     127    print $hcount . " cached ham items expired\n"; 
     128    if ($cleanup > 0) { 
     129        print $cleanup . " orphaned items expired - please investigate!\n"; 
     130    } 
     131    if ($strayclean > 0) { 
     132        print $strayclean . " stray items expired - please investigate!\n"; 
     133    }  
     134    print "\n"; 
     135    print "Current Cache After Expiration:\n"; 
     136    print "Quarantined Items: " . $curqcount . "\n"; 
     137    print "Non-spam Items: " . $curhamcount . "\n"; 
     138 
     139    # Disconnect from the database 
     140    $dbh->disconnect; 
     141 
     142    # We're done. 
     143    exit; 
     144 
     145 
     146    # Determine the database type: "mysql" or "pg" 
    102147    sub get_db_type($) { 
    103148        my($dbh) = @_; 
     
    338383        my($expiry_count); 
    339384       
    340         print "Expiring Stray Mail Recipient reference with no Mail Item\n"; 
     385        print "Expiring Stray Mail Recipient references with no Mail Item\n"; 
    341386        $select = "SELECT maia_mail_recipients.mail_id " . 
    342387            "FROM maia_mail_recipients " . 
     
    552597        $sth->finish; 
    553598    } 
    554  
    555  
    556 ######################################################################### 
    557 # Main subroutine                                                       # 
    558 ######################################################################### 
    559  
    560     # Read the database configuration file into memory once 
    561     open CONFIGFILE, "<" . $cfg 
    562         or die ("Maia: [expire-quarantine-cache] Unable to open $cfg\n"); 
    563     my($config) = ""; 
    564     my $line; 
    565     while ($line = <CONFIGFILE>) { 
    566         $config .= $line; 
    567     } 
    568     close CONFIGFILE; 
    569  
    570     # Connect to the database 
    571     my $dsn = get_string_key($config, "dsn"); 
    572     my $username = get_string_key($config, "username"); 
    573     my $password = get_string_key($config, "password"); 
    574     my $dbh = DBI->connect($dsn, $username, $password) 
    575                        or die("Can't connect to SQL database"); 
    576  
    577     my $qcount = expire_quarantine($dbh); 
    578     my $hcount = expire_ham_cache($dbh); 
    579     my $cleanup = expire_orphans($dbh); 
    580     my $strayclean = expire_strays($dbh); 
    581     recalc_stats($dbh) if ($qcount + $hcount + $cleanup + $strayclean > 0); 
    582  
    583     my $curhamcount = count_ham_cache($dbh); 
    584     my $curqcount = count_q_cache($dbh); 
    585     expire_tokens($dbh); 
    586  
    587     print $qcount . " quarantined items expired\n"; 
    588     print $hcount . " cached ham items expired\n"; 
    589     if ($cleanup > 0) { 
    590         print $cleanup . " orphaned items expired - please investigate!\n"; 
    591     } 
    592     if ($strayclean > 0) { 
    593         print $strayclean . " stray items expired - please investigate!\n"; 
    594     }  
    595     print "\n"; 
    596     print "Current Cache After Expiration:\n"; 
    597     print "Quarantined Items: " . $curqcount . "\n"; 
    598     print "Non-spam Items: " . $curhamcount . "\n"; 
    599  
    600     # Disconnect from the database 
    601     $dbh->disconnect; 
    602  
    603     # We're done. 
    604     exit; 
  • trunk/scripts/load-sa-rules.pl

    r964 r977  
    1 #!/usr/bin/perl -T 
     1#!/usr/bin/perl 
    22 
    33# $Id$ 
     
    7575######################################################################## 
    7676 
    77     use strict; 
    7877    use DBI; 
    7978    use Mail::SpamAssassin; 
    8079 
    81     # CONFIGURE THIS: SpamAssassin directories to search for rules 
    82     #                 files (*.cf and user_prefs) 
    83     my $local_cf_dir = "/etc/mail/spamassassin"; 
    84     my $system_rules_dir = "/usr/share/spamassassin"; 
    85     my $user_rules_dir = "/var/amavisd/.spamassassin"; 
    86  
    87     # CONFIGURE THIS: Location of your database.cfg file 
    88     my $cfg = "/var/amavisd/maia/scripts/database.cfg"; 
    89  
    90 ######################################################################## 
    91 # End of user-configurable portion.  There should be no need to modify # 
    92 # anything below this point.                                           # 
    93 ######################################################################## 
    94  
    95     # Retrieve the string value associated with a key in the database.cfg file. 
    96     sub get_string_key($$) 
    97     { 
    98        my ($file, $key) = @_; 
    99  
    100        if ($file =~ /\n[ \t]*$key[ \t]*=[ \t]*\"(.*)\"/) { 
    101           return ($1); 
    102        } else { 
    103           die ("Maia: [get_string_key] Unable to find $key value in $file\n"); 
    104        } 
     80    # prototypes 
     81    sub scan_rules_directory($$); 
     82 
     83    # name of this script 
     84    my $script_name = "load-sa-rules"; 
     85 
     86    # read configuration file (/etc/maia.conf) 
     87    my $config_file = "/etc/maia.conf"; 
     88    unless (my $rv = do $config_file) { 
     89        die("Maia: [$script_name] Couldn't parse $config_file: $@\n") if $@; 
     90        die("Maia: [$script_name] Couldn't open $config_file\n") if (!defined($rv) || !$rv); 
     91    }; 
     92 
     93    # defaults (overridden by values in /etc/maia.conf) 
     94    $local_cf_dir = "/etc/mail/spamassassin" if !defined($local_cf_dir); 
     95    $system_rules_dir = "/usr/share/spamassassin" if !defined($system_rules_dir); 
     96    $user_rules_dir = "/var/amavisd/.spamassassin" if !defined($user_rules_dir); 
     97 
     98    my $dbh; 
     99 
     100    # database configuration 
     101    if (defined($dsn) && defined($username) && defined($password)) { 
     102        $dbh = DBI->connect($dsn, $username, $password) 
     103            or die("Maia: [$script_name] Can't connect to the Maia database " . 
     104                   "(verify \$dsn, \$username, and \$password in maia.conf)\n"); 
     105    } else { 
     106        die("Maia: [$script_name] Can't connect to the Maia database " . 
     107            "(missing \$dsn, \$username, or \$password in maia.conf)\n"); 
    105108    } 
     109 
     110    # Scan the rules directories in this specific order: 
     111    # 
     112    #    1. Default rules (e.g. /usr/share/spamassassin) 
     113    #    2. System rules (e.g. /etc/mail/spamassassin) 
     114    #    3. User rules (e.g. /var/amavisd/.spamassassin) 
     115    # 
     116    # The order is critical, since later rules override 
     117    # the scores of earlier ones (e.g. a user rule could 
     118    # assign a score of 0 to a rule to disable it, etc.). 
     119    my $count = 0; 
     120    $count += scan_rules_directory($dbh, $system_rules_dir); 
     121    $count += scan_rules_directory($dbh, $local_cf_dir); 
     122    $count += scan_rules_directory($dbh, $user_rules_dir); 
     123 
     124    print "$count new rules added, all scores updated.\n"; 
     125 
     126    # Disconnect from the database 
     127    $dbh->disconnect; 
     128 
     129    # We're done. 
     130    exit; 
    106131 
    107132 
     
    264289        return $rules_added; 
    265290    } 
    266  
    267  
    268     # Read the database configuration file into memory once 
    269     open CONFIGFILE, "<" . $cfg 
    270         or die ("Maia: [load-sa-rules] Unable to open $cfg\n"); 
    271     my($config) = ""; 
    272     my $line; 
    273     while ($line = <CONFIGFILE>) { 
    274         $config .= $line; 
    275     } 
    276     close CONFIGFILE; 
    277  
    278     # Connect to the database 
    279     my $dsn = get_string_key($config, "dsn"); 
    280     my $username = get_string_key($config, "username"); 
    281     my $password = get_string_key($config, "password"); 
    282     my $dbh = DBI->connect($dsn, $username, $password) 
    283                        or die("Can't connect to SQL database"); 
    284  
    285     # Scan the rules directories in this specific order: 
    286     # 
    287     #    1. Default rules (e.g. /usr/local/share/spamassassin) 
    288     #    2. System rules (e.g. /etc/mail/spamassassin) 
    289     #    3. User rules (e.g. /var/amavisd/.spamassassin) 
    290     # 
    291     # The order is critical, since later rules override 
    292     # the scores of earlier ones (e.g. a user rule could 
    293     # assign a score of 0 to a rule to disable it, etc.). 
    294     my $count = 0; 
    295     $count += scan_rules_directory($dbh, $system_rules_dir); 
    296     $count += scan_rules_directory($dbh, $local_cf_dir); 
    297     $count += scan_rules_directory($dbh, $user_rules_dir); 
    298  
    299     print "$count new rules added, all scores updated.\n"; 
    300  
    301     # Disconnect from the database 
    302     $dbh->disconnect; 
    303  
    304     # We're done. 
    305     exit; 
  • trunk/scripts/process-quarantine-sub.pl

    r966 r977  
    1 #!/usr/bin/perl -T 
     1#!/usr/bin/perl 
    22 
    33# $Id$ 
     
    7575######################################################################## 
    7676 
    77 use strict; 
    7877use DBI; 
    7978use Mail::SpamAssassin; 
     
    9190use Mail::SpamAssassin::Reporter; 
    9291 
    93 # CONFIGURE THIS: Maximum number of spam/non-spam items to process at a  
    94 #                 time (1-127). 
    95 my $default_limit = 5; 
    96  
    97 # CONFIGURE THIS: Location of your database.cfg file 
    98 my $cfg = "/var/amavisd/maia/scripts/database.cfg"; 
    99  
    100 # CONFIGURE THIS: Location of your encryption key file, or undef to disable 
    101 #my $key_file = "/var/amavisd/blowfish.key"; 
    102 my $key_file = undef; 
    103  
    104 # CONFIGURE THIS: Items larger than this size (in bytes) will not be  
    105 #                 learned/reported. 
    106 my $default_max_size = 256*1024; 
    107  
    108  
    109 ######################################################################## 
    110 # End of user-configurable portion.  There should be no need to modify # 
    111 # anything below this point.                                           # 
    112 ######################################################################## 
     92# prototypes 
     93sub fatal($); 
     94sub get_encryption_key($); 
     95sub text_is_encrypted($); 
     96sub decrypt_text($$$); 
     97sub delete_mail_item($$); 
     98sub delete_mail($$$$); 
     99sub do_learn($$$); 
     100sub do_report($$$); 
     101sub process_spam($$$$$$$$); 
     102sub process_ham($$$$$$$); 
     103 
     104# name of this script 
     105my $script_name = "process-quarantine-sub"; 
     106 
     107# read configuration file (/etc/maia.conf) 
     108my $config_file = "/etc/maia.conf"; 
     109unless (my $rv = do $config_file) { 
     110    die("Maia: [$script_name] Couldn't parse $config_file: $@\n") if $@; 
     111    die("Maia: [$script_name] Couldn't open $config_file\n") if (!defined($rv) || !$rv); 
     112}; 
     113 
     114# defaults (overridden by settings in /etc/maia.conf) 
     115$default_limit = 5 if !defined($default_limit); 
     116$key_file = undef if !defined($key_file); 
     117$default_max_size = 256*1024 if !defined($default_max_size); 
     118 
     119my $limit = $default_limit; 
     120my $max_size = $default_max_size; 
     121my $learn = 0;                  # disabled 
     122my $report = 0;                 # disabled 
     123my $spamonly = 0;               # disabled 
     124my $hamonly = 0;                # disabled 
     125my $debug = 0;                  # disabled 
     126my $quiet = 0;                  # disabled 
     127     
     128GetOptions("limit=i" => \$limit,        # --limit=int or --limit int 
     129           "max-size=i" => \$max_size,  # --max-size=int or --max-size int 
     130           "learn" => \$learn,          # --learn 
     131           "report" => \$report,        # --report 
     132           "spam-only" => \$spamonly,   # --spam-only 
     133           "ham-only" => \$hamonly,     # --ham-only 
     134           "debug" => \$debug,          # --debug 
     135           "quiet" => \$quiet);         # --quiet 
     136 
     137# Sanity-check any supplied arguments 
     138$limit = ($limit > 0 ? $limit : $default_limit); 
     139if ($limit > 127) { 
     140    $limit = 127; 
     141    if ($debug) { 
     142        print "Maia: [$script_name] Warning: enforcing maximum limit of 127 spam/non-spam items per run.\n"; 
     143    } 
     144} 
     145$max_size = ($max_size > 0 ? $max_size : $default_max_size); 
     146if ($spamonly && $hamonly) { 
     147    $spamonly = 0; 
     148    $hamonly = 0; 
     149    if ($debug) { 
     150        print "Maia: [$script_name] Warning: --spam-only and --ham-only negate each other.\n"; 
     151    } 
     152} 
     153if ($hamonly) { 
     154    $report = 0; 
     155    if ($debug) { 
     156        print "Maia: [$script_name] Warning: --report disregarded when --ham-only is specified.\n"; 
     157    } 
     158} 
     159if ($debug && $quiet) { 
     160    $debug = 0; 
     161    $quiet = 0; 
     162    print "Maia: [$script_name] Warning: --debug and --quiet negate each other.\n"; 
     163} 
     164if ($debug) { 
     165    print "Maia: [$script_name] starting\n"; 
     166    print "Maia: [$script_name] limit = $limit items per run\n"; 
     167    print "Maia: [$script_name] max-size = $max_size bytes\n"; 
     168    print "Maia: [$script_name] learn = " . ($learn ? "enabled" : "disabled") . "\n"; 
     169    print "Maia: [$script_name] report = " . ($report ? "enabled" : "disabled") . "\n"; 
     170    print "Maia: [$script_name] spam-only = " . ($spamonly ? "enabled" : "disabled") . "\n"; 
     171    print "Maia: [$script_name] ham-only = " . ($hamonly ? "enabled" : "disabled") . "\n"; 
     172    print "Maia: [$script_name] debug = " . ($debug ? "enabled" : "disabled") . "\n"; 
     173    print "Maia: [$script_name] quiet = " . ($quiet ? "enabled" : "disabled") . "\n"; 
     174} 
     175 
     176my $dbh; 
     177 
     178# database configuration 
     179if (defined($dsn) && defined($username) && defined($password)) { 
     180    $dbh = DBI->connect($dsn, $username, $password) 
     181        or die("Maia: [$script_name] Can't connect to the Maia database " . 
     182               "(verify \$dsn, \$username, and \$password in maia.conf)\n"); 
     183} else { 
     184    die("Maia: [$script_name] Can't connect to the Maia database " . 
     185        "(missing \$dsn, \$username, or \$password in maia.conf)\n"); 
     186} 
     187 
     188# Process one batch of confirmed spam and/or confirmed ham 
     189my $key = get_encryption_key($key_file); 
     190my $spamcount = 0; 
     191my $hamcount = 0; 
     192if ($spamonly) { 
     193    $spamcount = process_spam($dbh, $learn, $report, $key, $limit, $debug, $quiet, $max_size); 
     194} elsif ($hamonly) { 
     195    $hamcount = process_ham($dbh, $learn, $key, $limit, $debug, $quiet, $max_size); 
     196} else { 
     197    $spamcount = process_spam($dbh, $learn, $report, $key, $limit, $debug, $quiet, $max_size); 
     198    $hamcount = process_ham($dbh, $learn, $key, $limit, $debug, $quiet, $max_size); 
     199} 
     200 
     201# Disconnect from the database 
     202$dbh->disconnect; 
     203 
     204# We're done, return the total number of items processed. 
     205exit ($spamcount + $hamcount); 
     206 
    113207 
    114208# Die, returning 255 to the wrapper 
     
    119213   print $msg . "\n"; 
    120214   exit 255; 
    121 } 
    122  
    123 # Retrieve the string value associated with a key in the database.cfg file. 
    124 sub get_string_key($$) 
    125 { 
    126    my ($file, $key) = @_; 
    127  
    128    if ($file =~ /\n[ \t]*$key[ \t]*=[ \t]*\"(.*)\"/) { 
    129       return ($1); 
    130    } else { 
    131       fatal("Maia: [get_string_key] Unable to find $key value in $file"); 
    132    } 
    133215} 
    134216 
     
    490572    return $count; 
    491573} 
    492  
    493  
    494 ######################################################################### 
    495 # Main subroutine                                                       # 
    496 ######################################################################### 
    497  
    498 my $limit = $default_limit; 
    499 my $max_size = $default_max_size; 
    500 my $learn = 0;                  # disabled 
    501 my $report = 0;                 # disabled 
    502 my $spamonly = 0;               # disabled 
    503 my $hamonly = 0;                # disabled 
    504 my $debug = 0;                  # disabled 
    505 my $quiet = 0;                  # disabled 
    506      
    507 GetOptions("limit=i" => \$limit,        # --limit=int or --limit int 
    508            "max-size=i" => \$max_size,  # --max-size=int or --max-size int 
    509            "learn" => \$learn,          # --learn 
    510            "report" => \$report,        # --report 
    511            "spam-only" => \$spamonly,   # --spam-only 
    512            "ham-only" => \$hamonly,     # --ham-only 
    513            "debug" => \$debug,          # --debug 
    514            "quiet" => \$quiet);         # --quiet 
    515  
    516 # Sanity-check any supplied arguments 
    517 $limit = ($limit > 0 ? $limit : $default_limit); 
    518 if ($limit > 127) { 
    519     $limit = 127; 
    520     if ($debug) { 
    521         print "Maia: [sub] Warning: enforcing maximum limit of 127 spam/non-spam items per run.\n"; 
    522     } 
    523 } 
    524 $max_size = ($max_size > 0 ? $max_size : $default_max_size); 
    525 if ($spamonly && $hamonly) { 
    526     $spamonly = 0; 
    527     $hamonly = 0; 
    528     if ($debug) { 
    529         print "Maia: [sub] Warning: --spam-only and --ham-only negate each other.\n"; 
    530     } 
    531 } 
    532 if ($hamonly) { 
    533     $report = 0; 
    534     if ($debug) { 
    535         print "Maia: [sub] Warning: --report disregarded when --ham-only is specified.\n"; 
    536     } 
    537 } 
    538 if ($debug && $quiet) { 
    539     $debug = 0; 
    540     $quiet = 0; 
    541     print "Maia: [sub] Warning: --debug and --quiet negate each other.\n"; 
    542 } 
    543 if ($debug) { 
    544     print "Maia: [sub] starting\n"; 
    545     print "Maia: [sub] limit = $limit items per run\n"; 
    546     print "Maia: [sub] max-size = $max_size bytes\n"; 
    547     print "Maia: [sub] learn = " . ($learn ? "enabled" : "disabled") . "\n";