]> git.proxmox.com Git - pmg-api.git/blame - PMG/RuleDB/Attach.pm
fix bug #1643: add port and protocol to spamquarantine config
[pmg-api.git] / PMG / RuleDB / Attach.pm
CommitLineData
f4fe6fc4
DM
1package PMG::RuleDB::Attach;
2
3use strict;
4use warnings;
f4fe6fc4
DM
5use DBI;
6use Digest::SHA;
7
8use PMG::Utils;
9use PMG::ModGroup;
10use PMG::RuleDB::Object;
74d48a9a 11use PMG::MailQueue;
f4fe6fc4
DM
12
13use base qw(PMG::RuleDB::Object);
14
15sub otype {
16 return 4004;
17}
18
19sub oclass {
20 return 'action';
21}
22
23sub otype_text {
24 return 'Attach';
25}
26
f4fe6fc4
DM
27sub oisedit {
28 return 0;
29}
30
31sub final {
32 return 0;
33}
34
35sub priority {
36 return 49;
37}
38
39sub new {
40 my ($type, $ogroup) = @_;
41
42 my $class = ref($type) || $type;
43
7a2cf7e6 44 my $self = $class->SUPER::new($class->otype(), $ogroup);
f4fe6fc4
DM
45
46 return $self;
47}
48
49sub 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 $obj->{digest} = Digest::SHA::sha1_hex($id, $ogroup);
58
59 return $obj;
60}
61
62sub save {
63 my ($self, $ruledb) = @_;
64
9ef3f143 65 defined($self->{ogroup}) || die "undefined object attribute: ERROR";
f4fe6fc4
DM
66
67 if (defined ($self->{id})) {
68 # update not needed
69 } else {
70 # insert
71
72 my $sth = $ruledb->{dbh}->prepare(
73 "INSERT INTO Object (Objectgroup_ID, ObjectType) VALUES (?, ?);");
74
75 $sth->execute($self->ogroup, $self->otype);
76
77 $self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq');
78 }
79
80 return $self->{id};
81}
82
83sub execute {
84 my ($self, $queue, $ruledb, $mod_group, $targets,
85 $msginfo, $vars, $marks) = @_;
86
87 my $subgroups = $mod_group->subgroups($targets);
88
89 foreach my $ta (@$subgroups) {
90 my ($tg, $entity) = (@$ta[0], @$ta[1]);
91
74d48a9a
DM
92 my $spooldir = $PMG::MailQueue::spooldir;
93 my $path = "$spooldir/active/$queue->{uid}";
f4fe6fc4
DM
94 $entity->attach(
95 Path => $path,
96 Filename => "original_message.eml",
97 Disposition => "attachment",
98 Type => "message/rfc822");
99 }
100}
101
102sub short_desc {
103 my $self = shift;
104
105 return "attach original mail";
106}
107
108
1091;
110
111__END__
112
113=head1 PMG::RuleDB::Attach
114
115Attach original mail.