1MIME::Field::ContType(3U)ser Contributed Perl DocumentatiMoInME::Field::ContType(3)
2
3
4
6 MIME::Field::ContType - a "Content-type" field
7
9 A subclass of Mail::Field.
10
11 Don't use this class directly... its name may change in the future!
12 Instead, ask Mail::Field for new instances based on the field name!
13
15 use Mail::Field;
16 use MIME::Head;
17
18 # Create an instance from some text:
19 $field = Mail::Field->new('Content-type',
20 'text/HTML; charset="US-ASCII"');
21
22 # Get the MIME type, like 'text/plain' or 'x-foobar'.
23 # Returns 'text/plain' as default, as per RFC 2045:
24 my ($type, $subtype) = split('/', $field->type);
25
26 # Get generic information:
27 print $field->name;
28
29 # Get information related to "message" type:
30 if ($type eq 'message') {
31 print $field->id;
32 print $field->number;
33 print $field->total;
34 }
35
36 # Get information related to "multipart" type:
37 if ($type eq 'multipart') {
38 print $field->boundary; # the basic value, fixed up
39 print $field->multipart_boundary; # empty if not a multipart message!
40 }
41
42 # Get information related to "text" type:
43 if ($type eq 'text') {
44 print $field->charset; # returns 'us-ascii' as default
45 }
46
48 boundary
49 Return the boundary field. The boundary is returned exactly as
50 given in the "Content-type:" field; that is, the leading double-
51 hyphen ("--") is not prepended.
52
53 (Well, almost exactly... from RFC 2046:
54
55 (If a boundary appears to end with white space, the white space
56 must be presumed to have been added by a gateway, and must be deleted.)
57
58 so we oblige and remove any trailing spaces.)
59
60 Returns the empty string if there is no boundary, or if the
61 boundary is illegal (e.g., if it is empty after all trailing
62 whitespace has been removed).
63
64 multipart_boundary
65 Like "boundary()", except that this will also return the empty
66 string if the message is not a multipart message. In other words,
67 there's an automatic sanity check.
68
69 type
70 Try real hard to determine the content type (e.g., "text/plain",
71 "image/gif", "x-weird-type", which is returned in all-lowercase.
72
73 A happy thing: the following code will work just as you would want,
74 even if there's no subtype (as in "x-weird-type")... in such a
75 case, the $subtype would simply be the empty string:
76
77 ($type, $subtype) = split('/', $head->mime_type);
78
79 If the content-type information is missing, it defaults to
80 "text/plain", as per RFC 2045:
81
82 Default RFC 2822 messages are typed by this protocol as plain text in
83 the US-ASCII character set, which can be explicitly specified as
84 "Content-type: text/plain; charset=us-ascii". If no Content-Type is
85 specified, this default is assumed.
86
87 Note: under the "be liberal in what we accept" principle, this
88 routine no longer syntax-checks the content type. If it ain't
89 empty, just downcase and return it.
90
92 Since nearly all (if not all) parameters must have non-empty values to
93 be considered valid, we just return the empty string to signify missing
94 fields. If you need to get the real underlying value, use the
95 inherited "param()" method (which returns undef if the parameter is
96 missing).
97
99 MIME::Field::ParamVal, Mail::Field
100
102 Eryq (eryq@zeegee.com), ZeeGee Software Inc (http://www.zeegee.com).
103 Dianne Skoll (dfs@roaringpenguin.com) http://www.roaringpenguin.com
104
105
106
107perl v5.34.0 2022-01-21 MIME::Field::ContType(3)