diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-03-10 13:54:57 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-03-10 13:54:57 +0100 |
commit | fcf5549584b69e62b6c2f0eb919f6799c7904211 (patch) | |
tree | e5f0e480af0f39f1c0f457ea0aca8d33f8fb4d0b /lib/JWebmail/Controller/Webmail.pm | |
parent | df59f9dec32d7f8f08706fd3eb5b784deaa0abfc (diff) |
Proper recursive rendering of mails to html
1. Added raw mode to model
2. Added raw route
3. Moved readmail view parts to RenderMail plugin
4. Renamed displayheaders partial templates
Diffstat (limited to 'lib/JWebmail/Controller/Webmail.pm')
-rw-r--r-- | lib/JWebmail/Controller/Webmail.pm | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/lib/JWebmail/Controller/Webmail.pm b/lib/JWebmail/Controller/Webmail.pm index 6d0cc55..fd1c499 100644 --- a/lib/JWebmail/Controller/Webmail.pm +++ b/lib/JWebmail/Controller/Webmail.pm @@ -73,7 +73,7 @@ sub login { my $passwd = $v->required('password')->size(4, 50)->like(qr/^.+$/)->param; # no new-lines my $challenge; if ($uses_cram) { - $challenge = $v->required('challenge')->size(4, 50)->param; # no new-lines + $challenge = $v->required('challenge')->size(4, 50)->param; } if ($v->has_error) { @@ -190,43 +190,42 @@ sub readmail { my $self = shift; my $mid = $self->stash('id'); - my $auth = $self->stash(ST_AUTH); my $mail; my $ok = eval { $mail = $self->users->show($auth, '', $mid); 1 }; if (!$ok) { - my $err = $@; - if ($err =~ m/unkown mail-id|no such message/) { + my $err = "$@"; + if ($err =~ /unkown mail-id|no such message/) { $self->reply->not_found; return; } die; } + $self->stash(msg => $mail); +} + + +sub raw { + my $self = shift; + + my $mid = $self->stash('id'); + my $auth = $self->stash(ST_AUTH); + # select a single body element my $v = $self->validation; - my $type = $v->optional('body')->like(qr(^[\w\-/; ]+$)a)->param; - return if $v->has_error; + my $path = $v->optional('path')->like(qr(^\d(\.\d)*$)a)->param; + return $self->render(text => 'Issue in parameter "path": '.join(' ', $v->error('path')->@*), status => 400, format => 'txt') if $v->has_error; - if ($type) { - if ($mail->{head}{mime}{content_maintype} eq 'multipart') { - my $content = first {$_->{head}{content_subtype} eq $type} $mail->{body}{parts}->@*; - $self->render(text => $content->{body}); - } - elsif ($mail->{head}{mime}{content_subtype} eq $type) { - $self->render(text => $mail->{body}); - } - else { - $self->reply->not_found; - } - return; - } + my $content = $self->users->raw($auth, '', $mid, $path); - $self->respond_to( - html => {msg => $mail}, - json => {json => $mail} - ); + $self->res->headers->content_disposition(qq[attachment; filename="$content->{head}{filename}"]) + if $content->{head}{content_disposition}; + my $ct = $self->to_mime_type($content->{head}); + if ($ct eq 'text/plain') { $ct .= '; charset=UTF-8' } + $self->res->headers->content_type($ct); + $self->render(data => $content->{body}); } @@ -369,9 +368,3 @@ Sends a mail written in writemail. =head2 move Moves mails between mail forlders. - -=head1 DEPENCIES - -Mojolicious and File::Type - -=cut |