]> git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/ArchiveFilter.pm
SMTP.pm: SMTPUTF8 is always passed with "mail" command
[pmg-api.git] / PMG / RuleDB / ArchiveFilter.pm
1 package PMG::RuleDB::ArchiveFilter;
2
3 use strict;
4 use warnings;
5 use DBI;
6 use MIME::Words;
7
8 use PVE::SafeSyslog;
9
10 use PMG::RuleDB::ContentTypeFilter;
11
12 use base qw(PMG::RuleDB::ContentTypeFilter);
13
14 sub otype {
15 return 3005;
16 }
17
18 sub otype_text {
19 return 'Archive Filter';
20 }
21
22 my $pmtypes = {
23 'proxmox/unreadable-archive' => undef,
24 };
25
26 sub new {
27 my ($type, $fvalue, $ogroup) = @_;
28
29 my $class = ref($type) || $type;
30
31 my $self = $class->SUPER::new ($fvalue, $ogroup);
32
33 return $self;
34 }
35
36 sub load_attr {
37 my ($type, $ruledb, $id, $ogroup, $value) = @_;
38
39 my $class = ref($type) || $type;
40
41 my $obj = $class->SUPER::load_attr($ruledb, $id, $ogroup, $value);
42
43 return $obj;
44 }
45
46 sub parse_entity {
47 my ($self, $entity) = @_;
48
49 my $res;
50
51 # match subtypes? We currently do exact matches only.
52
53 if (my $id = $entity->head->mime_attr ('x-proxmox-tmp-aid')) {
54 chomp $id;
55
56 my $header_ct = $entity->head->mime_attr ('content-type');
57
58 my $magic_ct = $entity->{PMX_magic_ct};
59
60 my $glob_ct = $entity->{PMX_glob_ct};
61
62 if ($header_ct && $header_ct =~ m|$self->{field_value}|) {
63 push @$res, $id;
64 } elsif ($magic_ct && $magic_ct =~ m|$self->{field_value}|) {
65 push @$res, $id;
66 } elsif ($glob_ct && $glob_ct =~ m|$self->{field_value}|) {
67 push @$res, $id;
68 } else {
69 # match inside archives
70 if (my $cts = $entity->{PMX_content_types}) {
71 foreach my $ct (keys %$cts) {
72 if ($ct =~ m|$self->{field_value}|) {
73 push @$res, $id;
74 last;
75 }
76 }
77 }
78 }
79 }
80
81 foreach my $part ($entity->parts) {
82 if (my $match = $self->parse_entity ($part)) {
83 push @$res, @$match;
84 }
85 }
86
87 return $res;
88 }
89
90 sub what_match {
91 my ($self, $queue, $entity, $msginfo) = @_;
92
93 return $self->parse_entity ($entity);
94 }
95
96 1;
97
98 __END__
99
100 =head1 PMG::RuleDB::ArchiveFilter
101
102 Content type filter for Archives