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

NAME

6       MIME::WordDecoder - decode RFC 2047 encoded words to a local
7       representation
8

SYNOPSIS

10       See MIME::Words for the basics of encoded words.  See "DESCRIPTION" for
11       how this class works.
12
13           use MIME::WordDecoder;
14
15
16           ### Get the default word-decoder (used by unmime()):
17           $wd = default MIME::WordDecoder;
18
19           ### Get a word-decoder which maps to ISO-8859-1 (Latin1):
20           $wd = supported MIME::WordDecoder "ISO-8859-1";
21
22
23           ### Decode a MIME string (e.g., into Latin1) via the default decoder:
24           $str = $wd->decode('To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld>');
25
26           ### Decode a string using the default decoder, non-OO style:
27           $str = unmime('To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld>');
28

DESCRIPTION

30       A MIME::WordDecoder consists, fundamentally, of a hash which maps a
31       character set name (US-ASCII, ISO-8859-1, etc.) to a subroutine which
32       knows how to take bytes in that character set and turn them into the
33       target string representation.  Ideally, this target representation
34       would be Unicode, but we don't want to overspecify the translation that
35       takes place: if you want to convert MIME strings directly to Big5,
36       that's your own decision.
37
38       The subroutine will be invoked with two arguments: DATA (the data in
39       the given character set), and CHARSET (the upcased character set name).
40
41       For example:
42
43           ### Keep 7-bit characters as-is, convert 8-bit characters to '#':
44           sub keep7bit {
45               local $_ = shift;
46               tr/\x00-\x7F/#/c;
47               $_;
48           }
49
50       Here's a decoder which uses that:
51
52          ### Construct a decoder:
53          $wd = MIME::WordDecoder->new({'US-ASCII'   => "KEEP",   ### sub { $_[0] }
54                                        'ISO-8859-1' => \&keep7bit,
55                                        'ISO-8859-2' => \&keep7bit,
56                                        'Big5'       => "WARN",
57                                        '*'          => "DIE"});
58
59          ### Convert some MIME text to a pure ASCII string...
60          $ascii = $wd->decode('To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld>');
61
62          ### ...which will now hold: "To: Keld J#rn Simonsen <keld>"
63

PUBLIC INTERFACE

65       default [DECODER]
66           Class method.  Get/set the default DECODER object.
67
68       supported CHARSET, [DECODER]
69           Class method.  If just CHARSET is given, returns a decoder object
70           which maps data into that character set (the character set is
71           forced to all-uppercase).
72
73               $wd = supported MIME::WordDecoder "ISO-8859-1";
74
75           If DECODER is given, installs such an object:
76
77               MIME::WordDecoder->supported("ISO-8859-1" =>
78                                            (new MIME::WordDecoder::ISO_8859 "1"));
79
80           You should not override this method.
81
82       new [\@HANDLERS]
83           Class method, constructor.  If \@HANDLERS is given, then @HANDLERS
84           is passed to handler() to initiallize the internal map.
85
86       handler CHARSET=>\&SUBREF, ...
87           Instance method.  Set the handler SUBREF for a given CHARSET, for
88           as many pairs as you care to supply.
89
90           When performing the translation of a MIME-encoded string, a given
91           SUBREF will be invoked when translating a block of text in
92           character set CHARSET.  The subroutine will be invoked with the
93           following arguments:
94
95               DATA    - the data in the given character set.
96               CHARSET - the upcased character set name, which may prove useful
97                         if you are using the same SUBREF for multiple CHARSETs.
98               DECODER - the decoder itself, if it contains configuration information
99                         that your handler function needs.
100
101           For example:
102
103               $wd = new MIME::WordDecoder;
104               $wd->handler('US-ASCII'   => "KEEP");
105               $wd->handler('ISO-8859-1' => \&handle_latin1,
106                            'ISO-8859-2' => \&handle_latin1,
107                            '*'          => "DIE");
108
109           Notice that, much as with %SIG, the SUBREF can also be taken from a
110           set of special keywords:
111
112              KEEP     Pass data through unchanged.
113              IGNORE   Ignore data in this character set, without warning.
114              WARN     Ignore data in this character set, with warning.
115              DIE      Fatal exception with "can't handle character set" message.
116
117           The subroutine for the special CHARSET of 'raw' is used for raw
118           (non-MIME-encoded) text, which is supposed to be US-ASCII.  The
119           handler for 'raw' defaults to whatever was specified for 'US-ASCII'
120           at the time of construction.
121
122           The subroutine for the special CHARSET of '*' is used for any
123           unrecognized character set.  The default action for '*' is WARN.
124
125       decode STRING
126           Instance method.  Decode a STRING which might contain MIME-encoded
127           components into a local representation (e.g., UTF-8, etc.).
128
129       unmime STRING
130           Function, exported.  Decode the given STRING using the default()
131           decoder.  See default().
132

SUBCLASSES

134       MIME::WordDecoder::ISO_8859
135           A simple decoder which keeps US-ASCII and the 7-bit characters of
136           ISO-8859 character sets and UTF8, and also keeps 8-bit characters
137           from the indicated character set.
138
139               ### Construct:
140               $wd = new MIME::WordDecoder::ISO_8859 2;    ### ISO-8859-2
141
142               ### What to translate unknown characters to (can also use empty):
143               ### Default is "?".
144               $wd->unknown("?");
145
146               ### Collapse runs of unknown characters to a single unknown()?
147               ### Default is false.
148               $wd->collapse(1);
149
150           According to http://czyborra.com/charsets/iso8859.html (ca.
151           November 2000):
152
153           ISO 8859 is a full series of 10 (and soon even more) standardized
154           multilingual single-byte coded (8bit) graphic character sets for
155           writing in alphabetic languages:
156
157               1. Latin1 (West European)
158               2. Latin2 (East European)
159               3. Latin3 (South European)
160               4. Latin4 (North European)
161               5. Cyrillic
162               6. Arabic
163               7. Greek
164               8. Hebrew
165               9. Latin5 (Turkish)
166              10. Latin6 (Nordic)
167
168           The ISO 8859 charsets are not even remotely as complete as the
169           truly great Unicode but they have been around and usable for quite
170           a while (first registered Internet charsets for use with MIME) and
171           have already offered a major improvement over the plain 7bit US-
172           ASCII.
173
174           Characters 0 to 127 are always identical with US-ASCII and the
175           positions 128 to 159 hold some less used control characters: the
176           so-called C1 set from ISO 6429.
177
178       MIME::WordDecoder::US_ASCII
179           A subclass of the ISO-8859-1 decoder which discards 8-bit
180           characters.  You're probably better off using ISO-8859-1.
181

SEE ALSO

183       MIME::Tools
184

AUTHOR

186       Eryq (eryq@zeegee.com), ZeeGee Software Inc (http://www.zeegee.com).
187       David F. Skoll (dfs@roaringpenguin.com) http://www.roaringpenguin.com
188
189
190
191perl v5.12.0                      2008-06-30              MIME::WordDecoder(3)
Impressum