]>
git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/Remove.pm
1 package PMG
::RuleDB
::Remove
;
16 use PMG
::RuleDB
::Object
;
18 use base
qw(PMG::RuleDB::Object);
25 return 'Remove attachments';
37 return 'Remove attachments';
53 my ($type, $all, $text, $ogroup) = @_;
55 my $class = ref($type) || $type;
57 $all = 0 if !defined ($all);
59 my $self = $class->SUPER::new
(otype
(), $ogroup);
62 $self->{text
} = $text;
68 my ($type, $ruledb, $id, $ogroup, $value) = @_;
70 my $class = ref($type) || $type;
72 defined ($value) || croak
"undefined value: ERROR";
76 if ($value =~ m/^([01])(\:(.*))?$/s) {
77 $obj = $class->new($1, $3, $ogroup);
79 $obj = $class->new(0, undef, $ogroup);
84 $obj->{digest
} = Digest
::SHA
::sha1_hex
($id, $value, $ogroup);
90 my ($self, $ruledb) = @_;
92 defined($self->{ogroup
}) || croak
"undefined ogroup: ERROR";
94 my $value = $self->{all
} ?
'1' : '0';
97 $value .= ":$self->{text}";
100 if (defined ($self->{id
})) {
104 "UPDATE Object SET Value = ? WHERE ID = ?",
105 undef, $value, $self->{id
});
110 my $sth = $ruledb->{dbh
}->prepare(
111 "INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " .
112 "VALUES (?, ?, ?);");
114 $sth->execute($self->ogroup, $self->otype, $value);
116 $self->{id
} = PMG
::Utils
::lastid
($ruledb->{dbh
}, 'object_id_seq');
122 sub delete_marked_parts
{
123 my ($self, $queue, $entity, $html, $rtype, $marks) = @_;
127 my $pn = $entity->parts;
128 for (my $i = 0; $i < $pn; $i++) {
129 my $part = $entity->parts($i);
133 if ($id = $part->head->mime_attr('x-proxmox-tmp-aid')) {
137 my $ctype_part = $part->head->mime_type;
138 if (!($i == 0 && $ctype_part =~ m
|text
/.*|i
)) {
142 foreach my $m (@$marks) {
143 $found = 1 if $m eq $id;
151 my $on = PMG
::Utils
::extract_filename
($part->head) || '';
153 my $text = PMG
::Utils
::subst_values
($html, { FILENAME
=> $on } );
155 my $fname = "REMOVED_ATTACHMENT_$id." . ($rtype eq "text/html" ?
"html" : "txt");
157 my $ent = MIME
::Entity-
>build(
160 Encoding
=> "quoted-printable",
162 Disposition
=> "attachment",
163 Data
=> encode
('UTF-8', $text));
165 push (@$nparts, $ent);
167 syslog
('info', "%s: removed attachment $id ('%s')",
168 $queue->{logid
}, $on);
171 $self->delete_marked_parts($queue, $part, $html, $rtype, $marks);
172 push (@$nparts, $part);
176 $entity->parts ($nparts);
180 my ($self, $queue, $ruledb, $mod_group, $targets,
181 $msginfo, $vars, $marks) = @_;
183 if (!$self->{all
} && ($#$marks == -1)) {
188 my $subgroups = $mod_group->subgroups ($targets);
190 my $html = PMG
::Utils
::subst_values
($self->{text
}, $vars);
192 $html = "This attachment was removed: __FILENAME__\n" if !$html;
194 my $rtype = "text/plain";
196 if ($html =~ m/\<\w+\>/s) {
197 $rtype = "text/html";
200 foreach my $ta (@$subgroups) {
201 my ($tg, $entity) = (@$ta[0], @$ta[1]);
203 # handle singlepart mails
204 my $ctype = $entity->head->mime_type;
205 if (!$entity->is_multipart && (!$self->{all
} || $ctype !~ m
|text
/.*|i
)) {
206 $entity->make_multipart();
207 my $first_part = $entity->parts(0);
208 $first_part->head->mime_attr('x-proxmox-tmp-aid' => $entity->head->mime_attr('x-proxmox-tmp-aid'));
209 $entity->head->delete('x-proxmox-tmp-aid');
212 $self->delete_marked_parts($queue, $entity, $html, $rtype, $marks);
214 if ($msginfo->{testmode
}) {
215 $entity->head->mime_attr('Content-type.boundary' => '------=_TEST123456') if $entity->is_multipart;
224 return "remove all attachments";
226 return "remove matching attachments";
234 =head1 PMG::RuleDB::Remove