summaryrefslogtreecommitdiff
path: root/lib/JWebmail/Controller
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de>2022-04-26 01:06:11 +0200
committerJannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de>2022-04-26 01:06:11 +0200
commitaffff46cea8dad31bb850ec27ba2a57f123e681b (patch)
tree8eca6f4b2c21ca0ea08f33c5ee104070fecee9db /lib/JWebmail/Controller
parenteae7431ea9ee9d87634b3938b5cf8b64ebdbfb5a (diff)
adjusted QMailAuthuser to ReadMails Role
Diffstat (limited to 'lib/JWebmail/Controller')
-rw-r--r--lib/JWebmail/Controller/Webmail.pm101
1 files changed, 48 insertions, 53 deletions
diff --git a/lib/JWebmail/Controller/Webmail.pm b/lib/JWebmail/Controller/Webmail.pm
index 6e3ff8b..6754ac7 100644
--- a/lib/JWebmail/Controller/Webmail.pm
+++ b/lib/JWebmail/Controller/Webmail.pm
@@ -62,8 +62,7 @@ sub login {
my $passwd = $v->required('password')->size(4, 50)->like(qr/^.+$/)->param; # no new-lines
if ($v->has_error) {
- $self->res->code(400);
- return $self->render(action => 'noaction');
+ return $self->render(action => 'noaction', status => 400);
}
my $auth = $self->users->Auth(user => $user, password => $passwd);
@@ -77,8 +76,9 @@ sub login {
$self->redirect_to('displayheaders');
}
else {
- $self->res->code(401);
- $self->render(action => 'noaction',
+ $self->render(
+ status => 401,
+ action => 'noaction',
warning => $self->l('login') . ' ' . $self->l('failed') . '!',
);
}
@@ -123,8 +123,8 @@ sub displayheaders {
my $folders = _time { $self->users->folders($auth) } $self, 'user folders';
unless ( $self->stash('folder') ~~ $folders ) {
- $self->res->code(404);
$self->render(template => 'error',
+ status => 404,
error => $self->l('no_folder'),
links => [map { $self->url_for(folder => $_) } @$folders],
);
@@ -136,8 +136,7 @@ sub displayheaders {
my $search = $v->optional('search')->param;
if ($v->has_error) {
- $self->res->code(400);
- $self->render(template => 'error', error => "errors in @{ $v->failed }");
+ $self->render(template => 'error', error => "errors in @{ $v->failed }", status => 400);
return;
}
@@ -195,9 +194,42 @@ sub readmail {
die $@;
}
- $self->render(action => 'readmail',
- msg => $mail,
+ $self->render(msg => $mail);
+}
+
+
+sub raw {
+ my $self = shift;
+
+ my $mid = $self->stash('id');
+
+ my $auth = $self->users->Auth(
+ user => $self->session(S_USER),
+ password => $self->session_passwd,
+ challenge => $self->app->secrets->[0],
);
+
+ my $mail = $self->users->show($auth, $mid);
+
+ my $v = $self->validation;
+ $v->optional('body')->like(qr/\w+/);
+ return if $v->has_error;
+
+ if (my $type = $self->param('body')) {
+ if ($mail->{head}{content_type} =~ '^multipart/') {
+ my ($content) = grep {$_->{head}{content_type} =~ $type} @{ $mail->{body} };
+ $self->render(text => $content->{body});
+ }
+ elsif ($mail->{head}{content_type} =~ $type) {
+ $self->render(text => $mail->{body}) ;
+ }
+ else {
+ $self->reply->not_found;
+ }
+ }
+ else {
+ $self->render(json => $mail);
+ }
}
@@ -238,6 +270,7 @@ sub sendmail {
$self->render(action => 'writemail',
warning => $self->l('error_send'),
+ status => 400,
);
return;
}
@@ -279,44 +312,6 @@ sub move {
}
-sub raw {
- my $self = shift;
-
- my $mid = $self->stash('id');
-
- my $auth = $self->users->Auth(
- user => $self->session(S_USER),
- password => $self->session_passwd,
- challenge => $self->app->secrets->[0],
- );
-
- my $mail = $self->users->show($auth, $mid);
-
- my $v = $self->validation;
- $v->optional('body')->like(qr/\w+/);
- if ($v->has_error) {
- return;
- }
-
- if (my $type = $self->param('body')) {
- if ($mail->{head}{content_type} =~ '^multipart/') {
- my ($content) = grep {$_->{head}{content_type} =~ $type} @{ $mail->{body} };
- $self->render(text => $content->{body});
- }
- elsif ($mail->{head}{content_type} =~ $type) {
- $self->render(text => $mail->{body}) ;
- }
- else {
- $self->res->code(404);
- }
- }
- else {
- $self->res->headers->content_type('text/plain');
- $self->render(text => $self->dumper($mail));
- }
-}
-
-
1
__END__
@@ -329,15 +324,15 @@ Webmail - All functions comprising the webmail application.
=head1 SYNOPSIS
- my $r = $app->routes;
- $r->get('/about')->to('Webmail#about');
- $r->post('/login')->to('Webmail#login');
+ my $r = $app->routes;
+ $r->get('/about')->to('Webmail#about');
+ $r->post('/login')->to('Webmail#login');
=head1 DESCRIPTION
The controller of JWebmail.
-=head1 METHODS
+=head1 ROUTES
=head2 noaction
@@ -345,9 +340,9 @@ The login page. This should be the root.
=head2 auth
- my $a = $r->under('/')->to('Webmail#auth');
+ my $a = $r->under('/')->to('Webmail#auth');
- An intermediate route that makes sure a user has a valid session.
+ An intermediate route that makes sure a user has a valid session.
=head2 login