]> git.proxmox.com Git - pmg-api.git/blame - PMG/RuleDB/Attach.pm
add more ruledb classes
[pmg-api.git] / PMG / RuleDB / Attach.pm
CommitLineData
f4fe6fc4
DM
1package PMG::RuleDB::Attach;
2
3use strict;
4use warnings;
5use Carp;
6use DBI;
7use Digest::SHA;
8
9use PMG::Utils;
10use PMG::ModGroup;
11use PMG::RuleDB::Object;
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
27sub oicon {
28 return 'attach.gif';
29}
30
31sub oconfigsite {
32 return '';
33}
34
35sub oinfo {
36 return 'Attach Data to Mail';
37}
38
39sub oisedit {
40 return 0;
41}
42
43sub final {
44 return 0;
45}
46
47sub priority {
48 return 49;
49}
50
51sub new {
52 my ($type, $ogroup) = @_;
53
54 my $class = ref($type) || $type;
55
56 my $self = $class->SUPER::new(otype(), $ogroup);
57
58 return $self;
59}
60
61sub load_attr {
62 my ($type, $ruledb, $id, $ogroup, $value) = @_;
63
64 my $class = ref($type) || $type;
65
66 my $obj = $class->new ($ogroup);
67 $obj->{id} = $id;
68
69 $obj->{digest} = Digest::SHA::sha1_hex($id, $ogroup);
70
71 return $obj;
72}
73
74sub save {
75 my ($self, $ruledb) = @_;
76
77 defined($self->{ogroup}) || croak "undefined object attribute: ERROR";
78
79 if (defined ($self->{id})) {
80 # update not needed
81 } else {
82 # insert
83
84 my $sth = $ruledb->{dbh}->prepare(
85 "INSERT INTO Object (Objectgroup_ID, ObjectType) VALUES (?, ?);");
86
87 $sth->execute($self->ogroup, $self->otype);
88
89 $self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq');
90 }
91
92 return $self->{id};
93}
94
95sub execute {
96 my ($self, $queue, $ruledb, $mod_group, $targets,
97 $msginfo, $vars, $marks) = @_;
98
99 my $subgroups = $mod_group->subgroups($targets);
100
101 foreach my $ta (@$subgroups) {
102 my ($tg, $entity) = (@$ta[0], @$ta[1]);
103
104 my $path = "/var/spool/proxmox/active/$queue->{uid}";
105 $entity->attach(
106 Path => $path,
107 Filename => "original_message.eml",
108 Disposition => "attachment",
109 Type => "message/rfc822");
110 }
111}
112
113sub short_desc {
114 my $self = shift;
115
116 return "attach original mail";
117}
118
119
1201;
121
122__END__
123
124=head1 PMG::RuleDB::Attach
125
126Attach original mail.