Tripletail
view release on metacpan or search on metacpan
lib/Tripletail/Sendmail/MailQueue.pm view on Meta::CPAN
# -----------------------------------------------------------------------------
# Tripletail::Sendmail::MailQueue - ç¬èªã®ã¡ã¼ã«ãã¥ã¼ã使ç¨ããã¡ã¼ã«éä¿¡
# -----------------------------------------------------------------------------
package Tripletail::Sendmail::MailQueue;
use base 'Tripletail::Sendmail';
use strict;
use warnings;
use Tripletail;
use Tripletail::Sendmail::Smtp;
use Unicode::Japanese ();
our $QUEUE_ID_COUNT = 0;
1;
sub _new {
my $class = shift;
my $group = shift;
my $this = bless {} => $class;
local($_);
$this->{queuedir} = do {
my $queuedir = $TL->INI->get($group => 'queuedir');
$queuedir =~ s!/+$!!; # æ«å°¾ã® / ãæ¶ã
$queuedir;
};
$this->{group} = $group;
$this->{smtp} = Tripletail::Sendmail::Smtp->_new($group);
$this->{erroraddr} = $TL->INI->get($group => 'erroraddr' => undef);
$this->{errorlog} = $TL->INI->get($group => 'errorlog' => undef);
$this->{host} = $TL->INI->get($group => 'host');
if(defined($_ = $TL->INI->get($group => 'timeout' => undef))) {
$this->{smtp}->setTimeout($_);
}
$this;
}
sub setTimeout {
my $this = shift;
$this->{smtp}->setTimeout(@_);
}
sub send {
my $this = shift;
my $data = $this->_getoptSend(@_);
my $fname = sprintf 'TL-%d-%d-%d', time, $$, $QUEUE_ID_COUNT++;
my $infile = "$this->{queuedir}/incoming/$fname";
my $queuefile = "$this->{queuedir}/queue/$fname";
open my $fh, '>', $infile
or die __PACKAGE__."#send: failed to write file [$infile] (ãã¡ã¤ã«ã«æ¸ãè¾¼ãã¾ãã)\n";
print $fh "$data->{from}\r\n";
foreach my $rcpt (@{$data->{rcpt}}) {
print $fh "$rcpt\r\n";
}
print $fh "\r\n";
$data->{data} =~ s/\r?\n|\r/\r\n/g;
print $fh $data->{data};
close $fh;
rename $infile => $queuefile
or die __PACKAGE__."#send: failed to rename [$infile] => [$queuefile] (ãªãã¼ã ã§ãã¾ãã)\n";
$this;
}
sub process {
my $this = shift;
local($_);
( run in 0.538 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )