about summary refs log tree commit
diff options
context:
space:
mode:
authorGraham Barr <gbarr@pobox.com>2003-05-20 10:46:04 +0000
committerGraham Barr <gbarr@pobox.com>2003-05-20 10:46:04 +0000
commitaf66d9d82d7887b6e37f566eeb8339d2e7788c03 (patch)
tree8c5b9176d98212dea9336fd6568fe5f7167efd6b
parent220861a053637f0e55f572c85221a275b710bc3f (diff)
downloadperl-libnet-af66d9d82d7887b6e37f566eeb8339d2e7788c03.tar.gz
Net::SMTP
- Make the use of email address extraction configurable. By default
it is now back how it was

-rw-r--r--Net/SMTP.pm43
1 files changed, 32 insertions, 11 deletions
diff --git a/Net/SMTP.pm b/Net/SMTP.pm
index 613d1db..960f537 100644
--- a/Net/SMTP.pm
+++ b/Net/SMTP.pm
@@ -16,7 +16,7 @@ use IO::Socket;
 use Net::Cmd;
 use Net::Config;
 
-$VERSION = "2.25"; # $Id: //depot/libnet/Net/SMTP.pm#26 $
+$VERSION = "2.26"; # $Id: //depot/libnet/Net/SMTP.pm#27 $
 
 @ISA = qw(Net::Cmd IO::Socket::INET);
 
@@ -56,6 +56,7 @@ sub new
    return undef;
   }
 
+ ${*$obj}{'net_smtp_exact_addr'} = $arg{ExactAddresses};
  ${*$obj}{'net_smtp_host'} = $host;
 
  (${*$obj}{'net_smtp_banner'}) = $obj->message;
@@ -183,16 +184,25 @@ sub supports {
 }
 
 sub _addr {
+  my $self = shift;
   my $addr = shift;
   $addr = "" unless defined $addr;
-  $addr =~ s/^\s*<?\s*|\s*>?\s*$//sg;
+
+  if (${*$self}{'net_smtp_exact_addr'}) {
+    return $1 if $addr =~ /^\s*(<.*>)\s*$/s;
+  }
+  else {
+    return $1 if $addr =~ /(<[^>]*>)/;
+    $addr =~ s/^\s+|\s+$//sg;
+  }
+
   "<$addr>";
 }
 
 sub mail
 {
  my $me = shift;
- my $addr = _addr(shift);
+ my $addr = _addr($me, shift);
  my $opts = "";
 
  if(@_)
@@ -244,7 +254,7 @@ sub mail
       {
        if(exists $esmtp->{CHECKPOINT})
         {
-         $opts .= " TRANSID=" . _addr($v);
+         $opts .= " TRANSID=" . _addr($me, $v);
         }
        else
         {
@@ -279,9 +289,9 @@ sub mail
  $me->_MAIL("FROM:".$addr.$opts);
 }
 
-sub send          { shift->_SEND("FROM:" . _addr($_[0])) }
-sub send_or_mail  { shift->_SOML("FROM:" . _addr($_[0])) }
-sub send_and_mail { shift->_SAML("FROM:" . _addr($_[0])) }
+sub send          { my $me = shift; $me->_SEND("FROM:" . _addr($me, $_[0])) }
+sub send_or_mail  { my $me = shift; $me->_SOML("FROM:" . _addr($me, $_[0])) }
+sub send_and_mail { my $me = shift; $me->_SAML("FROM:" . _addr($me, $_[0])) }
 
 sub reset
 {
@@ -338,7 +348,7 @@ sub recipient
  my $addr;
  foreach $addr (@_)
   {
-    if($smtp->_RCPT("TO:" . _addr($addr) . $opts)) {
+    if($smtp->_RCPT("TO:" . _addr($smtp, $addr) . $opts)) {
       push(@ok,$addr) if $skip_bad;
     }
     elsif(!$skip_bad) {
@@ -510,6 +520,10 @@ to IO::Socket to allow binding the socket to a local port.
 B<Timeout> - Maximum time, in seconds, to wait for a response from the
 SMTP server (default: 120)
 
+B<ExactAddresses> - If true the all ADDRESS arguments must be as
+defined by C<addr-spec> in RFC2822. If not given, or false, then
+Net::SMTP will attempt to extract the address from the value passed.
+
 B<Debug> - Enable debugging information
 
 
@@ -650,8 +664,15 @@ Send the QUIT command to the remote SMTP server and close the socket connection.
 
 =head1 ADDRESSES
 
-All methods that accept addresses expect the address to be a valid rfc2821-quoted address, although
-Net::SMTP will accept accept the address surrounded by angle brackets.
+Net::SMTP attempts to DWIM with addresses that are passed. For
+example an application might extract The From: line from an email
+and pass that to mail(). While this may work, it is not reccomended.
+The application should really use a module like L<Mail::Address>
+to extract the mail address and pass that.
+
+If C<ExactAddresses> is passed to the contructor, then addresses
+should be a valid rfc2821-quoted address, although Net::SMTP will
+accept accept the address surrounded by angle brackets.
 
  funny user@domain      WRONG
  "funny user"@domain    RIGHT, recommended
@@ -673,6 +694,6 @@ it under the same terms as Perl itself.
 
 =for html <hr>
 
-I<$Id: //depot/libnet/Net/SMTP.pm#26 $>
+I<$Id: //depot/libnet/Net/SMTP.pm#27 $>
 
 =cut