kivitendo/SL/Mailer/Sendmail.pm @ e592e0bc
5896d8bf | Moritz Bunkus | package SL::Mailer::Sendmail;
|
||
use strict;
|
||||
93b7fa24 | Moritz Bunkus | use Encode;
|
||
5896d8bf | Moritz Bunkus | use IO::File;
|
||
use SL::Template;
|
||||
use parent qw(Rose::Object);
|
||||
use Rose::Object::MakeMethods::Generic
|
||||
(
|
||||
24ab7ec0 | Moritz Bunkus | scalar => [ qw(myconfig mailer form status extended_status) ]
|
||
5896d8bf | Moritz Bunkus | );
|
||
sub init {
|
||||
my ($self) = @_;
|
||||
24ab7ec0 | Moritz Bunkus | Rose::Object::init(
|
||
@_,
|
||||
status => 'failed',
|
||||
extended_status => 'no send attempt made',
|
||||
);
|
||||
5896d8bf | Moritz Bunkus | |||
dbda14c2 | Moritz Bunkus | my $email = Encode::encode('utf-8', $self->myconfig->{email});
|
||
5896d8bf | Moritz Bunkus | $email =~ s/[^\w\.\-\+=@]//ig;
|
||
my %temp_form = ( %{ $self->form }, myconfig_email => $email );
|
||||
my $template = SL::Template::create(type => 'ShellCommand', form => \%temp_form);
|
||||
my $sendmail = $::lx_office_conf{applications}->{sendmail} || $::lx_office_conf{mail_delivery}->{sendmail} || "sendmail -t";
|
||||
$sendmail = $template->parse_block($sendmail);
|
||||
24ab7ec0 | Moritz Bunkus | $self->{sendmail} = IO::File->new("|$sendmail") or do { $self->extended_status("sendmail($sendmail): $!"); die $self->extended_status; };
|
||
dbda14c2 | Moritz Bunkus | $self->{sendmail}->binmode(':utf8');
|
||
5896d8bf | Moritz Bunkus | }
|
||
sub start_mail {
|
||||
}
|
||||
sub print {
|
||||
my $self = shift;
|
||||
24ab7ec0 | Moritz Bunkus | $self->{sendmail}->print(@_) or do { $self->extended_status("sendmail: $!"); die $self->extended_status; };
|
||
5896d8bf | Moritz Bunkus | }
|
||
sub send {
|
||||
my ($self) = @_;
|
||||
24ab7ec0 | Moritz Bunkus | |||
$self->{sendmail}->close or do { $self->extended_status("sendmail: $!"); die $self->extended_status; };
|
||||
$self->status('ok');
|
||||
$self->extended_status('');
|
||||
5896d8bf | Moritz Bunkus | delete $self->{sendmail};
|
||
}
|
||||
sub keep_from_header {
|
||||
0;
|
||||
}
|
||||
1;
|