VUser-SpamAssassin-SQL

 view release on metacpan or  search on metacpan

lib/VUser/SpamAssassin/SQL/Bayes.pm  view on Meta::CPAN

package VUser::SpamAssassin::SQL::Bayes;
use warnings;
use strict;

# Copyright (c) 2007 Randy Smith <perlstalker@vuser.org>
# $Id: Bayes.pm,v 1.2 2007/04/12 19:17:08 perlstalker Exp $

our $VERSION = '0.1.0';

use VUser::Log qw(:levels);
use VUser::ResultSet;
use VUser::SpamAssassin;
use VUser::SpamAssassin::SQL;
use VUser::Meta;
use VUser::ExtLib qw(:config);
use VUser::ExtLib::SQL;
use VUser::Extension;
use base qw(VUser::Extension);

our $log;
our $c_sec = 'Extension SpamAssassin::SQL::Userprefs';
our %meta;
our $db;
my $dsn;
my $username;
my $password;

sub c_sec { return $c_sec; };
sub meta { return %meta; };

sub depends { qw(SpamAssassin::SQL); }

sub init {
    my $eh = shift;
    my %cfg = @_;
    
    if ( defined $main::log ) {
        $log = $main::log;
    } else {
        $log = VUser::Log->new( \%cfg, 'vuser' );
    }
    
    %meta = VUser::SpamAssassin::SQL::meta();
    
    $dsn      = strip_ws( $cfg{$c_sec}{'dsn'} );
    $username = strip_ws( $cfg{$c_sec}{'username'} );
    $password = strip_ws( $cfg{$c_sec}{'password'} );

    if ($dsn) {    
        $db = VUser::ExtLib::SQL->new(\%cfg,
            		      {'dsn' => $dsn,
			 	           'user' => $username,
				           'password' => $password,
				           'macros' => { 'u' => 'username',
						      'o' => 'option',
						      'v' => 'value'
						      }
				           });
    } else {
        $db = VUser::SpamAssassin::SQL::db();
    }
    
    if (not defined $db) {
        $log->log(LOG_ERROR, "Unable to connect to database.");
        die "Unable to connect to database\n";
    }
    
    $eh->register_task('sa', 'delall', \&sa_delall);
    
    # Email
    $eh->register_keyword('email');

    # Email-del: When an email is deleted, we need to remove all their
    # settings as well.
    $eh->register_action('email', 'del');
    $eh->register_task('email', 'del', \&sa_delall);
}

sub sa_delall {
    my ( $cfg, $opts, $action, $eh ) = @_;



( run in 1.525 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )