Qpsmtpd::Transaction: add body_fh(), body_length() and data_size(),
depreceated body_size() git-svn-id: https://svn.perl.org/qpsmtpd/branches/0.3x@689 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
469c01a1f4
commit
ad541f6207
4
Changes
4
Changes
@ -1,4 +1,8 @@
|
|||||||
0.3x
|
0.3x
|
||||||
|
The ill-named $transaction->body_size() is depreceated now, use
|
||||||
|
$transaction->data_size() instead. Check your logs for LOGWARN messages
|
||||||
|
about "body_size" and fix your plugins. (Hanno Hecker)
|
||||||
|
|
||||||
Instead of failing with cryptic message, ignore lines in config/plugins
|
Instead of failing with cryptic message, ignore lines in config/plugins
|
||||||
for uninstalled plugins. (John Peacock)
|
for uninstalled plugins. (John Peacock)
|
||||||
|
|
||||||
|
@ -141,10 +141,23 @@ sub body_write {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub body_size {
|
sub body_size { # depreceated, use data_size() instead
|
||||||
|
my $self = shift;
|
||||||
|
$self->log(LOGWARN, "WARNING: body_size() is depreceated, use data_size() instead");
|
||||||
|
$self->{_body_size} || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub data_size {
|
||||||
shift->{_body_size} || 0;
|
shift->{_body_size} || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub body_length {
|
||||||
|
my $self = shift;
|
||||||
|
$self->{_body_size} or return 0;
|
||||||
|
$self->{_header_size} or return 0;
|
||||||
|
return $self->{_body_size} - $self->{_header_size};
|
||||||
|
}
|
||||||
|
|
||||||
sub body_resetpos {
|
sub body_resetpos {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
@ -190,6 +203,10 @@ sub body_as_string {
|
|||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub body_fh {
|
||||||
|
return shift->{_body_file};
|
||||||
|
}
|
||||||
|
|
||||||
sub DESTROY {
|
sub DESTROY {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
# would we save some disk flushing if we unlinked the file before
|
# would we save some disk flushing if we unlinked the file before
|
||||||
@ -294,6 +311,11 @@ use the notes field in the C<Qpsmtpd::Connection> object instead.
|
|||||||
Returns the temporary filename used to store the message contents; useful for
|
Returns the temporary filename used to store the message contents; useful for
|
||||||
virus scanners so that an additional copy doesn't need to be made.
|
virus scanners so that an additional copy doesn't need to be made.
|
||||||
|
|
||||||
|
Calling C<body_filename()> also forces spooling to disk. A message is not
|
||||||
|
spooled to disk if it's size is smaller than
|
||||||
|
I<$self-E<gt>config("size_threshold")>, default threshold is 0, the sample
|
||||||
|
config file sets this to 10000.
|
||||||
|
|
||||||
=head2 body_write( $data )
|
=head2 body_write( $data )
|
||||||
|
|
||||||
Write data to the end of the email.
|
Write data to the end of the email.
|
||||||
@ -302,7 +324,26 @@ C<$data> can be either a plain scalar, or a reference to a scalar.
|
|||||||
|
|
||||||
=head2 body_size( )
|
=head2 body_size( )
|
||||||
|
|
||||||
Get the current size of the email.
|
B<Depreceated>, Use I<data_size()> instead.
|
||||||
|
|
||||||
|
=head2 data_size( )
|
||||||
|
|
||||||
|
Get the current size of the email. Note that this is not the size of the
|
||||||
|
message that will be queued, it is the size of what the client sent after
|
||||||
|
the C<DATA> command. If you need the size that will be queued, use
|
||||||
|
|
||||||
|
my $msg_len = length($transaction->header->as_string)
|
||||||
|
+ $transaction->body_length;
|
||||||
|
|
||||||
|
The line above is of course only valid in I<hook_queue( )>, as other plugins
|
||||||
|
may add headers and qpsmtpd will add it's I<Received:> header.
|
||||||
|
|
||||||
|
=head2 body_length( )
|
||||||
|
|
||||||
|
Get the current length of the body of the email. This length includes the
|
||||||
|
empty line between the headers and the body. Until the client has sent
|
||||||
|
some data of the body of the message (i.e. headers are finished and client
|
||||||
|
sent the empty line) this will return 0.
|
||||||
|
|
||||||
=head2 body_resetpos( )
|
=head2 body_resetpos( )
|
||||||
|
|
||||||
@ -316,6 +357,12 @@ file pointer.
|
|||||||
|
|
||||||
Returns a single line of data from the body of the email.
|
Returns a single line of data from the body of the email.
|
||||||
|
|
||||||
|
=head2 body_fh( )
|
||||||
|
|
||||||
|
Returns the file handle to the temporary file of the email. This will return
|
||||||
|
undef if the file is not opened (yet). In I<hook_data( )> or later you can
|
||||||
|
force spooling to disk by calling I<$transaction-E<gt>body_filename>.
|
||||||
|
|
||||||
=head1 SEE ALSO
|
=head1 SEE ALSO
|
||||||
|
|
||||||
L<Mail::Header>, L<Qpsmtpd::Address>, L<Qpsmtpd::Connection>
|
L<Mail::Header>, L<Qpsmtpd::Address>, L<Qpsmtpd::Connection>
|
||||||
|
@ -44,7 +44,7 @@ sub hook_data_post {
|
|||||||
my ($self, $transaction) = @_;
|
my ($self, $transaction) = @_;
|
||||||
|
|
||||||
return (DENY, "You have to send some data first")
|
return (DENY, "You have to send some data first")
|
||||||
if $transaction->body_size == 0;
|
if $transaction->data_size == 0;
|
||||||
|
|
||||||
return (DENY, "Mail with no From header not accepted here")
|
return (DENY, "Mail with no From header not accepted here")
|
||||||
unless $transaction->header->get('From');
|
unless $transaction->header->get('From');
|
||||||
|
@ -96,7 +96,7 @@ sub hook_data_post { # check_spam
|
|||||||
my ($self, $transaction) = @_;
|
my ($self, $transaction) = @_;
|
||||||
|
|
||||||
$self->log(LOGDEBUG, "check_spam");
|
$self->log(LOGDEBUG, "check_spam");
|
||||||
return (DECLINED) if $transaction->body_size > 500_000;
|
return (DECLINED) if $transaction->data_size > 500_000;
|
||||||
|
|
||||||
my $leave_old_headers = lc($self->{_args}->{leave_old_headers}) || 'rename';
|
my $leave_old_headers = lc($self->{_args}->{leave_old_headers}) || 'rename';
|
||||||
|
|
||||||
|
@ -80,10 +80,10 @@ sub register {
|
|||||||
sub hook_data_post {
|
sub hook_data_post {
|
||||||
my ( $self, $transaction ) = @_;
|
my ( $self, $transaction ) = @_;
|
||||||
|
|
||||||
if ( $transaction->body_size > $self->{"_bitd"}->{"max_size"} ) {
|
if ( $transaction->data_size > $self->{"_bitd"}->{"max_size"} ) {
|
||||||
$self->log( LOGWARN,
|
$self->log( LOGWARN,
|
||||||
'Mail too large to scan ('
|
'Mail too large to scan ('
|
||||||
. $transaction->body_size . " vs "
|
. $transaction->data_size . " vs "
|
||||||
. $self->{"_bitd"}->{"max_size"}
|
. $self->{"_bitd"}->{"max_size"}
|
||||||
. ")" );
|
. ")" );
|
||||||
return (DECLINED);
|
return (DECLINED);
|
||||||
|
@ -164,9 +164,9 @@ sub register {
|
|||||||
sub hook_data_post {
|
sub hook_data_post {
|
||||||
my ($self, $transaction) = @_;
|
my ($self, $transaction) = @_;
|
||||||
|
|
||||||
if ($transaction->body_size > $self->{_max_size}) {
|
if ($transaction->data_size > $self->{_max_size}) {
|
||||||
$self->log(LOGWARN, 'Mail too large to scan ('.
|
$self->log(LOGWARN, 'Mail too large to scan ('.
|
||||||
$transaction->body_size . " vs $self->{_max_size})" );
|
$transaction->data_size . " vs $self->{_max_size})" );
|
||||||
return (DECLINED);
|
return (DECLINED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ sub hook_data_post {
|
|||||||
my ( $self, $transaction ) = @_;
|
my ( $self, $transaction ) = @_;
|
||||||
$DB::single = 1;
|
$DB::single = 1;
|
||||||
|
|
||||||
if ( $transaction->body_size > $self->{"_clamd"}->{"max_size"} * 1024 ) {
|
if ( $transaction->data_size > $self->{"_clamd"}->{"max_size"} * 1024 ) {
|
||||||
$self->log( LOGNOTICE, "Declining due to body_size" );
|
$self->log( LOGNOTICE, "Declining due to data_size" );
|
||||||
return (DECLINED);
|
return (DECLINED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@ sub hook_data_post {
|
|||||||
|
|
||||||
# klez files are always sorta big .. how big? Dunno.
|
# klez files are always sorta big .. how big? Dunno.
|
||||||
return (DECLINED)
|
return (DECLINED)
|
||||||
if $transaction->body_size < 60_000;
|
if $transaction->data_size < 60_000;
|
||||||
# 220k was too little, so let's just disable the "big size check"
|
# 220k was too little, so let's just disable the "big size check"
|
||||||
# or $transaction->body_size > 1_000_000;
|
# or $transaction->data_size > 1_000_000;
|
||||||
|
|
||||||
# maybe it would be worthwhile to add a check for
|
# maybe it would be worthwhile to add a check for
|
||||||
# Content-Type: multipart/alternative; here?
|
# Content-Type: multipart/alternative; here?
|
||||||
|
@ -16,8 +16,8 @@ sub hook_data_post {
|
|||||||
my ( $self, $transaction ) = @_;
|
my ( $self, $transaction ) = @_;
|
||||||
$DB::single = 1;
|
$DB::single = 1;
|
||||||
|
|
||||||
if ( $transaction->body_size > $self->{"_sophie"}->{"max_size"} * 1024 ) {
|
if ( $transaction->data_size > $self->{"_sophie"}->{"max_size"} * 1024 ) {
|
||||||
$self->log( LOGNOTICE, "Declining due to body_size" );
|
$self->log( LOGNOTICE, "Declining due to data_size" );
|
||||||
return (DECLINED);
|
return (DECLINED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ sub hook_data_post {
|
|||||||
my ($self, $transaction) = @_;
|
my ($self, $transaction) = @_;
|
||||||
|
|
||||||
return (DECLINED)
|
return (DECLINED)
|
||||||
if $transaction->body_size > 250_000;
|
if $transaction->data_size > 250_000;
|
||||||
|
|
||||||
# Ignore non-multipart emails
|
# Ignore non-multipart emails
|
||||||
my $content_type = $transaction->header->get('Content-Type');
|
my $content_type = $transaction->header->get('Content-Type');
|
||||||
|
Loading…
Reference in New Issue
Block a user