Permalink
Browse files

reject and reject_type handling for plugins

  • Loading branch information...
1 parent 600b0db commit cbd1be70e8eaafbb5d041137e62646d90d59d911 @msimerson committed Jun 3, 2012
Showing with 78 additions and 1 deletion.
  1. +44 −1 docs/config.pod
  2. +34 −0 lib/Qpsmtpd/Plugin.pm
View
45 docs/config.pod
@@ -89,7 +89,7 @@ connection before any auth succeeds, defaults to C<0>.
=back
-=head2 Plugin settings
+=head2 Plugin settings files
=over 4
@@ -153,5 +153,48 @@ only currenlty.
=back
+=head2 Plugin settings arguments
+
+These are arguments that can be set on the config/plugins line, after the name
+of the plugin. These config options are available to all plugins.
+
+=over 4
+
+=item loglevel
+
+Adjust the quantity of logging for the plugin. See docs/logging.pod
+
+=item reject
+
+ plugin reject [ 0 | 1 | naughty ]
+
+Should the plugin reject mail?
+
+The special 'naughty' case will mark the connection as a naughty. Most plugins
+skip processing naughty connections. Filtering plugins can learn from them.
+Naughty connections are terminated up by the B<naughty> plugin.
+
+Plugins that use $self->get_reject() or $self->get_reject_type() will
+automatically honor this setting.
+
+=item reject_type
+
+ plugin reject_type [ perm | temp | disconnect | temp_disconnect ]
+
+Default: perm
+
+Values with temp in the name return a 4xx code and the others return a 5xx
+code.
+
+The I<reject_type> argument and the corresponding get_reject_type() method
+provides a standard way for plugins to automatically return the selected
+rejection type, as chosen by the config setting, the plugin author, or the
+get_reject_type() method.
+
+Plugins that are updated to use the $self->get_reject() or
+$self->get_reject_type() methods will automatically honor this setting.
+
+=back
+
=cut
View
34 lib/Qpsmtpd/Plugin.pm
@@ -210,6 +210,40 @@ sub compile {
die "eval $@" if $@;
}
+sub get_reject {
+ my $self = shift;
+ my $message = shift || "why didn't you pass an error message?";
+
+ my $reject = $self->{_args}{reject};
+ if ( defined $reject && ! $reject ) {
+ $self->log(LOGINFO, 'fail, reject disabled');
+ return DECLINED;
+ };
+
+ # the naughty plugin will reject later
+ if ( $reject eq 'naughty' ) {
+ $self->log(LOGINFO, 'fail, NAUGHTY');
+ $self->connection->notes('naughty', $message);
+ return (DECLINED);
+ };
+
+ # they asked for reject, we give them reject
+ $self->log(LOGINFO, 'fail');
+ return ( $self->get_reject_type(), $message);
+};
+
+sub get_reject_type {
+ my $self = shift;
+ my $default = shift || DENY;
+ my $deny = $self->{_args}{reject_type} or return $default;
+
+ return $deny =~ /^(temp|soft)$/i ? DENYSOFT
+ : $deny =~ /^(perm|hard)$/i ? DENY
+ : $deny eq 'disconnect' ? DENY_DISCONNECT
+ : $deny eq 'temp_disconnect' ? DENYSOFT_DISCONNECT
+ : $default;
+};
+
sub _register_standard_hooks {
my ($plugin, $qp) = @_;

0 comments on commit cbd1be7

Please sign in to comment.