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#31 $
@ISA = qw(Net::Cmd IO::Socket::INET);
my $type = ref($self) || $self;
my $host = shift if @_ % 2;
my %arg = @_;
- my $hosts = defined $host ? [ $host ] : $NetConfig{smtp_hosts};
+ my $hosts = defined $host ? $host : $NetConfig{smtp_hosts};
my $obj;
my $h;
- foreach $h (@{$hosts})
+ foreach $h (@{ref($hosts) ? $hosts : [ $hosts ]})
{
$obj = $type->SUPER::new(PeerAddr => ($host = $h),
PeerPort => $arg{Port} || 'smtp(25)',
return undef;
}
+ ${*$obj}{'net_smtp_exact_addr'} = $arg{ExactAddresses};
${*$obj}{'net_smtp_host'} = $host;
(${*$obj}{'net_smtp_banner'}) = $obj->message;
if $ok = $me->_HELO($domain);
}
- $ok && $msg[0] =~ /\A\s*(\S+)/
- ? $1
- : undef;
+ return undef unless $ok;
+
+ $msg[0] =~ /\A\s*(\S+)/;
+ return ($1 || " ");
}
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(@_)
{
if(exists $esmtp->{DSN})
{
- $opts .= " RET=" . uc $v
+ $opts .= " RET=" . ((uc($v) eq "FULL") ? "FULL" : "HDRS");
}
else
{
if(defined($v = delete $opt{Bits}))
{
- if(exists $esmtp->{'8BITMIME'})
+ if($v eq "8")
+ {
+ if(exists $esmtp->{'8BITMIME'})
+ {
+ $opts .= " BODY=8BITMIME";
+ }
+ else
+ {
+ carp 'Net::SMTP::mail: 8BITMIME option not supported by host';
+ }
+ }
+ elsif($v eq "binary")
+ {
+ if(exists $esmtp->{'BINARYMIME'} && exists $esmtp->{'CHUNKING'})
+ {
+ $opts .= " BODY=BINARYMIME";
+ ${*$me}{'net_smtp_chunking'} = 1;
+ }
+ else
+ {
+ carp 'Net::SMTP::mail: BINARYMIME option not supported by host';
+ }
+ }
+ elsif(exists $esmtp->{'8BITMIME'} or exists $esmtp->{'BINARYMIME'})
{
- $opts .= $v == 8 ? " BODY=8BITMIME" : " BODY=7BIT"
+ $opts .= " BODY=7BIT";
}
else
{
- carp 'Net::SMTP::mail: 8BITMIME option not supported by host';
+ carp 'Net::SMTP::mail: 8BITMIME and BINARYMIME options not supported by host';
}
}
{
if(exists $esmtp->{CHECKPOINT})
{
- $opts .= " TRANSID=" . _addr($v);
+ $opts .= " TRANSID=" . _addr($me, $v);
}
else
{
$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
{
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) {
{
my $me = shift;
- my $ok = $me->_DATA() && $me->datasend(@_);
+ if(exists ${*$me}{'net_smtp_chunking'})
+ {
+ carp 'Net::SMTP::data: CHUNKING extension in use, must call bdat instead';
+ }
+ else
+ {
+ my $ok = $me->_DATA() && $me->datasend(@_);
+
+ $ok && @_ ? $me->dataend
+ : $ok;
+ }
+}
+
+sub bdat
+{
+ my $me = shift;
+
+ if(exists ${*$me}{'net_smtp_chunking'})
+ {
+ my $data = shift;
- $ok && @_ ? $me->dataend
- : $ok;
+ $me->_BDAT(length $data) && $me->rawdatasend($data) &&
+ $me->response() == CMD_OK;
+ }
+ else
+ {
+ carp 'Net::SMTP::bdat: CHUNKING extension is not in use, call data instead';
+ }
+}
+
+sub bdatlast
+{
+ my $me = shift;
+
+ if(exists ${*$me}{'net_smtp_chunking'})
+ {
+ my $data = shift;
+
+ $me->_BDAT(length $data, "LAST") && $me->rawdatasend($data) &&
+ $me->response() == CMD_OK;
+ }
+ else
+ {
+ carp 'Net::SMTP::bdat: CHUNKING extension is not in use, call data instead';
+ }
}
sub datafh {
sub _NOOP { shift->command("NOOP")->response() == CMD_OK }
sub _QUIT { shift->command("QUIT")->response() == CMD_OK }
sub _DATA { shift->command("DATA")->response() == CMD_MORE }
+sub _BDAT { shift->command("BDAT", @_) }
sub _TURN { shift->unsupported(@_); }
sub _ETRN { shift->command("ETRN", @_)->response() == CMD_OK }
sub _AUTH { shift->command("AUTH", @_)->response() == CMD_OK }
This is the constructor for a new Net::SMTP object. C<HOST> is the
name of the remote host to which an SMTP connection is required.
+If C<HOST> is an array reference then each value will be attempted
+in turn until a connection is made.
+
If C<HOST> is not given, then the C<SMTP_Host> specified in C<Net::Config>
will be used.
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
in hash like fashion, using key and value pairs. Possible options are:
Size => <bytes>
- Return => <???>
- Bits => "7" | "8"
+ Return => "FULL" | "HDRS"
+ Bits => "7" | "8" | "binary"
Transaction => <ADDRESS>
Envelope => <ENVID>
+The C<Return> and C<Envelope> parameters are used for DSN (Delivery
+Status Notification).
=item reset ()
=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
=for html <hr>
-I<$Id: //depot/libnet/Net/SMTP.pm#26 $>
+I<$Id: //depot/libnet/Net/SMTP.pm#31 $>
=cut