From: Moritz Bunkus Date: Wed, 31 Oct 2012 15:28:37 +0000 (+0100) Subject: Attachments via File::Slurp einlesen, nicht manuell X-Git-Tag: release-3.0.0beta1~63 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=e8c2a3b8e28d074bcbc3bfd4758b468ccea1e080;p=kivitendo-erp.git Attachments via File::Slurp einlesen, nicht manuell --- diff --git a/SL/Mailer.pm b/SL/Mailer.pm index dc3c662f0..cdfe9a401 100644 --- a/SL/Mailer.pm +++ b/SL/Mailer.pm @@ -32,6 +32,7 @@ package Mailer; use Email::Address; use Encode; +use File::Slurp; use SL::Common; use SL::MIME; @@ -205,17 +206,17 @@ Content-Type: $self->{contenttype}; charset="$self->{charset}" $filename =~ s/(.*\/|\Q$self->{fileid}\E)//g; } + my $attachment_content = eval { read_file($attachment) }; + if (!defined $attachment_content) { + $main::lxdebug->leave_sub(); + return "$attachment : $!"; + } + my $application = ($attachment =~ /(^\w+$)|\.(html|text|txt|sql)$/) ? "text" : "application"; my $content_type = SL::MIME->mime_type_from_ext($filename); $content_type = "${application}/$self->{format}" if (!$content_type && $self->{format}); $content_type ||= 'application/octet-stream'; - open(IN, $attachment); - if ($?) { - $main::lxdebug->leave_sub(); - return "$attachment : $!"; - } - # only set charset for attachements of type text. every other type should not have this field # refer to bug 883 for detailed information my $attachment_charset; @@ -228,15 +229,7 @@ Content-Type: ${content_type}; name="$filename"$attachment_charset Content-Transfer-Encoding: BASE64 Content-Disposition: attachment; filename="$filename"\n\n|); - my $msg = ""; - while () { - ; - $msg .= $_; - } - $driver->print(encode_base64($msg)); - - close(IN); - + $driver->print(encode_base64($attachment_content)); } $driver->print(qq|--${boundary}--\n|);