$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'}");
}
} 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;
use Email::Address;
use SL::Common;
+use SL::MIME;
use SL::Template;
my $num_sent = 0;
$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 ($?) {
}
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|;