line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 1999-2022 by [Mark Overmeer ]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.03. |
5
|
|
|
|
|
|
|
# This code is part of distribution MIME::Types. Meta-POD processed with |
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package MIME::Type; |
10
|
6
|
|
|
6
|
|
144428
|
use vars '$VERSION'; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
332
|
|
11
|
|
|
|
|
|
|
$VERSION = '2.23'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
|
30
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
119
|
|
15
|
|
|
|
|
|
|
|
16
|
6
|
|
|
6
|
|
25
|
use Carp 'croak'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
347
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#------------------------------------------- |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use overload |
23
|
6
|
|
|
|
|
35
|
'""' => 'type' |
24
|
6
|
|
|
6
|
|
7389
|
, cmp => 'cmp'; |
|
6
|
|
|
|
|
6269
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#------------------------------------------- |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
2092
|
|
|
2092
|
1
|
8653
|
sub new(@) { (bless {}, shift)->init( {@_} ) } |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub init($) |
32
|
2092
|
|
|
2092
|
0
|
3398
|
{ my ($self, $args) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $type = $self->{MT_type} = $args->{type} |
35
|
2092
|
50
|
|
|
|
5552
|
or croak "ERROR: Type parameter is obligatory."; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$self->{MT_simplified} = $args->{simplified} |
38
|
2092
|
|
66
|
|
|
4885
|
|| $self->simplified($type); |
39
|
|
|
|
|
|
|
|
40
|
2092
|
|
100
|
|
|
5138
|
$self->{MT_extensions} = $args->{extensions} || []; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$self->{MT_encoding} |
43
|
|
|
|
|
|
|
= $args->{encoding} ? $args->{encoding} |
44
|
2092
|
100
|
|
|
|
4067
|
: $self->mediaType eq 'text' ? 'quoted-printable' |
|
|
100
|
|
|
|
|
|
45
|
|
|
|
|
|
|
: 'base64'; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$self->{MT_system} = $args->{system} |
48
|
2092
|
50
|
|
|
|
4316
|
if defined $args->{system}; |
49
|
|
|
|
|
|
|
|
50
|
2092
|
|
|
|
|
9571
|
$self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#------------------------------------------- |
54
|
|
|
|
|
|
|
|
55
|
16548
|
|
|
16548
|
1
|
40439
|
sub type() {shift->{MT_type}} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub simplified(;$) |
59
|
2179
|
|
|
2179
|
1
|
2634
|
{ my $thing = shift; |
60
|
2179
|
100
|
|
|
|
3734
|
return $thing->{MT_simplified} unless @_; |
61
|
|
|
|
|
|
|
|
62
|
2124
|
|
|
|
|
2603
|
my $mime = shift; |
63
|
|
|
|
|
|
|
|
64
|
2124
|
50
|
|
|
|
18072
|
$mime =~ m!^\s*(?:x\-)?([\w.+-]+)/(?:x\-)?([\w.+-]+)\s*$!i ? lc "$1/$2" |
|
|
100
|
|
|
|
|
|
65
|
|
|
|
|
|
|
: $mime eq 'text' ? 'text/plain' # some silly mailers... |
66
|
|
|
|
|
|
|
: undef; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
4132
|
|
|
4132
|
1
|
4585
|
sub extensions() { @{shift->{MT_extensions}} } |
|
4132
|
|
|
|
|
9227
|
|
71
|
4099
|
|
|
4099
|
1
|
14115
|
sub encoding() {shift->{MT_encoding}} |
72
|
0
|
|
|
0
|
1
|
0
|
sub system() {shift->{MT_system}} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#------------------------------------------- |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
1994
|
100
|
|
1994
|
1
|
8930
|
sub mediaType() {shift->{MT_simplified} =~ m!^([\w.-]+)/! ? $1 : undef} |
78
|
2
|
|
|
2
|
0
|
6
|
sub mainType() {shift->mediaType} # Backwards compatibility |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
2
|
50
|
|
2
|
1
|
25
|
sub subType() {shift->{MT_simplified} =~ m!/([\w+.-]+)$! ? $1 : undef} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
8
|
|
|
8
|
1
|
77
|
sub isRegistered() { lc shift->{MT_type} !~ m{^x\-|/x\-} } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# http://tools.ietf.org/html/rfc4288#section-3 |
88
|
4
|
|
|
4
|
1
|
31
|
sub isVendor() {shift->{MT_simplified} =~ m!/vnd\.!} |
89
|
4
|
|
|
4
|
1
|
24
|
sub isPersonal() {shift->{MT_simplified} =~ m!/prs\.!} |
90
|
4
|
|
|
4
|
1
|
33
|
sub isExperimental() {shift->{MT_simplified} =~ m!/x\.! } |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
4
|
|
|
4
|
1
|
498
|
sub isBinary() { shift->{MT_encoding} eq 'base64' } |
94
|
4
|
|
|
4
|
1
|
25
|
sub isText() { shift->{MT_encoding} ne 'base64' } |
95
|
|
|
|
|
|
|
*isAscii = \&isText; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# simplified names only! |
99
|
|
|
|
|
|
|
my %sigs = map +($_ => 1), |
100
|
|
|
|
|
|
|
qw(application/pgp-keys application/pgp application/pgp-signature |
101
|
|
|
|
|
|
|
application/pkcs10 application/pkcs7-mime application/pkcs7-signature |
102
|
|
|
|
|
|
|
text/vCard); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
0
|
1
|
0
|
sub isSignature() { $sigs{shift->{MT_simplified}} } |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub cmp($) |
108
|
37
|
|
|
37
|
0
|
1598
|
{ my ($self, $other) = @_; |
109
|
|
|
|
|
|
|
|
110
|
37
|
100
|
|
|
|
109
|
my $type = ref $other |
111
|
|
|
|
|
|
|
? $other->simplified |
112
|
|
|
|
|
|
|
: (ref $self)->simplified($other); |
113
|
|
|
|
|
|
|
|
114
|
37
|
|
|
|
|
70
|
$self->simplified cmp $type; |
115
|
|
|
|
|
|
|
} |
116
|
19
|
|
|
19
|
1
|
1675
|
sub equals($) { $_[0]->cmp($_[1])==0 } |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |