summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2023-09-27 23:09:25 +0200
committerJannis M. Hoffmann <jannis@fehcom.de>2023-09-27 23:09:25 +0200
commitd08cb95db4883b6eb967135498f3ca75e3af3735 (patch)
tree9e5bb3e87e09fc512112b59ba7fe3177eff2ed73
parent8012e435a90675ca0efb2475e079a1320eecd6b2 (diff)
add remove action
-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
-rwxr-xr-xscript/extract.py14
5 files changed, 66 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
diff --git a/script/extract.py b/script/extract.py
index 526db92..cc8f03e 100755
--- a/script/extract.py
+++ b/script/extract.py
@@ -376,6 +376,15 @@ def move_mail(f, mid, from_, to):
return 1
+def remove_mail(f, subdir, mid):
+ if subdir:
+ f = f.get_folder(subdir)
+
+ f[mid].add_flag('T')
+
+ return 1
+
+
def parse_arguments():
ap = ArgumentParser(allow_abbrev=False)
ap.add_argument('maildir_path', type=Path)
@@ -415,6 +424,11 @@ def parse_arguments():
sp_move.add_argument('to')
sp_move.set_defaults(run=move_mail)
+ sp_remove = sp.add_parser('remove')
+ sp_remove.add_argument('subdir')
+ sp_remove.add_argument('mid', metavar='message')
+ sp_remove.set_defaults(run=remove_mail)
+
sp_search = sp.add_parser('search')
sp_search.add_argument('pattern')
sp_search.add_argument('subfolder')