]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/API2/Quarantine.pm
1 package PMG
:: API2
:: Quarantine
;
13 use Mail
:: SpamAssassin
;
16 use PVE
:: Exception
qw(raise_param_exc raise_perm_exc) ;
17 use PVE
:: Tools
qw(extract_param) ;
18 use PVE
:: JSONSchema
qw(get_standard_option) ;
21 use PVE
:: APIServer
:: Formatter
;
24 use PMG
:: AccessControl
;
32 use base
qw(PVE::RESTHandler) ;
36 my $extract_pmail = sub {
37 my ( $authuser, $role ) = @_ ;
39 if ( $authuser =~ m/^(.+)\@quarantine$/ ) {
42 raise_param_exc
({ pmail
=> "got unexpected authuser ' $authuser ' with role ' $role '" });
45 my $verify_optional_pmail = sub {
46 my ( $authuser, $role, $pmail_param ) = @_ ;
49 if ( $role eq 'quser' ) {
50 $pmail = $extract_pmail ->( $authuser, $role );
51 raise_param_exc
({ pmail
=> "parameter not allwed with role ' $role '" })
52 if defined ( $pmail_param ) && ( $pmail ne $pmail_param );
54 raise_param_exc
({ pmail
=> "parameter required with role ' $role '" })
55 if ! defined ( $pmail_param );
56 $pmail = $pmail_param ;
65 return $res if ! defined ( $info );
67 my $saversion = Mail
:: SpamAssassin-
> VERSION ;
69 my $salocaldir = "/var/lib/spamassassin/ $saversion/updates_spamassassin_org " ;
71 $spamdesc = PMG
:: Utils
:: load_sa_descriptions
([ $salocaldir ]) if ! $spamdesc ;
73 foreach my $test ( split ( ',' , $info )) {
74 my ( $name, $score ) = split ( ':' , $test );
76 my $info = { name
=> $name, score
=> $score + 0 , desc
=> '-' };
77 if ( my $si = $spamdesc ->{ $name }) {
78 $info ->{ desc
} = $si ->{ desc
};
79 $info ->{ url
} = $si ->{ url
} if defined ( $si ->{ url
});
87 my $extract_email = sub {
90 return $data if ! $data ;
92 if ( $data =~ m/^.*\s(\S+)\s*$/ ) {
96 if ( $data =~ m/^<([^<>\s]+)>$/ ) {
100 if ( $data !~ m/[\s><]/ && $data =~ m/^(.+\@[^\.]+\..*[^\.]+)$/ ) {
109 my $get_real_sender = sub {
112 my @lines = split ( ' \n ' , $ref ->{ header
});
113 my $head = Mail
:: Header-
> new ( \
@lines );
115 my @fromarray = split ( '\s*,\s*' , $head -> get ( 'from' ) || $ref ->{ sender
});
116 my $from = $extract_email ->( $fromarray [ 0 ]) || $ref ->{ sender
};;
117 my $sender = $extract_email ->( $head -> get ( 'sender' ));
119 return $sender if $sender ;
124 my $parse_header_info = sub {
127 my $res = { subject
=> '' , from
=> '' };
129 my @lines = split ( ' \n ' , $ref ->{ header
});
130 my $head = Mail
:: Header-
> new ( \
@lines );
132 $res ->{ subject
} = PMG
:: Utils
:: decode_rfc1522
( PVE
:: Tools
:: trim
( $head -> get ( 'subject' ))) // '' ;
134 my @fromarray = split ( '\s*,\s*' , $head -> get ( 'from' ) || $ref ->{ sender
});
136 $res ->{ from
} = PMG
:: Utils
:: decode_rfc1522
( PVE
:: Tools
:: trim
( $fromarray [ 0 ])) // '' ;
138 my $sender = PMG
:: Utils
:: decode_rfc1522
( PVE
:: Tools
:: trim
( $head -> get ( 'sender' )));
139 $res ->{ sender
} = $sender if $sender && ( $sender ne $res ->{ from
});
141 $res ->{ envelope_sender
} = $ref ->{ sender
};
142 $res ->{ receiver
} = $ref ->{ receiver
} // $ref ->{ pmail
};
143 $res ->{ id
} = 'C' . $ref ->{ cid
} . 'R' . $ref ->{ rid
} . 'T' . $ref ->{ ticketid
};
144 $res ->{ time } = $ref ->{ time };
145 $res ->{ bytes
} = $ref ->{ bytes
};
147 my $qtype = $ref ->{ qtype
};
150 $res ->{ virusname
} = $ref ->{ info
};
151 $res ->{ spamlevel
} = 0 ;
152 } elsif ( $qtype eq 'S' ) {
153 $res ->{ spamlevel
} = $ref ->{ spamlevel
} // 0 ;
159 my $pmail_param_type = get_standard_option
( 'pmg-email-address' , {
160 description
=> "List entries for the user with this primary email address. Quarantine users cannot speficy this parameter, but it is required for all other roles." ,
164 __PACKAGE__-
> register_method ({
168 permissions
=> { user
=> 'all' },
169 description
=> "Directory index." ,
171 additionalProperties
=> 0 ,
180 links
=> [ { rel
=> 'child' , href
=> "{name}" } ],
186 { name
=> 'whitelist' },
187 { name
=> 'blacklist' },
188 { name
=> 'content' },
190 { name
=> 'spamusers' },
191 { name
=> 'spamstatus' },
193 { name
=> 'virusstatus' },
194 { name
=> 'quarusers' },
195 { name
=> 'attachment' },
196 { name
=> 'listattachments' },
197 { name
=> 'download' },
204 my $read_or_modify_user_bw_list = sub {
205 my ( $listname, $param, $addrs, $delete ) = @_ ;
207 my $rpcenv = PMG
:: RESTEnvironment-
> get ();
208 my $authuser = $rpcenv -> get_user ();
209 my $role = $rpcenv -> get_role ();
211 my $pmail = $verify_optional_pmail ->( $authuser, $role, $param ->{ pmail
});
213 my $dbh = PMG
:: DBTools
:: open_ruledb
();
215 my $list = PMG
:: Quarantine
:: add_to_blackwhite
(
216 $dbh, $pmail, $listname, $addrs, $delete );
219 foreach my $a ( @$list ) { push @$res, { address
=> $a }; }
223 __PACKAGE__-
> register_method ({
227 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' , 'quser' ] },
228 description
=> "Show user whitelist." ,
230 additionalProperties
=> 0 ,
232 pmail
=> $pmail_param_type,
249 return $read_or_modify_user_bw_list ->( 'WL' , $param );
252 __PACKAGE__-
> register_method ({
253 name
=> 'whitelist_add' ,
256 description
=> "Add user whitelist entries." ,
257 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' , 'quser' ] },
260 additionalProperties
=> 0 ,
262 pmail
=> $pmail_param_type,
263 address
=> get_standard_option
( 'pmg-whiteblacklist-entry-list' , {
264 description
=> "The address you want to add." ,
268 returns
=> { type
=> 'null' },
272 my $addresses = [ split ( ',' , $param ->{ address
})];
273 $read_or_modify_user_bw_list ->( 'WL' , $param, $addresses );
278 __PACKAGE__-
> register_method ({
279 name
=> 'whitelist_delete' ,
280 path
=> 'whitelist/{address}' ,
282 description
=> "Delete user whitelist entries." ,
283 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' , 'quser' ] },
286 additionalProperties
=> 0 ,
288 pmail
=> $pmail_param_type,
289 address
=> get_standard_option
( 'pmg-whiteblacklist-entry-list' , {
290 description
=> "The address you want to remove." ,
294 returns
=> { type
=> 'null' },
298 my $addresses = [ split ( ',' , $param ->{ address
})];
299 $read_or_modify_user_bw_list ->( 'WL' , $param, $addresses, 1 );
304 __PACKAGE__-
> register_method ({
308 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' , 'quser' ] },
309 description
=> "Show user blacklist." ,
311 additionalProperties
=> 0 ,
313 pmail
=> $pmail_param_type,
330 return $read_or_modify_user_bw_list ->( 'BL' , $param );
333 __PACKAGE__-
> register_method ({
334 name
=> 'blacklist_add' ,
337 description
=> "Add user blacklist entries." ,
338 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' , 'quser' ] },
341 additionalProperties
=> 0 ,
343 pmail
=> $pmail_param_type,
344 address
=> get_standard_option
( 'pmg-whiteblacklist-entry-list' , {
345 description
=> "The address you want to add." ,
349 returns
=> { type
=> 'null' },
353 my $addresses = [ split ( ',' , $param ->{ address
})];
354 $read_or_modify_user_bw_list ->( 'BL' , $param, $addresses );
359 __PACKAGE__-
> register_method ({
360 name
=> 'blacklist_delete' ,
361 path
=> 'blacklist/{address}' ,
363 description
=> "Delete user blacklist entries." ,
364 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' , 'quser' ] },
367 additionalProperties
=> 0 ,
369 pmail
=> $pmail_param_type,
370 address
=> get_standard_option
( 'pmg-whiteblacklist-entry-list' , {
371 description
=> "The address you want to remove." ,
375 returns
=> { type
=> 'null' },
379 my $addresses = [ split ( ',' , $param ->{ address
})];
380 $read_or_modify_user_bw_list ->( 'BL' , $param, $addresses, 1 );
385 __PACKAGE__-
> register_method ({
389 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' ] },
390 description
=> "Get a list of receivers of spam in the given timespan (Default the last 24 hours)." ,
392 additionalProperties
=> 0 ,
394 starttime
=> get_standard_option
( 'pmg-starttime' ),
395 endtime
=> get_standard_option
( 'pmg-endtime' ),
404 description
=> 'the receiving email' ,
413 my $rpcenv = PMG
:: RESTEnvironment-
> get ();
414 my $authuser = $rpcenv -> get_user ();
418 my $dbh = PMG
:: DBTools
:: open_ruledb
();
420 my $start = $param ->{ starttime
} // ( time - 86400 );
421 my $end = $param ->{ endtime
} // ( $start + 86400 );
423 my $sth = $dbh -> prepare (
424 "SELECT DISTINCT pmail " .
425 "FROM CMailStore, CMSReceivers WHERE " .
426 "time >= $start AND time < $end AND " .
427 "QType = 'S' AND CID = CMailStore_CID AND RID = CMailStore_RID " .
428 "AND Status = 'N' ORDER BY pmail" );
432 while ( my $ref = $sth -> fetchrow_hashref ()) {
433 push @$res, { mail
=> $ref ->{ pmail
} };
439 __PACKAGE__-
> register_method ({
440 name
=> 'spamstatus' ,
441 path
=> 'spamstatus' ,
443 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' ] },
444 description
=> "Get Spam Quarantine Status" ,
446 additionalProperties
=> 0 ,
453 description
=> 'Number of stored mails.' ,
457 description
=> "Estimated disk space usage in MByte." ,
461 description
=> "Average size of stored mails in bytes." ,
465 description
=> "Average spam level." ,
473 my $dbh = PMG
:: DBTools
:: open_ruledb
();
474 my $ref = PMG
:: DBTools
:: get_quarantine_count
( $dbh, 'S' );
479 __PACKAGE__-
> register_method ({
483 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' ] },
484 description
=> "Get a list of users with whitelist/blacklist setttings." ,
486 additionalProperties
=> 0 ,
490 description
=> 'If set, limits the result to the given list.' ,
491 enum
=> [ 'BL' , 'WL' ],
502 description
=> 'the receiving email' ,
511 my $rpcenv = PMG
:: RESTEnvironment-
> get ();
512 my $authuser = $rpcenv -> get_user ();
516 my $dbh = PMG
:: DBTools
:: open_ruledb
();
519 if ( $param ->{ list
}) {
520 $sth = $dbh -> prepare ( "SELECT DISTINCT pmail FROM UserPrefs WHERE name = ? ORDER BY pmail" );
521 $sth -> execute ( $param ->{ list
});
523 $sth = $dbh -> prepare ( "SELECT DISTINCT pmail FROM UserPrefs ORDER BY pmail" );
527 while ( my $ref = $sth -> fetchrow_hashref ()) {
528 push @$res, { mail
=> $ref ->{ pmail
} };
534 my $quarantine_api = sub {
535 my ( $param, $quartype, $check_pmail ) = @_ ;
537 my $rpcenv = PMG
:: RESTEnvironment-
> get ();
538 my $authuser = $rpcenv -> get_user ();
540 my $start = $param ->{ starttime
} // ( time - 86400 );
541 my $end = $param ->{ endtime
} // ( $start + 86400 );
546 my $role = $rpcenv -> get_role ();
547 $pmail = $verify_optional_pmail ->( $authuser, $role, $param ->{ pmail
});
548 $select = "SELECT * " .
549 "FROM CMailStore, CMSReceivers WHERE " .
550 "pmail = ? AND time >= $start AND time < $end AND " .
551 "QType = ' $quartype ' AND CID = CMailStore_CID AND RID = CMailStore_RID " .
552 "AND Status = 'N' ORDER BY pmail, time, receiver" ;
554 $select = "SELECT * " .
555 "FROM CMailStore, CMSReceivers WHERE " .
556 "time >= $start AND time < $end AND " .
557 "QType = ' $quartype ' AND CID = CMailStore_CID AND RID = CMailStore_RID " .
558 "AND Status = 'N' ORDER BY time, receiver" ;
563 my $dbh = PMG
:: DBTools
:: open_ruledb
();
565 my $sth = $dbh -> prepare ( $select );
568 $sth -> execute ( $pmail );
573 while ( my $ref = $sth -> fetchrow_hashref ()) {
574 my $data = $parse_header_info ->( $ref );
581 __PACKAGE__-
> register_method ({
585 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' , 'quser' ] },
586 description
=> "Get a list of quarantined spam mails in the given timeframe (default the last 24 hours) for the given user." ,
588 additionalProperties
=> 0 ,
590 starttime
=> get_standard_option
( 'pmg-starttime' ),
591 endtime
=> get_standard_option
( 'pmg-endtime' ),
592 pmail
=> $pmail_param_type,
601 description
=> 'Unique ID' ,
605 description
=> "Size of raw email." ,
609 description
=> "SMTP envelope sender." ,
613 description
=> "Header 'From' field." ,
617 description
=> "Header 'Sender' field." ,
622 description
=> "Receiver email address" ,
626 description
=> "Header 'Subject' field." ,
630 description
=> "Receive time stamp" ,
634 description
=> "Spam score." ,
642 return $quarantine_api ->( $param, 'S' , 1 );
645 __PACKAGE__-
> register_method ({
649 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' ] },
650 description
=> "Get a list of quarantined virus mails in the given timeframe (default the last 24 hours)." ,
652 additionalProperties
=> 0 ,
654 starttime
=> get_standard_option
( 'pmg-starttime' ),
655 endtime
=> get_standard_option
( 'pmg-endtime' ),
664 description
=> 'Unique ID' ,
668 description
=> "Size of raw email." ,
672 description
=> "SMTP envelope sender." ,
676 description
=> "Header 'From' field." ,
680 description
=> "Header 'Sender' field." ,
685 description
=> "Receiver email address" ,
689 description
=> "Header 'Subject' field." ,
693 description
=> "Receive time stamp" ,
697 description
=> "Virus name." ,
705 return $quarantine_api ->( $param, 'V' );
708 __PACKAGE__-
> register_method ({
709 name
=> 'attachment' ,
710 path
=> 'attachment' ,
712 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' ] },
713 description
=> "Get a list of quarantined attachment mails in the given timeframe (default the last 24 hours)." ,
715 additionalProperties
=> 0 ,
717 starttime
=> get_standard_option
( 'pmg-starttime' ),
718 endtime
=> get_standard_option
( 'pmg-endtime' ),
727 description
=> 'Unique ID' ,
731 description
=> "Size of raw email." ,
735 description
=> "SMTP envelope sender." ,
739 description
=> "Header 'From' field." ,
743 description
=> "Header 'Sender' field." ,
748 description
=> "Receiver email address" ,
752 description
=> "Header 'Subject' field." ,
756 description
=> "Receive time stamp" ,
764 return $quarantine_api ->( $param, 'A' );
767 __PACKAGE__-
> register_method ({
768 name
=> 'virusstatus' ,
769 path
=> 'virusstatus' ,
771 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' ] },
772 description
=> "Get Virus Quarantine Status" ,
774 additionalProperties
=> 0 ,
781 description
=> 'Number of stored mails.' ,
785 description
=> "Estimated disk space usage in MByte." ,
789 description
=> "Average size of stored mails in bytes." ,
797 my $dbh = PMG
:: DBTools
:: open_ruledb
();
798 my $ref = PMG
:: DBTools
:: get_quarantine_count
( $dbh, 'V' );
800 delete $ref ->{ avgspam
};
805 my $get_and_check_mail = sub {
806 my ( $id, $rpcenv, $dbh ) = @_ ;
808 my ( $cid, $rid, $tid ) = $id =~ m/^C(\d+)R(\d+)T(\d+)$/ ;
814 $dbh = PMG
:: DBTools
:: open_ruledb
();
817 my $ref = PMG
:: DBTools
:: load_mail_data
( $dbh, $cid, $rid, $tid );
819 my $authuser = $rpcenv -> get_user ();
820 my $role = $rpcenv -> get_role ();
822 if ( $role eq 'quser' ) {
823 my $quar_username = $ref ->{ pmail
} . ' @quarantine ' ;
824 raise_perm_exc
( "mail does not belong to user ' $authuser ' ( $ref ->{pmail})" )
825 if $authuser ne $quar_username ;
831 __PACKAGE__-
> register_method ({
835 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' , 'quser' ] },
836 description
=> "Get email data. There is a special formatter called 'htmlmail' to get sanitized html view of the mail content (use the '/api2/htmlmail/quarantine/content' url)." ,
838 additionalProperties
=> 0 ,
841 description
=> 'Unique ID' ,
843 pattern
=> 'C\d+R\d+T\d+' ,
847 description
=> "Display 'raw' eml data. Deactivates size limit." ,
858 description
=> 'Unique ID' ,
862 description
=> "Size of raw email." ,
866 description
=> "SMTP envelope sender." ,
870 description
=> "Header 'From' field." ,
874 description
=> "Header 'Sender' field." ,
879 description
=> "Receiver email address" ,
883 description
=> "Header 'Subject' field." ,
887 description
=> "Receive time stamp" ,
891 description
=> "Spam score." ,
895 description
=> "Information about matched spam tests (name, score, desc, url)." ,
899 description
=> "Raw email header data." ,
903 description
=> "Raw email data (first 4096 bytes). Useful for preview. NOTE: The 'htmlmail' formatter displays the whole email." ,
911 my $rpcenv = PMG
:: RESTEnvironment-
> get ();
912 my $format = $rpcenv -> get_format ();
914 my $raw = $param ->{ raw
} // 0 ;
916 my $ref = $get_and_check_mail ->( $param ->{ id
}, $rpcenv );
918 my $res = $parse_header_info ->( $ref );
920 my $filename = $ref ->{ file
};
921 my $spooldir = $PMG :: MailQueue
:: spooldir
;
923 my $path = " $spooldir/$filename " ;
925 if ( $format eq 'htmlmail' ) {
927 my $cfg = PMG
:: Config-
> new ();
928 my $viewimages = $cfg -> get ( 'spamquar' , 'viewimages' );
929 my $allowhref = $cfg -> get ( 'spamquar' , 'allowhrefs' );
931 $res ->{ content
} = PMG
:: HTMLMail
:: email_to_html
( $path, $raw, $viewimages, $allowhref ) // 'unable to parse mail' ;
933 # to make result verification happy
936 $res ->{ spamlevel
} = 0 ;
937 $res ->{ spaminfo
} = [];
939 # include additional details
941 # we want to get the whole email in raw mode
942 my $maxbytes = (! $raw ) ?
4096 : undef ;
944 my ( $header, $content ) = PMG
:: HTMLMail
:: read_raw_email
( $path, $maxbytes );
946 $res ->{ file
} = $ref ->{ file
};
947 $res ->{ spaminfo
} = decode_spaminfo
( $ref ->{ info
});
948 $res ->{ header
} = $header ;
949 $res ->{ content
} = $content ;
956 my $get_attachments = sub {
957 my ( $mailid, $dumpdir, $with_path ) = @_ ;
959 my $rpcenv = PMG
:: RESTEnvironment-
> get ();
961 my $ref = $get_and_check_mail ->( $mailid, $rpcenv );
963 my $filename = $ref ->{ file
};
964 my $spooldir = $PMG :: MailQueue
:: spooldir
;
966 my $parser = PMG
:: MIMEUtils
:: new_mime_parser
({
969 extract_uuencode
=> 0 ,
973 my $entity = $parser -> parse_open ( " $spooldir/$filename " );
974 PMG
:: MIMEUtils
:: fixup_multipart
( $entity );
975 PMG
:: MailQueue
:: decode_entities
( $parser, 'attachmentquarantine' , $entity );
980 PMG
:: MIMEUtils
:: traverse_mime_parts
( $entity, sub {
982 my $name = PMG
:: Utils
:: extract_filename
( $part -> head ) || "part- $id " ;
983 my $attachment_path = $part ->{ PMX_decoded_path
};
984 return if ! $attachment_path || ! - f
$attachment_path ;
985 my $size = - s
$attachment_path // 0 ;
990 'content-type' => $part -> head -> mime_attr ( 'content-type' ),
992 $entry ->{ path
} = $attachment_path if $with_path ;
1000 __PACKAGE__-
> register_method ({
1001 name
=> 'listattachments' ,
1002 path
=> 'listattachments' ,
1004 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' ] },
1005 description
=> "Get Attachments for E-Mail in Quarantine." ,
1007 additionalProperties
=> 0 ,
1010 description
=> 'Unique ID' ,
1012 pattern
=> 'C\d+R\d+T\d+' ,
1023 description
=> 'Attachment ID' ,
1027 description
=> "Size of raw attachment in bytes." ,
1031 description
=> "Raw email header data." ,
1035 description
=> "Raw email header data." ,
1044 my $dumpdir = "/run/pmgproxy/pmg- $param ->{id}- $$ " ;
1045 my $res = $get_attachments ->( $param ->{ id
}, $dumpdir );
1052 __PACKAGE__-
> register_method ({
1056 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'audit' , 'quser' ] },
1057 description
=> "Download E-Mail or Attachment from Quarantine." ,
1060 additionalProperties
=> 0 ,
1063 description
=> 'Unique ID' ,
1065 pattern
=> 'C\d+R\d+T\d+' ,
1069 description
=> "The Attachment ID for the mail." ,
1081 my $mailid = $param ->{ mailid
};
1082 my $attachmentid = $param ->{ attachmentid
};
1084 my $dumpdir = "/run/pmgproxy/pmg- $mailid - $$/ " ;
1087 if ( $attachmentid ) {
1088 my $attachments = $get_attachments ->( $mailid, $dumpdir, 1 );
1089 $res = $attachments ->[ $attachmentid ];
1091 raise_param_exc
({ attachmentid
=> "Invalid Attachment ID for Mail." });
1094 my $rpcenv = PMG
:: RESTEnvironment-
> get ();
1095 my $ref = $get_and_check_mail ->( $mailid, $rpcenv );
1096 my $spooldir = $PMG :: MailQueue
:: spooldir
;
1099 'content-type' => 'message/rfc822' ,
1100 path
=> " $spooldir/$ref ->{file}" ,
1104 $res ->{ fh
} = IO
:: File-
> new ( $res ->{ path
}, '<' ) ||
1105 die "unable to open file ' $res ->{path}' - $!\n " ;
1107 rmtree
$dumpdir if - e
$dumpdir ;
1113 PVE
:: APIServer
:: Formatter
:: register_page_formatter
(
1114 'format' => 'htmlmail' ,
1116 path
=> '/quarantine/content' ,
1118 my ( $res, $data, $param, $path, $auth, $config ) = @_ ;
1120 if (! HTTP
:: Status
:: is_success
( $res ->{ status
})) {
1121 return ( "Error $res ->{status}: $res ->{message}" , "text/plain" );
1124 my $ct = "text/html;charset=UTF-8" ;
1126 my $raw = $data ->{ content
};
1128 return ( encode
( 'UTF-8' , $raw ), $ct, 1 );
1131 __PACKAGE__-
> register_method ({
1135 description
=> "Execute quarantine actions." ,
1136 permissions
=> { check
=> [ 'admin' , 'qmanager' , 'quser' ] },
1139 additionalProperties
=> 0 ,
1142 description
=> 'Unique IDs, seperate with ;' ,
1144 pattern
=> 'C\d+R\d+T\d+(;C\d+R\d+T\d+)*' ,
1147 description
=> 'Action - specify what you want to do with the mail.' ,
1149 enum
=> [ 'whitelist' , 'blacklist' , 'deliver' , 'delete' ],
1153 returns
=> { type
=> "null" },
1157 my $rpcenv = PMG
:: RESTEnvironment-
> get ();
1158 my $action = $param ->{ action
};
1159 my @idlist = split ( ';' , $param ->{ id
});
1161 my $dbh = PMG
:: DBTools
:: open_ruledb
();
1163 for my $id ( @idlist ) {
1165 my $ref = $get_and_check_mail ->( $id, $rpcenv, $dbh );
1166 my $sender = $get_real_sender ->( $ref );
1168 if ( $action eq 'whitelist' ) {
1169 PMG
:: Quarantine
:: add_to_blackwhite
( $dbh, $ref ->{ pmail
}, 'WL' , [ $sender ]);
1170 } elsif ( $action eq 'blacklist' ) {
1171 PMG
:: Quarantine
:: add_to_blackwhite
( $dbh, $ref ->{ pmail
}, 'BL' , [ $sender ]);
1172 } elsif ( $action eq 'deliver' ) {
1173 PMG
:: Quarantine
:: deliver_quarantined_mail
( $dbh, $ref, $ref ->{ receiver
} // $ref ->{ pmail
});
1174 } elsif ( $action eq 'delete' ) {
1175 PMG
:: Quarantine
:: delete_quarantined_mail
( $dbh, $ref );
1177 die "internal error" ; # should not be reached