1 # Copyrights 1999,2001-2009 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 1.06.
15 #-------------------------------------------
18 use overload '""' => 'type'
22 #-------------------------------------------
25 sub new(@) { (bless {}, shift)->init( {@_} ) }
28 { my ($self, $args) = @_;
30 $self->{MT_type} = $args->{type}
31 or croak "ERROR: Type parameter is obligatory.";
33 $self->{MT_simplified} = $args->{simplified}
34 || ref($self)->simplified($args->{type});
36 $self->{MT_extensions} = $args->{extensions} || [];
39 = $args->{encoding} ? $args->{encoding}
40 : $self->mediaType eq 'text' ? 'quoted-printable'
43 $self->{MT_system} = $args->{system}
44 if defined $args->{system};
49 #-------------------------------------------
52 sub type() {shift->{MT_type}}
54 #-------------------------------------------
59 return $thing->{MT_simplified} unless @_;
63 $mime =~ m!^\s*(?:x\-)?([\w.+-]+)/(?:x\-)?([\w.+-]+)\s*$!i ? lc "$1/$2"
64 : $mime =~ m!text! ? "text/plain" # some silly mailers...
68 #-------------------------------------------
71 sub extensions() { @{shift->{MT_extensions}} }
73 #-------------------------------------------
76 sub encoding() {shift->{MT_encoding}}
78 #-------------------------------------------
81 sub system() {shift->{MT_system}}
83 #-------------------------------------------
86 sub mediaType() {shift->{MT_simplified} =~ m!^([\w-]+)/! ? $1 : undef}
88 sub mainType() {shift->mediaType} # Backwards compatibility
90 #-------------------------------------------
93 sub subType() {shift->{MT_simplified} =~ m!/([\w-]+)$! ? $1 : undef}
95 #-------------------------------------------
99 { local $_ = shift->{MT_type};
100 not (m/^[xX]\-/ || m!/[xX]\-!);
104 #-------------------------------------------
107 sub isBinary() { shift->{MT_encoding} eq 'base64' }
109 #-------------------------------------------
112 sub isAscii() { shift->{MT_encoding} ne 'base64' }
114 #-------------------------------------------
117 # simplified names only!
118 my %sigs = map { ($_ => 1) }
119 qw(application/pgp-keys application/pgp application/pgp-signature
120 application/pkcs10 application/pkcs7-mime application/pkcs7-signature
123 sub isSignature() { $sigs{shift->{MT_simplified}} }
125 #-------------------------------------------
129 { my ($self, $other) = @_;
131 my $type = ref $other
133 : (ref $self)->simplified($other);
135 $self->simplified cmp $type;