X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/a40f0c2f7523a7d6936ca483901c22dfe86358c9..5ce99992a783b03eca2a382fe76a6e01d7ad724f:/SL/Mailer.pm diff --git a/SL/Mailer.pm b/SL/Mailer.pm index 6bb351701..abc25f7ce 100644 --- a/SL/Mailer.pm +++ b/SL/Mailer.pm @@ -137,11 +137,12 @@ sub _create_attachment_part { Encoding => 'base64', ); - my $file_id = 0; my $attachment_content; + my $file_id = 0; my $email_journal = $::instance_conf->get_email_journal; - $main::lxdebug->message(LXDebug->DEBUG2(), "mail5 att=".$attachment." email_journal=". $email_journal." id=".$attachment->{id}); + $::lxdebug->message(LXDebug->DEBUG2(), "mail5 att=" . $attachment . " email_journal=" . $email_journal . " id=" . $attachment->{id}); + if (ref($attachment) eq "HASH") { $attributes{Path} = $attachment->{path} || $attachment->{filename}; $attributes{Filename} = $attachment->{name}; @@ -164,48 +165,51 @@ sub _create_attachment_part { } return undef if $email_journal > 1 && !defined $attachment_content; - $attachment_content ||= ' '; - $main::lxdebug->message(LXDebug->DEBUG2(), "mail6 mtype=".$attributes{Type}." path=". - $attributes{Path}." filename=".$attributes{Filename}); -# $attributes{Charset} = $self->{charset} if lc $application eq 'text' && $self->{charset}; + $attachment_content ||= ' '; $attributes{Charset} = $self->{charset} if $self->{charset}; + $::lxdebug->message(LXDebug->DEBUG2(), "mail6 mtype=" . $attributes{Type} . " path=" . $attributes{Path} . " filename=" . $attributes{Filename}); + my $ent; if ( $attributes{Type} eq 'message/rfc822' ) { - my $fh = IO::File->new($attributes{Path}, "r"); - if (! defined $fh) { - return undef; - } - $ent = $parser->parse($fh); - undef $fh; - my $head = $ent->head; - $head->replace('Content-disposition','attachment; filename='.$attributes{Filename}); + my $fh = IO::File->new($attributes{Path}, "r") or return undef; + $ent = $parser->parse($fh); + + $ent->head->replace('Content-disposition','attachment; filename='.$attributes{Filename}); + } else { $ent = MIME::Entity->build(%attributes); } + push @{ $self->{mail_attachments}} , SL::DB::EmailJournalAttachment->new( name => $attributes{Filename}, mime_type => $attributes{Type}, content => ( $email_journal > 1 ? $attachment_content : ' '), file_id => $file_id, ); + return $ent; } sub _create_message { my ($self) = @_; - push @{ $self->{headers} }, ('Type' =>"multipart/mixed" ); - my $top = MIME::Entity->build(@{$self->{headers}}); + push @{ $self->{headers} }, (Type => "multipart/mixed"); + + my $top = MIME::Entity->build(@{$self->{headers}}); + if ($self->{message}) { - $top->attach(Data => encode($self->{charset},$self->{message}), - Charset => $self->{charset}, - Type => $self->{contenttype}, - Encoding => 'quoted-printable'); + $top->attach( + Data => encode($self->{charset},$self->{message}), + Charset => $self->{charset}, + Type => $self->{contenttype}, + Encoding => 'quoted-printable', + ); } - map { $top->add_part($self->_create_attachment_part($_)) } @{ $self->{attachments} || [] }; + $top->add_part($self->_create_attachment_part($_)) for @{ $self->{attachments} || [] }; + return $top; } @@ -241,7 +245,9 @@ sub send { #$::lxdebug->message(0, "message: " . $email->as_string); # return "boom"; - $self->{driver}->start_mail(from => encode('MIME-Header',$self->{from}), to => [ $self->_all_recipients ]); + my $from_obj = (Email::Address->parse($self->{from}))[0]; + + $self->{driver}->start_mail(from => $from_obj->address, to => [ $self->_all_recipients ]); $self->{driver}->print($email->as_string); $self->{driver}->send;