]>
Commit | Line | Data |
---|---|---|
f4fe6fc4 DM |
1 | package PMG::RuleDB::Attach; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
f4fe6fc4 DM |
5 | use DBI; |
6 | use Digest::SHA; | |
7 | ||
8 | use PMG::Utils; | |
9 | use PMG::ModGroup; | |
10 | use PMG::RuleDB::Object; | |
74d48a9a | 11 | use PMG::MailQueue; |
f4fe6fc4 DM |
12 | |
13 | use base qw(PMG::RuleDB::Object); | |
14 | ||
15 | sub otype { | |
16 | return 4004; | |
17 | } | |
18 | ||
19 | sub oclass { | |
20 | return 'action'; | |
21 | } | |
22 | ||
23 | sub otype_text { | |
24 | return 'Attach'; | |
25 | } | |
26 | ||
f4fe6fc4 DM |
27 | sub oisedit { |
28 | return 0; | |
29 | } | |
30 | ||
31 | sub final { | |
32 | return 0; | |
33 | } | |
34 | ||
35 | sub priority { | |
36 | return 49; | |
37 | } | |
38 | ||
39 | sub 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 | ||
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 | $obj->{digest} = Digest::SHA::sha1_hex($id, $ogroup); | |
58 | ||
59 | return $obj; | |
60 | } | |
61 | ||
62 | sub 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 | ||
83 | sub 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 | ||
102 | sub short_desc { | |
103 | my $self = shift; | |
104 | ||
105 | return "attach original mail"; | |
106 | } | |
107 | ||
108 | ||
109 | 1; | |
110 | ||
111 | __END__ | |
112 | ||
113 | =head1 PMG::RuleDB::Attach | |
114 | ||
115 | Attach original mail. |