Mail-MtPolicyd

 view release on metacpan or  search on metacpan

lib/Mail/MtPolicyd/AddressList.pm  view on Meta::CPAN

package Mail::MtPolicyd::AddressList;

use Moose;
use namespace::autoclean;

our $VERSION = '2.05'; # VERSION
# ABSTRACT: a class for IP address lists

use NetAddr::IP;

has '_localhost_addr' => ( is => 'ro', isa => 'ArrayRef[NetAddr::IP]',
    lazy => 1,
    default => sub {
        return [ map { NetAddr::IP->new( $_ ) }
            ( '127.0.0.0/8', '::ffff:127.0.0.0/104', '::1' ) ];
    },
);


has 'list' => (
    is => 'ro', isa => 'ArrayRef[NetAddr::IP]', lazy => 1,
    default => sub { [] },
    traits => [ 'Array' ],
    handles => {
        'add' => 'push',
        'is_empty' => 'is_empty',
        'count' => 'count',
    },
);


lib/Mail/MtPolicyd/Client/Request.pm  view on Meta::CPAN


has 'type' => ( is => 'ro', isa => 'Str', default => 'smtpd_access_policy' );

has 'instance' => ( is => 'ro', isa => 'Str', lazy => 1,
	default => sub {
		return rand;
	},
);

has 'attributes' => (
	is => 'ro', isa => 'HashRef[Str]',
	default => sub { {} },
);

sub as_string {
	my $self = shift;

	return join("\n",
		'request='.$self->type,
		'instance='.$self->instance,
		map { $_.'='.$self->attributes->{$_} } keys %{$self->attributes},

lib/Mail/MtPolicyd/Client/Response.pm  view on Meta::CPAN


use Moose;

our $VERSION = '2.05'; # VERSION
# ABSTRACT: a postfix policyd client response class


has 'action' => ( is => 'ro', isa => 'Str', required => 1 );

has 'attributes' => (
	is => 'ro', isa => 'HashRef[Str]',
	default => sub { {} },
);

sub as_string {
	my $self = shift;

	return join("\n",
		map { $_.'='.$self->attributes->{$_} } keys %{$self->attributes},
	)."\n\n";
}

lib/Mail/MtPolicyd/Connection/Memcached.pm  view on Meta::CPAN

our $VERSION = '2.05'; # VERSION
# ABSTRACT: a memcached connection plugin for mtpolicyd

extends 'Mail::MtPolicyd::Connection';


use Cache::Memcached;

has 'servers' => ( is => 'ro', isa => 'Str', default => '127.0.0.1:11211' );
has '_servers' => (
  is => 'ro', isa => 'ArrayRef[Str]', lazy => 1,
  default => sub {
    my $self = shift;
    return [ split(/\s*,\s*/, $self->servers) ];
  },
);

has 'debug' => ( is => 'ro', isa => 'Bool', default => 0 );
has 'namespace' => ( is => 'ro', isa => 'Str', default => '');

sub _create_handle {

lib/Mail/MtPolicyd/Plugin/Accounting.pm  view on Meta::CPAN

};

use Mail::MtPolicyd::Plugin::Result;

use Time::Piece;


has 'enabled' => ( is => 'rw', isa => 'Str', default => 'on' );

has 'fields' => ( is => 'rw', isa => 'Str', required => 1);
has '_fields' => ( is => 'ro', isa => 'ArrayRef', lazy => 1,
    default => sub {
        my $self = shift;
        return [ split('\s*,\s*', $self->fields) ];
    },
);

has 'time_pattern' => ( is => 'rw', isa => 'Str', default => '%Y-%m');

with 'Mail::MtPolicyd::Role::Connection' => {
  name => 'db',

lib/Mail/MtPolicyd/Plugin/Accounting.pm  view on Meta::CPAN


	return;
}

sub init {
    my $self = shift;
    $self->check_sql_tables( %{$self->_table_definitions} );
    return;
}

has '_single_table_create' => ( is => 'ro', isa => 'HashRef', lazy => 1,
    default => sub { {
        'mysql' => 'CREATE TABLE %TABLE_NAME% (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `key` VARCHAR(255) NOT NULL,
    `time` VARCHAR(255) NOT NULL,
    `count` INT UNSIGNED NOT NULL,
    `count_rcpt` INT UNSIGNED NOT NULL,
    `size` INT UNSIGNED NOT NULL,
    `size_rcpt` INT UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),

lib/Mail/MtPolicyd/Plugin/Accounting.pm  view on Meta::CPAN

    `size_rcpt` INT UNSIGNED NOT NULL
)',
    } }
);

sub get_table_name {
    my ( $self, $field ) = @_;
    return( $self->table_prefix . $field );
}

has '_table_definitions' => ( is => 'ro', isa => 'HashRef', lazy => 1,
    default => sub {
        my $self = shift;
        my $tables = {};
        foreach my $field ( @{$self->_fields} ) {
            my $table_name = $self->get_table_name($field);
            $tables->{$table_name} = $self->_single_table_create;
        }
        return $tables;
    },
);

lib/Mail/MtPolicyd/Plugin/GeoIPAction.pm  view on Meta::CPAN

};

use Mail::MtPolicyd::Plugin::Result;

has 'result_from' => ( is => 'rw', isa => 'Str', required => 1 );
has 'enabled' => ( is => 'rw', isa => 'Str', default => 'on' );
has 'mode' => ( is => 'rw', isa => 'Str', default => 'reject' );

has 'country_codes' => ( is => 'rw', isa => 'Str', required => 1 );
has '_country_codes' => (
	is => 'ro', isa => 'ArrayRef', lazy => 1,
	default => sub {
		my $self = shift;
		return [ split(/\s*,\s*/, $self->country_codes) ];
	},
);

sub is_in_country_codes {
	my ( $self, $cc ) = @_;
	if ( grep { $_ eq $cc } @{$self->_country_codes} ) {
		return(1);

lib/Mail/MtPolicyd/Plugin/Greylist/AWL/Sql.pm  view on Meta::CPAN

    $self->autowl_table );
	$self->execute_sql($sql, $now, $timeout);
	return;
}

sub init {
  my $self = shift;
  $self->check_sql_tables( %{$self->_table_definitions} );
}

has '_table_definitions' => ( is => 'ro', isa => 'HashRef', lazy => 1,
    default => sub { {
        'autowl' => {
            'mysql' => 'CREATE TABLE %TABLE_NAME% (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `sender_domain` VARCHAR(255) NOT NULL,
    `client_ip` VARCHAR(39) NOT NULL,
    `count` INT UNSIGNED NOT NULL,
    `last_seen` INT UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `domain_ip` (`client_ip`, `sender_domain`),

lib/Mail/MtPolicyd/Plugin/Honeypot.pm  view on Meta::CPAN



has 'enabled' => ( is => 'rw', isa => 'Str', default => 'on' );

has 'score' => ( is => 'rw', isa => 'Maybe[Num]' );
has 'mode' => ( is => 'rw', isa => 'Str', default => 'reject');

has 'recipients' => ( is => 'rw', isa => 'Str', default => '' );
has 'recipients_re' => ( is => 'rw', isa => 'Str', default => '' );

has _recipients => ( is => 'ro', isa => 'ArrayRef', lazy => 1,
	default => sub {
		my $self = shift;
		return  [ split(/\s*,\s*/, $self->recipients) ];
	},
);

has _recipients_re => ( is => 'ro', isa => 'ArrayRef', lazy => 1,
	default => sub {
		my $self = shift;
		return  [ split(/\s*,\s*/, $self->recipients_re) ];
	},
);

has 'reject_message' => ( is => 'rw', isa => 'Str', default => 'trapped by honeypod' );

has 'expire' => ( is => 'rw', isa => 'Int', default => 60*60*2 );

lib/Mail/MtPolicyd/Plugin/LdapUserConfig.pm  view on Meta::CPAN

      default => 'sasl_username',
      value_isa => 'Str',
    },
  },
};


has 'config_fields' => ( is => 'rw', isa => 'Str', required => 1 );

has '_config_fields' => (
  is => 'ro', isa => 'ArrayRef[Str]', lazy => 1,
  default => sub {
    my $self = shift;
    return [ split(/\s*,\s*/, $self->config_fields ) ];
  },
);

has 'connection' => ( is => 'ro', isa => 'Str', default => 'ldap' );
has 'connection_type' => ( is => 'ro', isa => 'Str', default => 'Ldap' );

with 'Mail::MtPolicyd::Role::Connection' => {

lib/Mail/MtPolicyd/Plugin/PostfixMap.pm  view on Meta::CPAN

use Mail::MtPolicyd::Plugin::Result;

use BerkeleyDB;
use BerkeleyDB::Hash;


has 'enabled' => ( is => 'rw', isa => 'Str', default => 'on' );

has 'db_file' => ( is => 'rw', isa => 'Str', required => 1 );
has _map => (
	is => 'ro', isa => 'HashRef', lazy => 1,
	default => sub {
		my $self = shift;
		my %map;
		my $db = tie %map, 'BerkeleyDB::Hash',
			-Filename => $self->db_file,
			-Flags => DB_RDONLY
		or die "Cannot open ".$self->db_file.": $!\n" ;
		$db->filter_fetch_key  ( sub { s/\0$//    } ) ;
		$db->filter_store_key  ( sub { $_ .= "\0" } ) ;
		$db->filter_fetch_value( sub { s/\0$//    } ) ;

lib/Mail/MtPolicyd/Plugin/RegexList.pm  view on Meta::CPAN

    }
  }
  return $class->$orig(%params);
};

has 'regex' => ( is => 'rw', isa => 'ArrayRef[Str]', default => sub { [] });

has 'file' => ( is => 'rw', isa => 'Maybe[Str]' );

has '_file_regex_list' => (
  is => 'ro', isa => 'ArrayRef', lazy => 1,
  default => sub {
    my $self = shift;
    if( ! defined $self->file ) {
      return [];
    }
    my @regexes;
    foreach my $line ( read_file($self->file) ) {
      chomp $line;
      if( $line =~ /^\s*$/ ) {
        next;

lib/Mail/MtPolicyd/Plugin/RegexList.pm  view on Meta::CPAN

      if( $line =~ /^\s*#/ ) {
        next;
      }
      push( @regexes, $line );
    }
    return \@regexes;
  },
);

has '_regex_list' => (
  is => 'ro', isa => 'ArrayRef', lazy => 1,
  default => sub {
    my $self = shift;
    return [ @{$self->regex}, @{$self->_file_regex_list} ]
  },
);

sub _match_regex_list {
  my ( $self, $r, $value ) = @_;

  foreach my $regex_str ( @{$self->_regex_list} ) {

lib/Mail/MtPolicyd/Plugin/SaAwlLookup.pm  view on Meta::CPAN

use BerkeleyDB::Hash;

use NetAddr::IP;


has 'db_file' => ( is => 'rw', isa => 'Str',
    default => '/var/lib/amamvis/.spamassassin/auto-whitelist'
);

has '_awl' => (
	is => 'ro', isa => 'HashRef', lazy => 1,
	default => sub {
		my $self = shift;
		my %map;
		my $db = tie %map, 'BerkeleyDB::Hash',
			-Filename => $self->db_file,
			-Flags => DB_RDONLY
		or die "Cannot open ".$self->db_file.": $!\n" ;
		return(\%map);
	},
);

lib/Mail/MtPolicyd/Profiler/Timer.pm  view on Meta::CPAN

# ABSTRACT: a profiler for the mtpolicyd

use Time::HiRes 'gettimeofday', 'tv_interval';

has 'name' => ( is => 'rw', isa => 'Str', required => 1 );

has 'start_time' => ( is => 'rw', isa => 'ArrayRef',
    default => sub { [gettimeofday()] },
);

has 'ticks' => ( is => 'ro', isa => 'ArrayRef', lazy => 1,
    default => sub { [] },
);

has 'parent' => ( is => 'ro', isa => 'Maybe[Mail::MtPolicyd::Profiler::Timer]' );

around BUILDARGS => sub {
        my $orig  = shift;
        my $class = shift;

        if ( @_ == 1 && !ref $_[0] ) {

lib/Mail/MtPolicyd/Request.pm  view on Meta::CPAN

use Moose;
use namespace::autoclean;

use Mail::MtPolicyd::Plugin::Result;

our $VERSION = '2.05'; # VERSION
# ABSTRACT: the request object


has 'attributes' => (
	is => 'ro', isa => 'HashRef', required => 1,
	traits => [ 'Hash' ],
	handles => { 'attr' => 'get' },
);


# gets attached later
has 'session' => ( is => 'rw', isa => 'Maybe[HashRef]' );


has 'server' => (

t/step_definitions/00test-net-server_steps.pl  view on Meta::CPAN

    while( ! -e $self->log_file ) {
        if( $retry >= $self->timeout ) {
            die('timeout while waiting for log_file to appear!');
        }
        sleep(1);
        $retry++;
    }
    return;
}

has 'lastlog' => ( is => 'ro', isa => 'ArrayRef', lazy => 1,
    default => sub {[]},
);

sub wait_for_logmessage {
    my $self = shift;
    my $regex = shift;
    my $log = IO::File->new( $self->log_file, 'r');
    if( ! defined $log ) {
        die('could not open logfile '.$self->log_file.': '.$!);
    }



( run in 0.456 second using v1.01-cache-2.11-cpan-5f2e87ce722 )