Mail-Decency

 view release on metacpan or  search on metacpan

lib/Mail/Decency/Policy/Greylist.pm  view on Meta::CPAN


=head1 CLASS ATTRIBUTES


=head2 hosts_policy : HashRef[HashRef[Int]]

Determines accommodation requirements per host (IP)

=cut

has hosts_policy    => ( is => 'rw', isa => 'HashRef[HashRef[Int]]', predicate => 'has_hosts_policy' );

=head2 domains_policy : HashRef[HashRef[Int]]

Determines accommodation requirements per domain (sender)

=cut

has domains_policy  => ( is => 'rw', isa => 'HashRef[HashRef[Int]]', predicate => 'has_domains_policy' );

=head2 min_interval : Int

Min interval 

=cut

has min_interval => ( is => 'rw', isa => 'Int', default => 600 );

=head2 reject_message : Str

Message for greylisted rejection.

Default: "Greylisted - Patience, young jedi"

=cut

has reject_message  => ( is => 'rw', isa => 'Str', default => "Greylisted - Patience, young jedi" );

=head2 pass_code : Str

Set to "OK" if mails on the found on the greylist shall be whitelisted. Per default, they just won't be rejected (DUNNO).

=cut

has pass_code => ( is => 'rw', isa => 'Str', default => "DUNNO" );

=head2 scoring_aware : Bool

If scoring aware, will not use the host- and domain policies if score is below zero (spammy).

=cut

has scoring_aware => ( is => 'rw', isa => 'Bool', default => 0 );

=head2 schema_definition : HashRef[HashRef]

Database schema

=cut

has schema_definition => ( is => 'ro', isa => 'HashRef[HashRef]', default => sub {
    {
        greylist => {
            client_address => {
                client_address => [ varchar => 39 ],
                counter        => 'integer',
                last_seen      => 'integer',
                -unique        => [ 'client_address' ]
            },
            sender_domain => {
                sender_domain => [ varchar => 255 ],
                counter       => 'integer',
                last_seen     => 'integer',
                max_unique    => 'integer',
                max_one       => 'integer',
                unique_sender => 'blob',
                -unique       => [ 'sender_domain' ]
            },
            sender_recipient => {
                sender_address    => [ varchar => 255 ],
                recipient_address => [ varchar => 255 ],
                counter           => 'integer',
                last_seen         => 'integer',
                max_unique        => 'integer',
                max_one           => 'integer',
                unique_sender     => 'blob',
                -unique           => [ 'sender_address', 'recipient_address' ]
            }
        }
    };
} );



=head1 METHODS


=head2 init

=cut 

sub init {
    my ( $self ) = @_;
    
    # having sender policies ?
    foreach my $policy( qw/ hosts_policy domains_policy / ) {
        next unless defined $self->config->{ $policy };
        die "$policy is not a hashref!\n"
            unless ref( $self->config->{ $policy } ) eq 'HASH';
        die "provide unique_sender and/or one_address for $policy\n"
            unless $self->config->{ $policy }->{ one_address }
            && $self->config->{ $policy }->{ unique_sender };
    }
    
    # min interval before re-send is considered ok
    $self->min_interval( $self->config->{ min_interval } )
        if defined $self->config->{ min_interval };
    
    # reject code (temporary)
    $self->reject_message( $self->config->{ reject_message } )
        if $self->config->{ reject_message };



( run in 0.353 second using v1.01-cache-2.11-cpan-d8267643d1d )