diff options
author | Jannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de> | 2020-11-12 23:20:30 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de> | 2020-11-12 23:20:30 +0100 |
commit | bf5554febae6f299c716b5a9582c6bfd6980b728 (patch) | |
tree | 8a1ef7206ea5affca689ce71edf31e3114440fe9 /lib/JWebmail/Controller | |
parent | 487629cca62c29719e44df2e68cf14d8b0cc2f3e (diff) |
+ added some files that should belonged to the last commit
+ preparation for supporting more mime types
Diffstat (limited to 'lib/JWebmail/Controller')
-rw-r--r-- | lib/JWebmail/Controller/Webmail.pm | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/JWebmail/Controller/Webmail.pm b/lib/JWebmail/Controller/Webmail.pm index 3ec93f1..5f8d986 100644 --- a/lib/JWebmail/Controller/Webmail.pm +++ b/lib/JWebmail/Controller/Webmail.pm @@ -2,7 +2,7 @@ package JWebmail::Controller::Webmail; use Mojo::Base 'Mojolicious::Controller'; -use File::Type; +use Mojolicious::Types; use constant { S_USER => 'user', # Key for user name in active session @@ -219,7 +219,7 @@ sub sendmail { $mail{bcc} = $v->optional('bcc', 'not_empty')->check('mail_line')->every_param; $mail{reply} = $v->optional('back_to', 'not_empty')->check('mail_line')->param; $mail{attach} = $v->optional('attach', 'non_empty_ul')->upload->param; - $mail{attach_type} = File::Type->new()->mime_type($mail{attach}->asset->get_chunk(0, 512)) if $mail{attach}; + $mail{attach_type} = Mojolicious::Types->new->file_type($mail{attach}->filename) if $mail{attach}; $mail{from} = $self->session(S_USER); if ($v->has_error) { @@ -292,14 +292,20 @@ sub raw { my $mail = $self->users->show($auth, $mid); - if ($self->param('body')//'' eq 'html') { - if ($mail->{content_type} eq 'text/html') { - $self->render(text => $mail->{body}) ; - } - elsif ($mail->{content_type} eq 'multipart/alternative') { - my ($content) = grep {$_->{type} eq 'text/html'} @{ $mail->{body} }; + my $v = $self->validation; + $v->optional('body')->like(qr/\w+/); + if ($v->has_error) { + return; + } + + if (my $type = $self->param('body')) { + if ($mail->{content_type} =~ '^multipart/') { + my ($content) = grep {$_->{type} =~ $type} @{ $mail->{body} }; $self->render(text => $content->{val}); } + elsif ($mail->{content_type} =~ $type) { + $self->render(text => $mail->{body}) ; + } else { $self->res->code(404); } @@ -383,4 +389,4 @@ Displays the mail raw, ready to be downloaded. Mojolicious and File::Type -=cut
\ No newline at end of file +=cut |