]> git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/ReportSpam.pm
fix schema definition
[pmg-api.git] / PMG / RuleDB / ReportSpam.pm
1 package PMG::RuleDB::ReportSpam;
2
3 use strict;
4 use warnings;
5 use DBI;
6
7 use PVE::SafeSyslog;
8
9 use PMG::Utils;
10 use PMG::ModGroup;
11 use PMG::RuleDB::Object;
12
13 use base qw(PMG::RuleDB::Object);
14
15 sub otype {
16 return 4008;
17 }
18
19 sub oclass {
20 return 'action';
21 }
22
23 sub otype_text {
24 return 'Report Spam';
25 }
26
27 sub oisedit {
28 return 0;
29 }
30
31 sub final {
32 return 1;
33 }
34
35 sub priority {
36 return 97;
37 }
38
39 sub new {
40 my ($type, $ogroup) = @_;
41
42 my $class = ref($type) || $type;
43
44 my $self = $class->SUPER::new($class->otype(), $ogroup);
45
46 return $self;
47 }
48
49 sub load_attr {
50 my ($type, $ruledb, $id, $ogroup, $value) = @_;
51
52 my $class = ref($type) || $type;
53
54 my $obj = $class->new($ogroup);
55 $obj->{id} = $id;
56
57 return $obj;
58 }
59
60 sub save {
61 my ($self, $ruledb) = @_;
62
63 defined($self->{ogroup}) || return undef;
64
65 if (defined ($self->{id})) {
66 # update
67
68 # nothing to update
69
70 } else {
71 # insert
72
73 my $sth = $ruledb->{dbh}->prepare(
74 "INSERT INTO Object (Objectgroup_ID, ObjectType) VALUES (?, ?);");
75
76 $sth->execute($self->ogroup, $self->otype);
77
78 $self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq');
79 }
80
81 return $self->{id};
82 }
83
84 sub execute {
85 my ($self, $queue, $ruledb, $mod_group, $targets,
86 $msginfo, $vars, $marks) = @_;
87
88 my $subgroups = $mod_group->subgroups($targets);
89
90 foreach my $ta (@$subgroups) {
91 my ($tg, $entity) = (@$ta[0], @$ta[1]);
92
93 if ($msginfo->{testmode}) {
94 my $fh = $msginfo->{test_fh};
95 print $fh "report as spam\n";
96 } else {
97
98 my $spamtest = $queue->{sa};
99
100 $queue->{fh}->seek (0, 0);
101 *SATMP = \*{$queue->{fh}};
102 my $mail = $spamtest->parse(\*SATMP);
103
104 $spamtest->report_as_spam($mail);
105
106 $mail->finish();
107 }
108 $queue->set_status ($tg, 'delivered');
109 }
110 }
111
112 sub short_desc {
113 my $self = shift;
114
115 return "";
116 }
117
118 1;
119 __END__
120
121 =head1 PMG::RuleDB::ReportSpam
122
123 Report as SPAM.