]>
git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/Remove.pm
1 package PMG
::RuleDB
::Remove
;
15 use PMG
::RuleDB
::Object
;
17 use base
qw(PMG::RuleDB::Object);
24 return 'Remove attachments';
44 my ($type, $all, $text, $ogroup) = @_;
46 my $class = ref($type) || $type;
48 $all = 0 if !defined ($all);
50 my $self = $class->SUPER::new
($class->otype(), $ogroup);
53 $self->{text
} = $text;
59 my ($type, $ruledb, $id, $ogroup, $value) = @_;
61 my $class = ref($type) || $type;
63 defined ($value) || die "undefined value: ERROR";
67 if ($value =~ m/^([01])(\:(.*))?$/s) {
68 $obj = $class->new($1, $3, $ogroup);
70 $obj = $class->new(0, undef, $ogroup);
75 $obj->{digest
} = Digest
::SHA
::sha1_hex
($id, $value, $ogroup);
81 my ($self, $ruledb) = @_;
83 defined($self->{ogroup
}) || die "undefined ogroup: ERROR";
85 my $value = $self->{all
} ?
'1' : '0';
88 $value .= ":$self->{text}";
91 if (defined ($self->{id
})) {
95 "UPDATE Object SET Value = ? WHERE ID = ?",
96 undef, $value, $self->{id
});
101 my $sth = $ruledb->{dbh
}->prepare(
102 "INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " .
103 "VALUES (?, ?, ?);");
105 $sth->execute($self->ogroup, $self->otype, $value);
107 $self->{id
} = PMG
::Utils
::lastid
($ruledb->{dbh
}, 'object_id_seq');
113 sub delete_marked_parts
{
114 my ($self, $queue, $entity, $html, $rtype, $marks) = @_;
118 my $pn = $entity->parts;
119 for (my $i = 0; $i < $pn; $i++) {
120 my $part = $entity->parts($i);
124 if ($id = $part->head->mime_attr('x-proxmox-tmp-aid')) {
128 my $ctype_part = $part->head->mime_type;
129 if (!($i == 0 && $ctype_part =~ m
|text
/.*|i
)) {
133 foreach my $m (@$marks) {
134 $found = 1 if $m eq $id;
142 my $on = PMG
::Utils
::extract_filename
($part->head) || '';
144 my $text = PMG
::Utils
::subst_values
($html, { FILENAME
=> $on } );
146 my $fname = "REMOVED_ATTACHMENT_$id." . ($rtype eq "text/html" ?
"html" : "txt");
148 my $ent = MIME
::Entity-
>build(
151 Encoding
=> "quoted-printable",
153 Disposition
=> "attachment",
154 Data
=> encode
('UTF-8', $text));
156 push (@$nparts, $ent);
158 syslog
('info', "%s: removed attachment $id ('%s')",
159 $queue->{logid
}, $on);
162 $self->delete_marked_parts($queue, $part, $html, $rtype, $marks);
163 push (@$nparts, $part);
167 $entity->parts ($nparts);
171 my ($self, $queue, $ruledb, $mod_group, $targets,
172 $msginfo, $vars, $marks) = @_;
174 if (!$self->{all
} && ($#$marks == -1)) {
179 my $subgroups = $mod_group->subgroups ($targets);
181 my $html = PMG
::Utils
::subst_values
($self->{text
}, $vars);
183 $html = "This attachment was removed: __FILENAME__\n" if !$html;
185 my $rtype = "text/plain";
187 if ($html =~ m/\<\w+\>/s) {
188 $rtype = "text/html";
191 foreach my $ta (@$subgroups) {
192 my ($tg, $entity) = (@$ta[0], @$ta[1]);
194 # handle singlepart mails
195 my $ctype = $entity->head->mime_type;
196 if (!$entity->is_multipart && (!$self->{all
} || $ctype !~ m
|text
/.*|i
)) {
197 $entity->make_multipart();
198 my $first_part = $entity->parts(0);
199 $first_part->head->mime_attr('x-proxmox-tmp-aid' => $entity->head->mime_attr('x-proxmox-tmp-aid'));
200 $entity->head->delete('x-proxmox-tmp-aid');
203 $self->delete_marked_parts($queue, $entity, $html, $rtype, $marks);
205 if ($msginfo->{testmode
}) {
206 $entity->head->mime_attr('Content-type.boundary' => '------=_TEST123456') if $entity->is_multipart;
215 return "remove all attachments";
217 return "remove matching attachments";
226 description
=> "Remove all attachments",
231 description
=> "The replacement text.",
242 text
=> $self->{text
},
248 my ($self, $param) = @_;
250 $self->{text
} = $param->{text
};
251 $self->{all
} = $param->{all
} ?
1 : 0;
257 =head1 PMG::RuleDB::Remove