summaryrefslogtreecommitdiff
path: root/lib/JWebmail/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'lib/JWebmail/Controller')
-rw-r--r--lib/JWebmail/Controller/Webmail.pm51
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