From: Jason Mills <jmmi...@cpan.org>

 id() is hex a representation of remote_ip, remote_port and time of creation.


Signed-off-by: Jason Mills <jmmi...@cpan.org>
---
 lib/Qpsmtpd/Connection.pm |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/lib/Qpsmtpd/Connection.pm b/lib/Qpsmtpd/Connection.pm
index 22ed704..d0748a6 100644
--- a/lib/Qpsmtpd/Connection.pm
+++ b/lib/Qpsmtpd/Connection.pm
@@ -52,6 +52,21 @@ sub clone {
   return $new;
 }
 
+sub id {
+  my $self = shift;
+  
+  return $self->{_id} if $self->{_id} || !$self->remote_ip;
+  
+  my @ip = split( /\./, $self->remote_ip ) or return;
+  my $port = $self->remote_port or return;
+  my $time = time;
+  
+  return $self->{_id} ||= sprintf(
+    "%02x%02x%02x%02x%04x%08x", @ip, $port, $time
+  );
+
+}
+
 sub remote_host {
   my $self = shift;
   @_ and $self->{_remote_host} = shift;
-- 
1.6.0.4

Reply via email to