App-Milter-Limit

 view release on metacpan or  search on metacpan

lib/App/Milter/Limit.pm  view on Meta::CPAN

    if (index(','.$ignore.',', ','.$from.',') != -1) {
        info("$from found in ignore list, continuing");
        return SMFIS_CONTINUE;
    }

    my $count = $self->driver->query($from);
    debug("$from [$count/$$conf{limit}]");

    if ($count > $$conf{limit}) {
        if ($reply eq 'defer') {
            info("$from exceeded message limit, deferring");

            $ctx->setreply(450, '4.7.1', $message);

            return SMFIS_TEMPFAIL;
        }
        else {
            info("$from exceeded message limit, rejecting");

            $ctx->setreply(550, '5.7.1', $message);

            return SMFIS_REJECT;
        }
    }
    else {
        return SMFIS_CONTINUE;
    }
}


# shortcut to get the config.
sub config {
    App::Milter::Limit::Config->instance;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

App::Milter::Limit - Sendmail Milter that limits message rate by sender

=head1 VERSION

version 0.54

=head1 SYNOPSIS

 my $config = App::Milter::Limit::Config->instance('/etc/mail/milter-limit.conf');
 my $milter = App::Milter::Limit->instance('BerkeleyDB');
 $milter->register;
 $milter->main

=head1 DESCRIPTION

This is a milter framework that limits the number of messages sent by SMTP
envelope sender within a specified time period.  The number of messages and
length of time in which the maximum number of messages can be sent is
configurable in the configuration file.  Once the limit is reached, messages
will be rejected from that sender until the time period has elapsed.

This module provides the interface for the milter.  A datastore plugin is also
required to use this milter.  Datastores are available in the
I<App::Milter::Limit::Plugin> namespace.

=head1 METHODS

=head2 instance($driver)

This gets the I<App::Milter::Limit> object, constructing it if necessary.
C<$driver> is the name of the driver that you wish to use (e.g.: I<SQLite>,
I<BerkeleyDB>).

=head2 register

Registers the milter with sendmail and sets up the milter handlers.
See L<Milter::PMilter::register()>.

=head2 main

Main milter loop.

=head2 config

get the App::Milter::Limit::Config instance

=for Pod::Coverage init

=head1 SEE ALSO

L<App::Milter::Limit::Plugin::BerkeleyDB>,
L<App::Milter::Limit::Plugin::SQLite>

=head1 SOURCE

The development version is on github at L<https://github.com/mschout/milter-limit>
and may be cloned from L<https://github.com/mschout/milter-limit.git>

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website
L<https://github.com/mschout/milter-limit/issues>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

Michael Schout <mschout@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Michael Schout.

This is free software; you can redistribute it and/or modify it under



( run in 1.896 second using v1.01-cache-2.11-cpan-e1769b4cff6 )