Bei Verwendung von SMTP nicht doppelt nach UTF-8 encoden
[kivitendo-erp.git] / SL / Mailer / Sendmail.pm
1 package SL::Mailer::Sendmail;
2
3 use strict;
4
5 use IO::File;
6 use SL::Template;
7
8 use parent qw(Rose::Object);
9
10 use Rose::Object::MakeMethods::Generic
11 (
12   scalar => [ qw(myconfig mailer form) ]
13 );
14
15 sub init {
16   my ($self) = @_;
17
18   Rose::Object::init(@_);
19
20   my $email         =  $self->mailer->recode($self->myconfig->{email});
21   $email            =~ s/[^\w\.\-\+=@]//ig;
22
23   my %temp_form     = ( %{ $self->form }, myconfig_email => $email );
24   my $template      = SL::Template::create(type => 'ShellCommand', form => \%temp_form);
25   my $sendmail      = $::lx_office_conf{applications}->{sendmail} || $::lx_office_conf{mail_delivery}->{sendmail} || "sendmail -t";
26   $sendmail         = $template->parse_block($sendmail);
27
28   $self->{sendmail} = IO::File->new("|$sendmail") || die "sendmail($sendmail): $!";
29   $self->{sendmail}->binmode(':utf8') if $::locale->is_utf8;
30 }
31
32 sub start_mail {
33 }
34
35 sub print {
36   my $self = shift;
37
38   $self->{sendmail}->print(@_);
39 }
40
41 sub send {
42   my ($self) = @_;
43   $self->{sendmail}->close;
44   delete $self->{sendmail};
45 }
46
47 sub keep_from_header {
48   0;
49 }
50
51 1;