]>
git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/ContentTypeFilter.pm
1 package PMG
::RuleDB
::ContentTypeFilter
;
11 use PMG
::RuleDB
::MatchField
;
13 use base
qw(PMG::RuleDB::MatchField);
16 'message/delivery-status' => undef,
17 'message/disposition-notification' => undef,
18 'message/external-body' => undef,
19 'message/news' => undef,
20 'message/partial' => undef,
21 'message/rfc822' => undef,
22 'multipart/alternative' => undef,
23 'multipart/digest' => undef,
24 'multipart/encrypted' => undef,
25 'multipart/mixed' => undef,
26 'multipart/related' => undef,
27 'multipart/report' => undef,
28 'multipart/signed' => undef,
32 'application/x-msdos-program' => 'application/x-ms-dos-executable',
33 'application/java-vm' => 'application/x-java',
34 'application/x-javascript' => 'application/javascript',
38 open(DAT
, "/usr/share/mime/globs") ||
39 croak
("Could not open file $!: ERROR");
41 while (my $row = <DAT
>) {
42 next if $row =~ m/^\#/;
44 if ($row =~ m/([A-Za-z0-9-_\.]*)\/([A-Za-z0-9-_\
+\
.]*):\
*\
.(\S
{1,10})\s
*$/) {
49 $m =~ s/\./\\\./g; # quote '.'
50 $m =~ s/\+/\\\+/g; # quote '+'
53 $mtypes->{"$m"} = $mtypes->{"$m"} ?
$mtypes->{"$m"} . ",$end" : $end;
67 return 'ContentType Filter';
72 return 'contentfilter.gif';
76 my ($type, $fvalue, $ogroup) = @_;
78 my $class = ref($type) || $type;
80 # translate old values
81 if ($fvalue && (my $nt = $oldtypemap->{$fvalue})) {
85 my $self = $class->SUPER::new
('content-type', $fvalue, $ogroup);
87 $self->{mtypes
} = $mtypes;
93 my ($type, $ruledb, $id, $ogroup, $value) = @_;
95 my $class = ref($type) || $type;
97 my $obj = $class->SUPER::load_attr
($ruledb, $id, $ogroup, $value);
99 # translate old values
100 if ($obj->{field_value
} && (my $nt = $oldtypemap->{$obj->{field_value
}})) {
101 $obj->{field_value
} = $nt;
104 $obj->{mtypes
} = $mtypes;
110 my ($self, $entity) = @_;
114 # match subtypes? We currently do exact matches only.
116 if (my $id = $entity->head->mime_attr ('x-proxmox-tmp-aid')) {
119 my $header_ct = $entity->head->mime_attr ('content-type');
121 my $magic_ct = $entity->{PMX_magic_ct
};
123 my $glob_ct = $entity->{PMX_glob_ct
};
125 if ($header_ct && $header_ct =~ m
|$self->{field_value
}|) {
127 } elsif ($magic_ct && $magic_ct =~ m
|$self->{field_value
}|) {
129 } elsif ($glob_ct && $glob_ct =~ m
|$self->{field_value
}|) {
134 foreach my $part ($entity->parts) {
135 if (my $match = $self->parse_entity ($part)) {
144 my ($self, $queue, $entity, $msginfo) = @_;
146 return $self->parse_entity ($entity);
154 =head1 PMG::RuleDB::ContentTypeFilter