| 1 | package Net::Server::Mail::ESMTP::PIPELINING; | ||
| 2 | |||
| 3 | use 5.006; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use base 'Net::Server::Mail::ESMTP::Extension'; | ||
| 7 | use constant GROUP_COMMANDS => [qw(RSET MAIL SEND SOML SAML RCPT)]; | ||
| 8 | use Scalar::Util qw(weaken); | ||
| 9 | |||
| 10 | our $VERSION = 0.26; | ||
| 11 | |||
| 12 | sub init { | ||
| 13 | my ( $self, $parent ) = @_; | ||
| 14 | $self->{parent} = $parent; | ||
| 15 | weaken( $self->{parent} ); | ||
| 16 | return $self; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub extend_mode { | ||
| 20 | my ( $self, $mode ) = @_; | ||
| 21 | if ($mode) { | ||
| 22 | $self->{old_process_operation} = $self->{parent}->{process_operation}; | ||
| 23 | $self->{parent}->{process_operation} = \&process_operation; | ||
| 24 | $self->{old_handle_more} = $self->{parent}->{data_handle_more_data}; | ||
| 25 | $self->{parent}->{data_handle_more_data} = 1; | ||
| 26 | } | ||
| 27 | else { | ||
| 28 | if ( exists( $self->{old_process_operation} ) ) { | ||
| 29 | $self->{parent}->{process_operation} = | ||
| 30 | $self->{old_process_operation}; | ||
| 31 | } | ||
| 32 | if ( exists( $self->{old_handle_more} ) ) { | ||
| 33 | $self->{parent}->{data_handle_more_data} = $self->{old_handle_more}; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | sub process_operation { | ||
| 39 | my ( $self, $operation ) = @_; | ||
| 40 | my @commands = grep( length $_, split( /\r?\n/, $operation ) ); | ||
| 41 | for ( my $i = 0 ; $i <= $#commands ; $i++ ) { | ||
| 42 | my ( $verb, $params ) = $self->tokenize_command( $commands[$i] ); | ||
| 43 | |||
| 44 | # Once the client SMTP has confirmed that support exists for | ||
| 45 | # the pipelining extension, the client SMTP may then elect to | ||
| 46 | # transmit groups of SMTP commands in batches without waiting | ||
| 47 | # for a response to each individual command. In particular, | ||
| 48 | # the commands RSET, MAIL FROM, SEND FROM, SOML FROM, SAML | ||
| 49 | # FROM, and RCPT TO can all appear anywhere in a pipelined | ||
| 50 | # command group. The EHLO, DATA, VRFY, EXPN, TURN, QUIT, and | ||
| 51 | # NOOP commands can only appear as the last command in a group | ||
| 52 | # since their success or failure produces a change of state | ||
| 53 | # which the client SMTP must accommodate. (NOOP is included in | ||
| 54 | # this group so it can be used as a synchronization point.) | ||
| 55 | if ( $i < $#commands && not grep( $verb eq $_, @{ (GROUP_COMMANDS) } ) ) | ||
| 56 | { | ||
| 57 | $self->reply( 550, | ||
| 58 | "Protocol error: `$verb' not allowed in a group of commands" ); | ||
| 59 | return; | ||
| 60 | } | ||
| 61 | |||
| 62 | my $rv = $self->process_command( $verb, $params ); | ||
| 63 | return $rv if defined $rv; | ||
| 64 | } | ||
| 65 | return; | ||
| 66 | } | ||
| 67 | |||
| 68 | sub keyword { | ||
| 69 | return 'PIPELINING'; | ||
| 70 | } | ||
| 71 | |||
| 72 | 1; |