From 49c7621e7bd48352be257e6ceea0e6fbb1718516 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 4 May 2009 11:23:12 +0000 Subject: [PATCH] Beim Verschicken von Dokumenten per EMail die MIME-Header richtig setzen: MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 1. MIME-Header anhand des Dateinamens setzen; weniger anhand von $form->{format}, weil das nicht immer gesetzt ist und nicht immer zu einem richtigen MIME-Typ führt (so ist "format" z.B. "opendocument", und der MIME-Typ lautet aber "vnd.oasis.opendocument.text"). 2. Die Dateinamenserweiterung von Dateianhängen beim Drucken/Mailen in $form anhand von $form->{format} anpassen, damit nicht ".pdf" dranhängt, wenn OpenDocument drin ist. Fix für Bug 912. --- SL/Form.pm | 34 ++++++++++++++++++++++++---------- SL/Mailer.pm | 11 ++++++----- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/SL/Form.pm b/SL/Form.pm index 8ed29eb0b..637bbe286 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1129,25 +1129,37 @@ sub parse_template { $self->{"cwd"} = getcwd(); $self->{"tmpdir"} = $self->{cwd} . "/${userspath}"; + my $ext_for_format; + if ($self->{"format"} =~ /(opendocument|oasis)/i) { - $template = OpenDocumentTemplate->new($self->{"IN"}, $self, $myconfig, $userspath); + $template = OpenDocumentTemplate->new($self->{"IN"}, $self, $myconfig, $userspath); + $ext_for_format = 'odt'; + } elsif ($self->{"format"} =~ /(postscript|pdf)/i) { $ENV{"TEXINPUTS"} = ".:" . getcwd() . "/" . $myconfig->{"templates"} . ":" . $ENV{"TEXINPUTS"}; - $template = LaTeXTemplate->new($self->{"IN"}, $self, $myconfig, $userspath); - } elsif (($self->{"format"} =~ /html/i) || - (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) { - $template = HTMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath); - } elsif (($self->{"format"} =~ /xml/i) || - (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) { - $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath); + $template = LaTeXTemplate->new($self->{"IN"}, $self, $myconfig, $userspath); + $ext_for_format = 'pdf'; + + } elsif (($self->{"format"} =~ /html/i) || (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) { + $template = HTMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath); + $ext_for_format = 'html'; + + } elsif (($self->{"format"} =~ /xml/i) || (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) { + $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath); + $ext_for_format = 'xml'; + } elsif ( $self->{"format"} =~ /elsterwinston/i ) { $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath); + } elsif ( $self->{"format"} =~ /elstertaxbird/i ) { $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath); + } elsif ( defined $self->{'format'}) { $self->error("Outputformat not defined. This may be a future feature: $self->{'format'}"); + } elsif ( $self->{'format'} eq '' ) { $self->error("No Outputformat given: $self->{'format'}"); + } else { #Catch the rest $self->error("Outputformat not defined: $self->{'format'}"); } @@ -1232,8 +1244,10 @@ sub parse_template { } else { if (!$self->{"do_not_attach"}) { - $mail->{attachments} = [{ "filename" => $self->{"tmpfile"}, - "name" => $self->{"attachment_filename"} ? $self->{"attachment_filename"} : $self->{"tmpfile"} }]; + 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; diff --git a/SL/Mailer.pm b/SL/Mailer.pm index 3cf205364..5e280128b 100644 --- a/SL/Mailer.pm +++ b/SL/Mailer.pm @@ -33,6 +33,7 @@ package Mailer; use Email::Address; use SL::Common; +use SL::MIME; use SL::Template; my $num_sent = 0; @@ -181,10 +182,10 @@ $self->{message} $filename =~ s/(.*\/|\Q$self->{fileid}\E)//g; } - my $application = - ($attachment =~ /(^\w+$)|\.(html|text|txt|sql)$/) - ? "text" - : "application"; + 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 ($?) { @@ -201,7 +202,7 @@ $self->{message} } print OUT qq|--${boundary} -Content-Type: $application/$self->{format}; name="$filename"$attachment_charset +Content-Type: ${content_type}; name="$filename"$attachment_charset Content-Transfer-Encoding: BASE64 Content-Disposition: attachment; filename="$filename"\n\n|; -- 2.20.1