summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/JWebmail.pm7
-rw-r--r--lib/JWebmail/Controller/Webmail.pm37
-rw-r--r--lib/JWebmail/Model/ReadMails/QMailAuthuser.pm18
-rw-r--r--lib/JWebmail/Model/ReadMails/Role.pm7
4 files changed, 52 insertions, 17 deletions
diff --git a/lib/JWebmail.pm b/lib/JWebmail.pm
index 11c66db..92c5b44 100644
--- a/lib/JWebmail.pm
+++ b/lib/JWebmail.pm
@@ -79,10 +79,10 @@ sub route {
my $r = shift || $self->routes;
- $r->get( '/' => 'login')->to('Webmail#noaction');
+ $r->get ('/' => 'login')->to('Webmail#noaction');
$r->post('/' => 'login')->to('Webmail#login');
- $r->get('/about' )->to('Webmail#about');
- $r->get('/logout' )->to('Webmail#logout');
+ $r->get ('/about' )->to('Webmail#about');
+ $r->get ('/logout' )->to('Webmail#logout');
my $a = $r->under('/')->to('Webmail#auth');
$a->get('/home/*folder' )->to('Webmail#displayheaders', folder => '')->name('displayheaders');
@@ -91,6 +91,7 @@ sub route {
$a->get('/write' )->to('Webmail#writemail');
$a->post('/write' => 'send' )->to('Webmail#sendmail');
$a->post('/move' )->to('Webmail#move');
+ $a->post('/remove/*folder' )->to('Webmail#remove', folder => '');
}
diff --git a/lib/JWebmail/Controller/Webmail.pm b/lib/JWebmail/Controller/Webmail.pm
index 7bf083a..b044fc6 100644
--- a/lib/JWebmail/Controller/Webmail.pm
+++ b/lib/JWebmail/Controller/Webmail.pm
@@ -55,16 +55,13 @@ sub auth {
sub _time :prototype(&$$) {
- my $code = shift;
- my $self = shift;
- my $name = shift;
+ my ($code, $self, $name) = @_;
$self->timing->begin($name);
-
my @res = $code->();
-
my $elapsed = $self->timing->elapsed($name);
- $self->app->log->debug(sprintf("%s took %fs", $name, $elapsed));
+
+ $self->app->log->debug(sprintf("[%s] %s took %fs", $self->req->request_id, $name, $elapsed));
return wantarray ? @res : $res[-1];
}
@@ -183,7 +180,7 @@ sub displayheaders {
}
};
my $elapsed = $self->timing->elapsed('user_headers');
- $self->app->log->debug(sprintf("Reading user headers took %fs", $elapsed));
+ $self->app->log->debug(sprintf("[%s] Reading user headers took %fs", $self->req->request_id, $elapsed));
$self->stash(
v => JWebmail::View::Webmail->new,
@@ -296,6 +293,7 @@ sub move {
$v->csrf_protect;
if ($v->has_error) {
+ $self->res->code(400);
return;
}
@@ -305,7 +303,6 @@ sub move {
my $mm = $self->every_param('mail');
my $folder = $self->param('folder');
- no warnings 'experimental::smartmatch';
die "$folder not valid" unless any { $folder eq $_ } @$folders;
$self->users->move($auth, $_, '', $folder) for @$mm;
@@ -316,6 +313,30 @@ sub move {
}
+sub remove {
+ my $self = shift;
+
+ my $v = $self->validation;
+ $v->csrf_protect;
+ $v->required('mail');
+
+ if ($v->has_error) {
+ $self->reply->exception('errors in ' . join('', $v->failed->@*));
+ return;
+ }
+
+ my $auth = $self->stash(STS_AUTH);
+
+ my $mm = $self->every_param('mail');
+ my $folder = $self->stash('folder');
+
+ $self->users->remove($auth, $folder, $_) for @$mm;
+
+ $self->res->code(303);
+ $self->redirect_to('displayheaders');
+}
+
+
### session password handling
use constant { S_PASSWD => 'pw', S_OTP_S3D_PW => 'otp_s3d_pw' };
diff --git a/lib/JWebmail/Model/ReadMails/QMailAuthuser.pm b/lib/JWebmail/Model/ReadMails/QMailAuthuser.pm
index 5190e26..f5f9392 100644
--- a/lib/JWebmail/Model/ReadMails/QMailAuthuser.pm
+++ b/lib/JWebmail/Model/ReadMails/QMailAuthuser.pm
@@ -170,6 +170,14 @@ sub move {
return 1;
}
+sub remove {
+ my $self = shift;
+ my ($auth, $folder, $mid) = @_;
+
+ my $_resp = $self->build_and_run($auth, 'remove', [$folder, $mid]);
+ return 1;
+}
+
sub build_arg {
my $self = shift;
@@ -235,8 +243,8 @@ sub read_qmauth {
$resp = {
head => $r,
body => $buf,
- rc => $?,
- e => $e,
+ rc => $?,
+ e => $e,
};
}
elsif ($rs == 3 << 8 || $rs == 0) {
@@ -244,9 +252,9 @@ sub read_qmauth {
eval { $resp = decode_json $input if $input; 1 }
or do {
$resp = {
- info => "error decoding response",
- response => $input,
- cause => $@,
+ info => "error decoding response",
+ response => $input,
+ cause => $@,
return_code => $rc,
};
};
diff --git a/lib/JWebmail/Model/ReadMails/Role.pm b/lib/JWebmail/Model/ReadMails/Role.pm
index f094190..dfccbde 100644
--- a/lib/JWebmail/Model/ReadMails/Role.pm
+++ b/lib/JWebmail/Model/ReadMails/Role.pm
@@ -43,6 +43,7 @@ my @methods = (
'search',
'show',
'raw',
+ 'remove',
);
requires(@methods);
@@ -127,7 +128,11 @@ List all mailbox sub folders.
=head2 move
-Move mails between folders.
+Move a mail between folders.
+
+=head2 remove
+
+Mark a mail to be moved to the trash.
=head2 Auth