Subject: | Bug in datasend |
Date: | Fri, 8 Feb 2008 14:25:38 -0500 |
To: | bug-Net-SMTP-TLS [...] rt.cpan.org |
From: | Joseph DiPaolo <jdipaolo [...] rdpfoodservice.com> |
If the SMTP server you are attempting to send to doesn't accept a
large message in a single batch, your datasend method will just resend
the first section of the message over and over until the proper size
limit is reached.
The fix is to increment $offset by $w for each iteration of the loop
as such:
# send stuff over raw (for use as message body)
sub datasend {
my $cmd = shift;
my $arr = @_ == 1 && ref($_[0]) ? $_[0] : \@_;
my $line = join("" ,@$arr);
return 0 unless defined(fileno($cmd->{sock}));
my $last_ch = $cmd->{last_ch};
$last_ch = $cmd->{last_ch} = "\012" unless defined $last_ch;
return 1 unless length $line;
$line =~ tr/\r\n/\015\012/ unless "\r" eq "\015";
my $first_ch = '';
if ($last_ch eq "\015") {
$first_ch = "\012" if $line =~ s/^\012//;
}
elsif ($last_ch eq "\012") {
$first_ch = "." if $line =~ /^\./;
}
$line =~ s/\015?\012(\.?)/\015\012$1$1/sg;
substr($line,0,0) = $first_ch;
$cmd->{last_ch} = substr($line,-1,1);
my $len = length($line);
my $offset = 0;
my $win = "";
vec($win,fileno($cmd->{sock}),1) = 1;
my $timeout = $cmd->{sock}->timeout || undef;
local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS';
print "Printing arr\n";
print $line."\n";
print "Done Printing arr\n";
while($len)
{
my $wout;
if (select(undef,$wout=$win, undef, $timeout) > 0 or -f $cmd-
Show quoted text
>{sock}) # -f for testing on win32
{
my $w = syswrite($cmd->{sock}, $line, $len, $offset);
unless (defined($w))
{
carp("Error: $!");
return undef;
}
$len -= $w;
$offset += $w; #BUG FIX;
}
else
{
carp("Error: Timeout");
return undef;
}
}
}
---------------------------------------------------
Joseph DiPaolo
I.T. Manager
RDP Foodservice
jdipaolo@rdpfoodservice.com