| 1 |
# |
| 2 |
# This file is best read with ``perldoc advanced.pod'' |
| 3 |
# |
| 4 |
|
| 5 |
### |
| 6 |
# Conventions: |
| 7 |
# plugin names: F<myplugin>, F<qpsmtpd-async> |
| 8 |
# constants: I<LOGDEBUG> |
| 9 |
# smtp commands, answers: B<HELO>, B<250 Queued!> |
| 10 |
# |
| 11 |
# Notes: |
| 12 |
# * due to restrictions of some POD parsers, no C<<$object->method()>> |
| 13 |
# are allowed, use C<$object-E<gt>method()> |
| 14 |
# |
| 15 |
|
| 16 |
=head1 Advanced Playground |
| 17 |
|
| 18 |
=head2 Discarding messages |
| 19 |
|
| 20 |
If you want to make the client think a message has been regularily accepted, |
| 21 |
but in real you delete it or send it to F</dev/null>, ..., use something |
| 22 |
like the following plugin and load it before your default queue plugin. |
| 23 |
|
| 24 |
sub hook_queue { |
| 25 |
my ($self, $transaction) = @_; |
| 26 |
if ($transaction->notes('discard_mail')) { |
| 27 |
my $msg_id = $transaction->header->get('Message-Id') || ''; |
| 28 |
$msg_id =~ s/[\r\n].*//s; |
| 29 |
return(OK, "Queued! $msg_id"); |
| 30 |
} |
| 31 |
return(DECLINED); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
=head2 Changing return values |
| 36 |
|
| 37 |
This is an example how to use the C<isa_plugin> method. |
| 38 |
|
| 39 |
The B<rcpt_ok_maxrelay> plugin wraps the B<rcpt_ok> plugin. The B<rcpt_ok> |
| 40 |
plugin checks the F<rcpthosts> and F<morercpthosts> config files for |
| 41 |
domains, which we accept mail for. If not found it tells the |
| 42 |
client that relaying is not allowed. Clients which are marked as |
| 43 |
C<relay clients> are excluded from this rule. This plugin counts the |
| 44 |
number of unsuccessfull relaying attempts and drops the connection if |
| 45 |
too many were made. |
| 46 |
|
| 47 |
The optional parameter I<MAX_RELAY_ATTEMPTS> configures this plugin to drop |
| 48 |
the connection after I<MAX_RELAY_ATTEMPTS> unsuccessful relaying attempts. |
| 49 |
Set to C<0> to disable, default is C<5>. |
| 50 |
|
| 51 |
Note: Do not load both (B<rcpt_ok> and B<rcpt_ok_maxrelay>). This plugin |
| 52 |
should be configured to run I<last>, like B<rcpt_ok>. |
| 53 |
|
| 54 |
use Qpsmtpd::DSN; |
| 55 |
|
| 56 |
sub init { |
| 57 |
my ($self, $qp, @args) = @_; |
| 58 |
die "too many arguments" |
| 59 |
if @args > 1; |
| 60 |
$self->{_count_relay_max} = defined $args[0] ? $args[0] : 5; |
| 61 |
$self->isa_plugin("rcpt_ok"); |
| 62 |
} |
| 63 |
|
| 64 |
sub hook_rcpt { |
| 65 |
my ($self, $transaction, $recipient) = @_; |
| 66 |
my ($rc, @msg) = $self->SUPER::hook_rcpt($transaction, $recipient); |
| 67 |
|
| 68 |
return ($rc, @msg) |
| 69 |
unless (($rc == DENY) and $self->{_count_relay_max}); |
| 70 |
|
| 71 |
my $count = |
| 72 |
($self->connection->notes('count_relay_attempts') || 0) + 1; |
| 73 |
$self->connection->notes('count_relay_attempts', $count); |
| 74 |
|
| 75 |
return ($rc, @msg) unless ($count > $self->{_count_relay_max}); |
| 76 |
return Qpsmtpd::DSN->relaying_denied(DENY_DISCONNECT, |
| 77 |
"Too many relaying attempts"); |
| 78 |
} |
| 79 |
|
| 80 |
=head2 Results of other hooks |
| 81 |
|
| 82 |
B<NOTE:> just copied from README.plugins |
| 83 |
|
| 84 |
If we're in a transaction, the results of a callback are stored in |
| 85 |
|
| 86 |
$self->transaction->notes( $code->{name})->{"hook_$hook"}->{return} |
| 87 |
|
| 88 |
If we're in a connection, store things in the connection notes instead. |
| 89 |
B<FIXME>: does the above (regarding connection notes) work? |
| 90 |
|
| 91 |
=cut |
| 92 |
|
| 93 |
# vim: ts=2 sw=2 expandtab |