Greetings,
I wrote a plugin to limit the size of messages allowed through Qpsmtpd.
It's crude, waiting for the message to be spooled to disk, but I
didn't see a way of grabbing the body size before the transaction object
was created. Perhaps someone here can enlighten me.
Anyway, this was inspired by my friends who were using my email server
to trade large music files back in forth (since I host their email for
free of course :) ). Here's a copy of the source, and a link to the
subversion repo. Feedback welcome.
- Fred
https://www.redhotpenguin.com/svn/qpsmtpd/plugins/size_matters
=head1 NAME
size_matters - Reject emails that are too big
=head1 DESCRIPTION
Plugin that rejects emails which are too large. Inspired by my friends
whose email I host and who have a penchant for trading music via email.
=head1 CONFIG
Configure your plugin as so in config/plugins:
size_matters limit size_in_bytes
=head1 TODO
=over 4
=item *
Reject the email before it's spooled to disk if it's too big.
=back
=head1 AUTHOR
Fred Moyer <[EMAIL PROTECTED]>
=head1 COPYRIGHT AND LICENSE
Copyright 2006 Fred Moyer
This plugin is licensed under the same terms as the qpsmtpd package itself.
Please see the LICENSE file included with qpsmtpd for details.
=cut
sub register {
my ( $self, $qp, @args ) = @_;
$self->log( LOGERROR, "Bad parameters for the size_matters plugin" )
if @_ % 2;
%{ $self->{_args} } = @args;
}
sub hook_data_post {
my ( $self, $transaction ) = @_;
$self->log( LOGDEBUG, "Body size is ", $transaction->body_size );
return ( DENY,
sprintf(
"The email is %.2f MB and the limit is %.2f MB :(",
( $transaction->body_size / ( 1024 * 1024 ) ),
( $self->{_args}->{limit} / ( 1024 * 1024 ) )
)
)
if $transaction->body_size > $self->{_args}->{limit};
return (DECLINED);
}