1MIME::Words(3)        User Contributed Perl Documentation       MIME::Words(3)
2
3
4

NAME

6       MIME::Words - deal with RFC 2047 encoded words
7

SYNOPSIS

9       Before reading further, you should see MIME::Tools to make sure that
10       you understand where this module fits into the grand scheme of things.
11       Go on, do it now.  I'll wait.
12
13       Ready?  Ok...
14
15           use MIME::Words qw(:all);
16
17           ### Decode the string into another string, forgetting the charsets:
18           $decoded = decode_mimewords(
19                 'To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>',
20                 );
21
22           ### Split string into array of decoded [DATA,CHARSET] pairs:
23           @decoded = decode_mimewords(
24                 'To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>',
25                 );
26
27           ### Encode a single unsafe word:
28           $encoded = encode_mimeword("\xABFran\xE7ois\xBB");
29
30           ### Encode a string, trying to find the unsafe words inside it:
31           $encoded = encode_mimewords("Me and \xABFran\xE7ois\xBB in town");
32

DESCRIPTION

34       Fellow Americans, you probably won't know what the hell this module is
35       for.  Europeans, Russians, et al, you probably do.  ":-)".
36
37       For example, here's a valid MIME header you might get:
38
39             From: =?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu>
40             To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>
41             CC: =?ISO-8859-1?Q?Andr=E9_?= Pirard <PIRARD@vm1.ulg.ac.be>
42             Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=
43              =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=
44              =?US-ASCII?Q?.._cool!?=
45
46       The fields basically decode to (sorry, I can only approximate the Latin
47       characters with 7 bit sequences /o and 'e):
48
49             From: Keith Moore <moore@cs.utk.edu>
50             To: Keld J/orn Simonsen <keld@dkuug.dk>
51             CC: Andr'e  Pirard <PIRARD@vm1.ulg.ac.be>
52             Subject: If you can read this you understand the example... cool!
53

PUBLIC INTERFACE

55       decode_mimewords ENCODED
56           Function.  Go through the string looking for RFC 2047-style "Q"
57           (quoted-printable, sort of) or "B" (base64) encoding, and decode
58           them.
59
60           In an array context, splits the ENCODED string into a list of
61           decoded "[DATA, CHARSET]" pairs, and returns that list.  Unencoded
62           data are returned in a 1-element array "[DATA]", giving an
63           effective CHARSET of "undef".
64
65               $enc = '=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>';
66               foreach (decode_mimewords($enc)) {
67                   print "", ($_->[1] || 'US-ASCII'), ": ", $_->[0], "\n";
68               }
69
70           In a scalar context, joins the "data" elements of the above list
71           together, and returns that.  Warning: this is information-lossy,
72           and probably not what you want, but if you know that all charsets
73           in the ENCODED string are identical, it might be useful to you.
74           (Before you use this, please see "unmime" in MIME::WordDecoder,
75           which is probably what you want.)
76
77           In the event of a syntax error, $@ will be set to a description of
78           the error, but parsing will continue as best as possible (so as to
79           get something back when decoding headers).  $@ will be false if no
80           error was detected.
81
82           Any arguments past the ENCODED string are taken to define a hash of
83           options:
84
85       encode_mimeword RAW, [ENCODING], [CHARSET]
86           Function.  Encode a single RAW "word" that has unsafe characters.
87           The "word" will be encoded in its entirety.
88
89               ### Encode "<<Franc,ois>>":
90               $encoded = encode_mimeword("\xABFran\xE7ois\xBB");
91
92           You may specify the ENCODING ("Q" or "B"), which defaults to "Q".
93           You may specify the CHARSET, which defaults to "iso-8859-1".
94
95       encode_mimewords RAW, [OPTS]
96           Function.  Given a RAW string, try to find and encode all "unsafe"
97           sequences of characters:
98
99               ### Encode a string with some unsafe "words":
100               $encoded = encode_mimewords("Me and \xABFran\xE7ois\xBB");
101
102           Returns the encoded string.  Any arguments past the RAW string are
103           taken to define a hash of options:
104
105           Charset
106               Encode all unsafe stuff with this charset.  Default is
107               'ISO-8859-1', a.k.a. "Latin-1".
108
109           Encoding
110               The encoding to use, "q" or "b".  The default is "q".
111
112           Warning: this is a quick-and-dirty solution, intended for character
113           sets which overlap ASCII.  It does not comply with the RFC 2047
114           rules regarding the use of encoded words in message headers.  You
115           may want to roll your own variant, using "encode_mimeword()", for
116           your application.  Thanks to Jan Kasprzak for reminding me about
117           this problem.
118

SEE ALSO

120       MIME::Base64, MIME::QuotedPrint, MIME::Tools
121
122       For other implementations of this or similar functionality
123       (particularly, ones with proper UTF8 support), see:
124
125       Encode::MIME::Header, MIME::EncWords, MIME::AltWords
126
127       At some future point, one of these implementations will likely replace
128       MIME::Words and MIME::Words will become deprecated.
129

NOTES

131       Exports its principle functions by default, in keeping with
132       MIME::Base64 and MIME::QuotedPrint.
133

AUTHOR

135       Eryq (eryq@zeegee.com), ZeeGee Software Inc (http://www.zeegee.com).
136       Dianne Skoll (dfs@roaringpenguin.com) http://www.roaringpenguin.com
137
138       All rights reserved.  This program is free software; you can
139       redistribute it and/or modify it under the same terms as Perl itself.
140
141       Thanks also to...
142
143             Kent Boortz        For providing the idea, and the baseline
144                                RFC-1522-decoding code!
145             KJJ at PrimeNet    For requesting that this be split into
146                                its own module.
147             Stephane Barizien  For reporting a nasty bug.
148
149
150
151perl v5.32.1                      2021-01-27                    MIME::Words(3)
Impressum