GetWeb
view release on metacpan or search on metacpan
MailBot/UI/Spool.pm view on Meta::CPAN
while (1)
{
my @stat = stat($mailSpool);
my $size = $stat[7];
if ($size > 1)
{
my $cmd = $config -> getIniVal('spool','get');
$cmd =~ s/\$localSpool/$localSpool/g;
my $mailStatus = `$cmd`;
#my $mailStatus = `/bin/echo 's * $localSpool' | /usr/bin/Mail -n`;
if ($? << 8)
{
if ($mailStatus =~ /no mail for/i)
{
sleep $sleep;
next;
}
die "Mail command returned nonzero: $mailStatus";
}
# print STDERR "status: $mailStatus";
return $localSpool;
}
sleep $sleep;
}
}
sub vGetMessage
{
my $self = shift;
my $spool = $self -> waitForSpool;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat($spool);
$size > 400000 and die "spool too long";
open(SPOOL,$spool) or die "could not open spool: $!";
flock(SPOOL,2); # exclusive lock
my @message = ();
my $line = <SPOOL>;
$line =~ /^From / or die "$spool is not a mail spool";
push(@message,$line);
while ($line = <SPOOL>)
{
last if $line =~ /^From /;
push(@message,$line);
}
if (defined $line)
{
my $spoolNew = "$spool.new";
open(SPOOL_NEW,">$spoolNew") or die "could not create $spoolNew: $!";
print SPOOL_NEW $line;
while ($line = <SPOOL>)
{
print SPOOL_NEW $line;
}
close(SPOOL_NEW) or die "could not write to $spoolNew: $!";
# chmod($mode,$spoolNew) or die "could not chmod $spoolNew: $!";
# chown($uid,$gid,$spoolNew) or die "could not chown $spoolNew: $!";
rename($spoolNew,$spool) or
die "could not rename $spool to $spoolNew: $!";
}
else
{
unlink($spool) or die "could not delete $spool: $!";
}
my $message = new Mail::Internet(@message);
$self -> analyzeMessage($message);
}
( run in 2.191 seconds using v1.01-cache-2.11-cpan-71847e10f99 )