diff --git a/lib/Qpsmtpd/SMTP.pm b/lib/Qpsmtpd/SMTP.pm index c420215..0ebc4de 100644 --- a/lib/Qpsmtpd/SMTP.pm +++ b/lib/Qpsmtpd/SMTP.pm @@ -135,7 +135,7 @@ sub transaction { sub reset_transaction { my $self = shift; $self->run_hooks("reset_transaction") if $self->{_transaction}; - return $self->{_transaction} = Qpsmtpd::Transaction->new(); + return $self->{_transaction} = Qpsmtpd::Transaction->new(connection => $self->connection); } diff --git a/lib/Qpsmtpd/TcpServer/Prefork.pm b/lib/Qpsmtpd/TcpServer/Prefork.pm index 71aa221..cd2dac5 100644 --- a/lib/Qpsmtpd/TcpServer/Prefork.pm +++ b/lib/Qpsmtpd/TcpServer/Prefork.pm @@ -12,7 +12,7 @@ sub start_connection { #reset info $self->{_connection} = Qpsmtpd::Connection->new(); #reset connection - $self->{_transaction} = Qpsmtpd::Transaction->new(); #reset transaction + $self->reset_transaction; $self->SUPER::start_connection(@_); } diff --git a/lib/Qpsmtpd/Transaction.pm b/lib/Qpsmtpd/Transaction.pm index 6cfaed4..2abc735 100644 --- a/lib/Qpsmtpd/Transaction.pm +++ b/lib/Qpsmtpd/Transaction.pm @@ -4,6 +4,8 @@ use Qpsmtpd; use strict; use Qpsmtpd::Utils; use Qpsmtpd::Constants; +use Socket qw(inet_aton); +use Time::HiRes qw(time); use IO::File qw(O_RDWR O_CREAT); @@ -13,11 +15,23 @@ sub start { my $proto = shift; my $class = ref($proto) || $proto; my %args = @_; - my $self = { _rcpt => [], started => time }; + + # generate id + my $conn = $args{connection}; + my $ip = $conn->local_port || "0"; + my $start = time; + my $id = "$start.$$.$ip"; + + my $self = { _rcpt => [], started => $start, _id => $id }; bless ($self, $class); return $self; } +sub id { + my $self = shift; + $self->{_id}; +} + sub add_recipient { my $self = shift; @_ and push @{$self->{_recipients}}, shift;