From 20069819d0de7313f5f6fcc724d0ea35d8fd0bd6 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 3 Jul 2013 10:05:35 +0200 Subject: [PATCH] =?utf8?q?Beim=20Drucken=20immer=20zuerst=20in=20tempor?= =?utf8?q?=C3=A4re=20Datei=20speichern?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Form.pm | 128 +++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 67 deletions(-) diff --git a/SL/Form.pm b/SL/Form.pm index fc900c108..6c3785b4d 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1044,12 +1044,10 @@ sub parse_template { close $temp_fh; (undef, undef, $self->{template_meta}{tmpfile}) = File::Spec->splitpath( $self->{tmpfile} ); - if ($template->uses_temp_file() || $self->{media} eq 'email') { - $out = $self->{OUT}; - $out_mode = $self->{OUT_MODE} || '>'; - $self->{OUT} = "$self->{tmpfile}"; - $self->{OUT_MODE} = '>'; - } + $out = $self->{OUT}; + $out_mode = $self->{OUT_MODE} || '>'; + $self->{OUT} = "$self->{tmpfile}"; + $self->{OUT_MODE} = '>'; my $result; my $command_formatter = sub { @@ -1085,92 +1083,88 @@ sub parse_template { return; } - if ($template->uses_temp_file() || $self->{media} eq 'email') { - - if ($self->{media} eq 'email') { + if ($self->{media} eq 'email') { - my $mail = new Mailer; + my $mail = new Mailer; - map { $mail->{$_} = $self->{$_} } - qw(cc bcc subject message version format); - $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email}; - $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|; - $mail->{fileid} = time() . '.' . $$ . '.'; - $myconfig->{signature} =~ s/\r//g; + map { $mail->{$_} = $self->{$_} } + qw(cc bcc subject message version format); + $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email}; + $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|; + $mail->{fileid} = time() . '.' . $$ . '.'; + $myconfig->{signature} =~ s/\r//g; - # if we send html or plain text inline - if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) { - $mail->{contenttype} = "text/html"; - $mail->{message} =~ s/\r//g; - $mail->{message} =~ s/\n/
\n/g; - $myconfig->{signature} =~ s/\n/
\n/g; - $mail->{message} .= "
\n--
\n$myconfig->{signature}\n
"; + # if we send html or plain text inline + if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) { + $mail->{contenttype} = "text/html"; + $mail->{message} =~ s/\r//g; + $mail->{message} =~ s/\n/
\n/g; + $myconfig->{signature} =~ s/\n/
\n/g; + $mail->{message} .= "
\n--
\n$myconfig->{signature}\n
"; - open(IN, "<", $self->{tmpfile}) - or $self->error($self->cleanup . "$self->{tmpfile} : $!"); - $mail->{message} .= $_ while ; - close(IN); + open(IN, "<", $self->{tmpfile}) + or $self->error($self->cleanup . "$self->{tmpfile} : $!"); + $mail->{message} .= $_ while ; + close(IN); - } else { + } else { - if (!$self->{"do_not_attach"}) { - my $attachment_name = $self->{attachment_filename} || $self->{tmpfile}; - $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format); - $mail->{attachments} = [{ "filename" => $self->{tmpfile}, - "name" => $attachment_name }]; - } + if (!$self->{"do_not_attach"}) { + my $attachment_name = $self->{attachment_filename} || $self->{tmpfile}; + $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format); + $mail->{attachments} = [{ "filename" => $self->{tmpfile}, + "name" => $attachment_name }]; + } - $mail->{message} =~ s/\r//g; - $mail->{message} .= "\n-- \n$myconfig->{signature}"; + $mail->{message} =~ s/\r//g; + $mail->{message} .= "\n-- \n$myconfig->{signature}"; - } + } - my $err = $mail->send(); - $self->error($self->cleanup . "$err") if ($err); + my $err = $mail->send(); + $self->error($self->cleanup . "$err") if ($err); - } else { + } else { - $self->{OUT} = $out; - $self->{OUT_MODE} = $out_mode; + $self->{OUT} = $out; + $self->{OUT_MODE} = $out_mode; - my $numbytes = (-s $self->{tmpfile}); - open(IN, "<", $self->{tmpfile}) - or $self->error($self->cleanup . "$self->{tmpfile} : $!"); - binmode IN; + my $numbytes = (-s $self->{tmpfile}); + open(IN, "<", $self->{tmpfile}) + or $self->error($self->cleanup . "$self->{tmpfile} : $!"); + binmode IN; - $self->{copies} = 1 unless $self->{media} eq 'printer'; + $self->{copies} = 1 unless $self->{media} eq 'printer'; - chdir("$self->{cwd}"); - #print(STDERR "Kopien $self->{copies}\n"); - #print(STDERR "OUT $self->{OUT}\n"); - for my $i (1 .. $self->{copies}) { - if ($self->{OUT}) { - $self->{OUT} = $command_formatter->($self->{OUT_MODE}, $self->{OUT}); + chdir("$self->{cwd}"); + #print(STDERR "Kopien $self->{copies}\n"); + #print(STDERR "OUT $self->{OUT}\n"); + for my $i (1 .. $self->{copies}) { + if ($self->{OUT}) { + $self->{OUT} = $command_formatter->($self->{OUT_MODE}, $self->{OUT}); - open OUT, $self->{OUT_MODE}, $self->{OUT} or $self->error($self->cleanup . "$self->{OUT} : $!"); - print OUT $_ while ; - close OUT; - seek IN, 0, 0; + open OUT, $self->{OUT_MODE}, $self->{OUT} or $self->error($self->cleanup . "$self->{OUT} : $!"); + print OUT $_ while ; + close OUT; + seek IN, 0, 0; - } else { - $self->{attachment_filename} = ($self->{attachment_filename}) - ? $self->{attachment_filename} - : $self->generate_attachment_filename(); + } else { + $self->{attachment_filename} = ($self->{attachment_filename}) + ? $self->{attachment_filename} + : $self->generate_attachment_filename(); - # launch application - print qq|Content-Type: | . $template->get_mime_type() . qq| + # launch application + print qq|Content-Type: | . $template->get_mime_type() . qq| Content-Disposition: attachment; filename="$self->{attachment_filename}" Content-Length: $numbytes |; - $::locale->with_raw_io(\*STDOUT, sub { print while }); - } + $::locale->with_raw_io(\*STDOUT, sub { print while }); } - - close(IN); } + close(IN); } $self->cleanup; -- 2.20.1