From 4f41cebcc279d57cab7fcc2a7385e870894c072f Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Wed, 23 Aug 2017 12:26:27 +0200 Subject: [PATCH] add spamusers api call this api call returns a list of receiver emails, which have received spam in the quarantine in the given timeframe by default this is the last 24 hours Signed-off-by: Dominik Csapak --- PMG/API2/Quarantine.pm | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/PMG/API2/Quarantine.pm b/PMG/API2/Quarantine.pm index 2786e12..439e6fa 100644 --- a/PMG/API2/Quarantine.pm +++ b/PMG/API2/Quarantine.pm @@ -166,6 +166,7 @@ __PACKAGE__->register_method ({ { name => 'blacklist' }, { name => 'content' }, { name => 'spam' }, + { name => 'spamusers' }, { name => 'virus' }, ]; @@ -449,6 +450,71 @@ __PACKAGE__->register_method ({ return $res; }}); +__PACKAGE__->register_method ({ + name => 'spamusers', + path => 'spamusers', + method => 'GET', + permissions => { check => [ 'admin', 'qmanager', 'audit', 'quser'] }, + description => "Get a list of receivers of spam in the given timespan (Default the last 24 hours).", + parameters => { + additionalProperties => 0, + properties => { + starttime => { + description => "Only consider entries newer than 'starttime' (unix epoch). Default is 'now - 1day'.", + type => 'integer', + minimum => 0, + optional => 1, + }, + endtime => { + description => "Only consider entries older than 'endtime' (unix epoch). This is set to ' + 1day' by default.", + type => 'integer', + minimum => 1, + optional => 1, + }, + }, + }, + returns => { + type => 'array', + items => { + type => "object", + properties => { + mail => { + description => 'the receiving email', + type => 'string', + }, + }, + }, + }, + code => sub { + my ($param) = @_; + + my $rpcenv = PMG::RESTEnvironment->get(); + my $authuser = $rpcenv->get_user(); + my $role = $rpcenv->get_role(); + + my $res = []; + + my $dbh = PMG::DBTools::open_ruledb(); + + my $start = $param->{starttime} // (time - 86400); + my $end = $param->{endtime} // ($start + 86400); + + my $sth = $dbh->prepare( + "SELECT DISTINCT pmail " . + "FROM CMailStore, CMSReceivers WHERE " . + "time >= $start AND time < $end AND " . + "QType = 'S' AND CID = CMailStore_CID AND RID = CMailStore_RID " . + "AND Status = 'N' ORDER BY pmail"); + + $sth->execute(); + + while (my $ref = $sth->fetchrow_hashref()) { + push @$res, { mail => $ref->{pmail} }; + } + + return $res; + }}); + __PACKAGE__->register_method ({ name => 'spamlist', path => 'spam/{starttime}', -- 2.39.2