Update Dokumentation
[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) ]
14 );
15
16 sub init {
17   my ($self) = @_;
18
19   Rose::Object::init(@_);
20
21   my $email         =  Encode::encode('utf-8', $self->myconfig->{email});
22   $email            =~ s/[^\w\.\-\+=@]//ig;
23
24   my %temp_form     = ( %{ $self->form }, myconfig_email => $email );
25   my $template      = SL::Template::create(type => 'ShellCommand', form => \%temp_form);
26   my $sendmail      = $::lx_office_conf{applications}->{sendmail} || $::lx_office_conf{mail_delivery}->{sendmail} || "sendmail -t";
27   $sendmail         = $template->parse_block($sendmail);
28
29   $self->{sendmail} = IO::File->new("|$sendmail") || die "sendmail($sendmail): $!";
30   $self->{sendmail}->binmode(':utf8');
31 }
32
33 sub start_mail {
34 }
35
36 sub print {
37   my $self = shift;
38
39   $self->{sendmail}->print(@_);
40 }
41
42 sub send {
43   my ($self) = @_;
44   $self->{sendmail}->close;
45   delete $self->{sendmail};
46 }
47
48 sub keep_from_header {
49   0;
50 }
51
52 1;