1Email::MIME::ContentTypUes(e3r)Contributed Perl DocumentEamtaiioln::MIME::ContentType(3)
2
3
4
6 Email::MIME::ContentType - Parse and build a MIME Content-Type or
7 Content-Disposition Header
8
10 version 1.028
11
13 use Email::MIME::ContentType;
14
15 # Content-Type: text/plain; charset="us-ascii"; format=flowed
16 my $ct = 'text/plain; charset="us-ascii"; format=flowed';
17 my $data = parse_content_type($ct);
18
19 $data = {
20 type => "text",
21 subtype => "plain",
22 attributes => {
23 charset => "us-ascii",
24 format => "flowed"
25 }
26 };
27
28 my $ct_new = build_content_type($data);
29 # text/plain; charset=us-ascii; format=flowed
30
31
32 # Content-Type: application/x-stuff;
33 # title*0*=us-ascii'en'This%20is%20even%20more%20;
34 # title*1*=%2A%2A%2Afun%2A%2A%2A%20;
35 # title*2="isn't it!"
36 my $ct = q(application/x-stuff;
37 title*0*=us-ascii'en'This%20is%20even%20more%20;
38 title*1*=%2A%2A%2Afun%2A%2A%2A%20;
39 title*2="isn't it!");
40 my $data = parse_content_type($ct);
41
42 $data = {
43 type => "application",
44 subtype => "x-stuff",
45 attributes => {
46 title => "This is even more ***fun*** isn't it!"
47 }
48 };
49
50
51 # Content-Disposition: attachment; filename=genome.jpeg;
52 # modification-date="Wed, 12 Feb 1997 16:29:51 -0500"
53 my $cd = q(attachment; filename=genome.jpeg;
54 modification-date="Wed, 12 Feb 1997 16:29:51 -0500");
55 my $data = parse_content_disposition($cd);
56
57 $data = {
58 type => "attachment",
59 attributes => {
60 filename => "genome.jpeg",
61 "modification-date" => "Wed, 12 Feb 1997 16:29:51 -0500"
62 }
63 };
64
65 my $cd_new = build_content_disposition($data);
66 # attachment; filename=genome.jpeg; modification-date="Wed, 12 Feb 1997 16:29:51 -0500"
67
69 This library should run on perls released even a long time ago. It
70 should work on any version of perl released in the last five years.
71
72 Although it may work on older versions of perl, no guarantee is made
73 that the minimum required version will not be increased. The version
74 may be increased for any reason, and there is no promise that patches
75 will be accepted to lower the minimum required perl.
76
78 parse_content_type
79 This routine is exported by default.
80
81 This routine parses email content type headers according to section 5.1
82 of RFC 2045 and also RFC 2231 (Character Set and Parameter
83 Continuations). It returns a hash as above, with entries for the
84 "type", the "subtype", and a hash of "attributes".
85
86 For backward compatibility with a really unfortunate misunderstanding
87 of RFC 2045 by the early implementors of this module, "discrete" and
88 "composite" are also present in the returned hashref, with the values
89 of "type" and "subtype" respectively.
90
91 parse_content_disposition
92 This routine is exported by default.
93
94 This routine parses email Content-Disposition headers according to RFC
95 2183 and RFC 2231. It returns a hash as above, with entries for the
96 "type", and a hash of "attributes".
97
98 build_content_type
99 This routine is exported by default.
100
101 This routine builds email Content-Type header according to RFC 2045 and
102 RFC 2231. It takes a hash as above, with entries for the "type", the
103 "subtype", and optionally also a hash of "attributes". It returns a
104 string representing Content-Type header. Non-ASCII attributes are
105 encoded to UTF-8 according to Character Set section of RFC 2231.
106 Attribute which has more then 78 ASCII characters is split into more
107 attributes accorrding to Parameter Continuations of RFC 2231.
108
109 For compatibility reasons with clients which do not support RFC 2231,
110 output string contains also truncated ASCII version of any too long or
111 non-ASCII attribute. Encoding to ASCII is done via Text::Unidecode
112 module. This behavior can cause confusion by 2231-compatible MIME
113 implementations, and can be disabled by setting
114 $Email::MIME::ContentType::STRICT to true.
115
116 build_content_disposition
117 This routine is exported by default.
118
119 This routine builds email Content-Disposition header according to RFC
120 2182 and RFC 2231. It takes a hash as above, with entries for the
121 "type", and optionally also a hash of "attributes". It returns a
122 string representing Content-Disposition header. Non-ASCII or too long
123 attributes are handled in the same way like in build_content_type
124 function.
125
127 This is not a valid content-type header, according to both RFC 1521 and
128 RFC 2045:
129
130 Content-Type: type/subtype;
131
132 If a semicolon appears, a parameter must. "parse_content_type" will
133 carp if it encounters a header of this type, but you can suppress this
134 by setting $Email::MIME::ContentType::STRICT_PARAMS to a false value.
135 Please consider localizing this assignment!
136
137 Same applies for "parse_content_disposition".
138
140 • Simon Cozens <simon@cpan.org>
141
142 • Casey West <casey@geeknest.com>
143
144 • Ricardo Signes <cpan@semiotic.systems>
145
147 • Matthew Green <mrg@eterna.com.au>
148
149 • Pali <pali@cpan.org>
150
151 • Ricardo Signes <rjbs@semiotic.systems>
152
153 • Thomas Szukala <ts@abusix.com>
154
156 This software is copyright (c) 2004 by Simon Cozens.
157
158 This is free software; you can redistribute it and/or modify it under
159 the same terms as the Perl 5 programming language system itself.
160
161
162
163perl v5.36.0 2023-01-20 Email::MIME::ContentType(3)