From 63dc98ee1d7bc23baa2567f2da7ad188f38d70d1 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 2 Feb 2017 14:23:50 +0100 Subject: [PATCH] =?utf8?q?SL::Mailer:=20Kosmetik=20f=C3=BCr=20bessere=20Le?= =?utf8?q?sbarkeit=20(Alignment,=20Leerzeichen,=20Einr=C3=BCckung)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Mailer.pm | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/SL/Mailer.pm b/SL/Mailer.pm index 6bb351701..b8b8b1775 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; } -- 2.20.1