Part Controller - falschen Code aus kivi.Order.js wieder entfernt
[kivitendo-erp.git] / SL / Mailer / Sendmail.pm
1 package SL::Mailer::Sendmail;
2
3 use strict;
4
5 use Encode;
6 use IO::File;
7 use SL::Template;
8
9 use parent qw(Rose::Object);
10
11 use Rose::Object::MakeMethods::Generic
12 (
13   scalar => [ qw(myconfig mailer form status extended_status) ]
14 );
15
16 sub init {
17   my ($self) = @_;
18
19   Rose::Object::init(
20     @_,
21     status          => 'failed',
22     extended_status => 'no send attempt made',
23   );
24
25   my $email         =  Encode::encode('utf-8', $self->myconfig->{email});
26   $email            =~ s/[^\w\.\-\+=@]//ig;
27
28   my %temp_form     = ( %{ $self->form }, myconfig_email => $email );
29   my $template      = SL::Template::create(type => 'ShellCommand', form => \%temp_form);
30   my $sendmail      = $::lx_office_conf{applications}->{sendmail} || $::lx_office_conf{mail_delivery}->{sendmail} || "sendmail -t";
31   $sendmail         = $template->parse_block($sendmail);
32
33   $self->{sendmail} = IO::File->new("|$sendmail") or do { $self->extended_status("sendmail($sendmail): $!"); die $self->extended_status; };
34   $self->{sendmail}->binmode(':utf8');
35 }
36
37 sub start_mail {
38 }
39
40 sub print {
41   my $self = shift;
42
43   $self->{sendmail}->print(@_) or do { $self->extended_status("sendmail: $!"); die $self->extended_status; };
44 }
45
46 sub send {
47   my ($self) = @_;
48
49   $self->{sendmail}->close or do { $self->extended_status("sendmail: $!"); die $self->extended_status; };
50
51   $self->status('ok');
52   $self->extended_status('');
53
54   delete $self->{sendmail};
55 }
56
57 sub keep_from_header {
58   0;
59 }
60
61 1;