Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 49c7621e

Von Moritz Bunkus vor mehr als 15 Jahren hinzugefügt

  • ID 49c7621e7bd48352be257e6ceea0e6fbb1718516
  • Vorgänger 1cd85a06
  • Nachfolger ecf8fe1e

Beim Verschicken von Dokumenten per EMail die MIME-Header richtig setzen:

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.

Unterschiede anzeigen:

SL/Form.pm
1129 1129
  $self->{"cwd"} = getcwd();
1130 1130
  $self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
1131 1131

  
1132
  my $ext_for_format;
1133

  
1132 1134
  if ($self->{"format"} =~ /(opendocument|oasis)/i) {
1133
    $template = OpenDocumentTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1135
    $template       = OpenDocumentTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1136
    $ext_for_format = 'odt';
1137

  
1134 1138
  } elsif ($self->{"format"} =~ /(postscript|pdf)/i) {
1135 1139
    $ENV{"TEXINPUTS"} = ".:" . getcwd() . "/" . $myconfig->{"templates"} . ":" . $ENV{"TEXINPUTS"};
1136
    $template = LaTeXTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1137
  } elsif (($self->{"format"} =~ /html/i) ||
1138
           (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) {
1139
    $template = HTMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1140
  } elsif (($self->{"format"} =~ /xml/i) ||
1141
             (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
1142
    $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1140
    $template         = LaTeXTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1141
    $ext_for_format   = 'pdf';
1142

  
1143
  } elsif (($self->{"format"} =~ /html/i) || (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) {
1144
    $template       = HTMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1145
    $ext_for_format = 'html';
1146

  
1147
  } elsif (($self->{"format"} =~ /xml/i) || (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
1148
    $template       = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1149
    $ext_for_format = 'xml';
1150

  
1143 1151
  } elsif ( $self->{"format"} =~ /elsterwinston/i ) {
1144 1152
    $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1153

  
1145 1154
  } elsif ( $self->{"format"} =~ /elstertaxbird/i ) {
1146 1155
    $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1156

  
1147 1157
  } elsif ( defined $self->{'format'}) {
1148 1158
    $self->error("Outputformat not defined. This may be a future feature: $self->{'format'}");
1159

  
1149 1160
  } elsif ( $self->{'format'} eq '' ) {
1150 1161
    $self->error("No Outputformat given: $self->{'format'}");
1162

  
1151 1163
  } else { #Catch the rest
1152 1164
    $self->error("Outputformat not defined: $self->{'format'}");
1153 1165
  }
......
1232 1244
      } else {
1233 1245

  
1234 1246
        if (!$self->{"do_not_attach"}) {
1235
          $mail->{attachments} = [{ "filename" => $self->{"tmpfile"},
1236
                                    "name"     => $self->{"attachment_filename"} ? $self->{"attachment_filename"} : $self->{"tmpfile"} }];
1247
          my $attachment_name  =  $self->{attachment_filename} || $self->{tmpfile};
1248
          $attachment_name     =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
1249
          $mail->{attachments} =  [{ "filename" => $self->{tmpfile},
1250
                                     "name"     => $attachment_name }];
1237 1251
        }
1238 1252

  
1239 1253
        $mail->{message}  =~ s/\r//g;
SL/Mailer.pm
33 33
use Email::Address;
34 34

  
35 35
use SL::Common;
36
use SL::MIME;
36 37
use SL::Template;
37 38

  
38 39
my $num_sent = 0;
......
181 182
        $filename =~ s/(.*\/|\Q$self->{fileid}\E)//g;
182 183
      }
183 184

  
184
      my $application =
185
        ($attachment =~ /(^\w+$)|\.(html|text|txt|sql)$/)
186
        ? "text"
187
        : "application";
185
      my $application    = ($attachment =~ /(^\w+$)|\.(html|text|txt|sql)$/) ? "text" : "application";
186
      my $content_type   = SL::MIME->mime_type_from_ext($filename);
187
      $content_type      = "${application}/${self->{format}}" if (!$content_type && $self->{format});
188
      $content_type    ||= 'application/octet-stream';
188 189

  
189 190
      open(IN, $attachment);
190 191
      if ($?) {
......
201 202
      }
202 203

  
203 204
      print OUT qq|--${boundary}
204
Content-Type: $application/$self->{format}; name="$filename"$attachment_charset
205
Content-Type: ${content_type}; name="$filename"$attachment_charset
205 206
Content-Transfer-Encoding: BASE64
206 207
Content-Disposition: attachment; filename="$filename"\n\n|;
207 208

  

Auch abrufbar als: Unified diff