.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "MIME::WordDecoder 3pm" .TH MIME::WordDecoder 3pm "2013-08-13" "perl v5.18.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MIME::WordDecoder \- decode RFC 2047 encoded words to a local representation .PP WARNING: Most of this module is deprecated and may disappear. The only function you should use for MIME decoding is "mime_to_perl_string". .SH "SYNOPSIS" .IX Header "SYNOPSIS" See MIME::Words for the basics of encoded words. See \*(L"\s-1DESCRIPTION\*(R"\s0 for how this class works. .PP .Vb 1 \& use MIME::WordDecoder; \& \& \& ### Get the default word\-decoder (used by unmime()): \& $wd = default MIME::WordDecoder; \& \& ### Get a word\-decoder which maps to ISO\-8859\-1 (Latin1): \& $wd = supported MIME::WordDecoder "ISO\-8859\-1"; \& \& \& ### Decode a MIME string (e.g., into Latin1) via the default decoder: \& $str = $wd\->decode(\*(AqTo: =?ISO\-8859\-1?Q?Keld_J=F8rn_Simonsen?= \*(Aq); \& \& ### Decode a string using the default decoder, non\-OO style: \& $str = unmime(\*(AqTo: =?ISO\-8859\-1?Q?Keld_J=F8rn_Simonsen?= \*(Aq); \& \& ### Decode a string to an internal Perl string, non\-OO style \& ### The result is likely to have the UTF8 flag ON. \& $str = mime_to_perl_string(\*(AqTo: =?ISO\-8859\-1?Q?Keld_J=F8rn_Simonsen?= \*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\s-1WARNING:\s0 Most of this module is deprecated and may disappear. It duplicates (badly) the function of the standard 'Encode' module. The only function you should rely on is mime_to_perl_string. .PP A MIME::WordDecoder consists, fundamentally, of a hash which maps a character set name (US-ASCII, \s-1ISO\-8859\-1,\s0 etc.) to a subroutine which knows how to take bytes in that character set and turn them into the target string representation. Ideally, this target representation would be Unicode, but we don't want to overspecify the translation that takes place: if you want to convert \s-1MIME\s0 strings directly to Big5, that's your own decision. .PP The subroutine will be invoked with two arguments: \s-1DATA \s0(the data in the given character set), and \s-1CHARSET \s0(the upcased character set name). .PP For example: .PP .Vb 6 \& ### Keep 7\-bit characters as\-is, convert 8\-bit characters to \*(Aq#\*(Aq: \& sub keep7bit { \& local $_ = shift; \& tr/\ex00\-\ex7F/#/c; \& $_; \& } .Ve .PP Here's a decoder which uses that: .PP .Vb 6 \& ### Construct a decoder: \& $wd = MIME::WordDecoder\->new({\*(AqUS\-ASCII\*(Aq => "KEEP", ### sub { $_[0] } \& \*(AqISO\-8859\-1\*(Aq => \e&keep7bit, \& \*(AqISO\-8859\-2\*(Aq => \e&keep7bit, \& \*(AqBig5\*(Aq => "WARN", \& \*(Aq*\*(Aq => "DIE"}); \& \& ### Convert some MIME text to a pure ASCII string... \& $ascii = $wd\->decode(\*(AqTo: =?ISO\-8859\-1?Q?Keld_J=F8rn_Simonsen?= \*(Aq); \& \& ### ...which will now hold: "To: Keld J#rn Simonsen " .Ve .PP The \s-1UTF\-8\s0 built-in decoder decodes everything into Perl's internal string format, possibly turning on the internal \s-1UTF8\s0 flag. Use it like this: .PP .Vb 3 \& $wd = supported MIME::WordDecoder \*(AqUTF\-8\*(Aq; \& $perl_string = $wd\->decode(\*(AqTo: =?ISO\-8859\-1?Q?Keld_J=F8rn_Simonsen?= \*(Aq); \& # perl_string will be a valid UTF\-8 string with the "UTF8" flag set. .Ve .PP Generally, you should use the \s-1UTF\-8\s0 decoder in preference to \*(L"unmime\*(R". .SH "PUBLIC INTERFACE" .IX Header "PUBLIC INTERFACE" .IP "default [\s-1DECODER\s0]" 4 .IX Item "default [DECODER]" \&\fIClass method.\fR Get/set the default \s-1DECODER\s0 object. .IP "supported \s-1CHARSET,\s0 [\s-1DECODER\s0]" 4 .IX Item "supported CHARSET, [DECODER]" \&\fIClass method.\fR If just \s-1CHARSET\s0 is given, returns a decoder object which maps data into that character set (the character set is forced to all-uppercase). .Sp .Vb 1 \& $wd = supported MIME::WordDecoder "ISO\-8859\-1"; .Ve .Sp If \s-1DECODER\s0 is given, installs such an object: .Sp .Vb 2 \& MIME::WordDecoder\->supported("ISO\-8859\-1" => \& (new MIME::WordDecoder::ISO_8859 "1")); .Ve .Sp You should not override this method. .IP "new [\e@HANDLERS]" 4 .IX Item "new [@HANDLERS]" \&\fIClass method, constructor.\fR If \e@HANDLERS is given, then \f(CW@HANDLERS\fR is passed to \fIhandler()\fR to initialize the internal map. .IP "handler CHARSET=>\e&SUBREF, ..." 4 .IX Item "handler CHARSET=>&SUBREF, ..." \&\fIInstance method.\fR Set the handler \s-1SUBREF\s0 for a given \s-1CHARSET,\s0 for as many pairs as you care to supply. .Sp When performing the translation of a MIME-encoded string, a given \s-1SUBREF\s0 will be invoked when translating a block of text in character set \s-1CHARSET. \s0 The subroutine will be invoked with the following arguments: .Sp .Vb 5 \& DATA \- the data in the given character set. \& CHARSET \- the upcased character set name, which may prove useful \& if you are using the same SUBREF for multiple CHARSETs. \& DECODER \- the decoder itself, if it contains configuration information \& that your handler function needs. .Ve .Sp For example: .Sp .Vb 5 \& $wd = new MIME::WordDecoder; \& $wd\->handler(\*(AqUS\-ASCII\*(Aq => "KEEP"); \& $wd\->handler(\*(AqISO\-8859\-1\*(Aq => \e&handle_latin1, \& \*(AqISO\-8859\-2\*(Aq => \e&handle_latin1, \& \*(Aq*\*(Aq => "DIE"); .Ve .Sp Notice that, much as with \f(CW%SIG\fR, the \s-1SUBREF\s0 can also be taken from a set of special keywords: .Sp .Vb 4 \& KEEP Pass data through unchanged. \& IGNORE Ignore data in this character set, without warning. \& WARN Ignore data in this character set, with warning. \& DIE Fatal exception with "can\*(Aqt handle character set" message. .Ve .Sp The subroutine for the special \s-1CHARSET\s0 of 'raw' is used for raw (non-MIME-encoded) text, which is supposed to be US-ASCII. The handler for 'raw' defaults to whatever was specified for '\s-1US\-ASCII\s0' at the time of construction. .Sp The subroutine for the special \s-1CHARSET\s0 of '*' is used for any unrecognized character set. The default action for '*' is \s-1WARN.\s0 .IP "decode \s-1STRING\s0" 4 .IX Item "decode STRING" \&\fIInstance method.\fR Decode a \s-1STRING\s0 which might contain MIME-encoded components into a local representation (e.g., \s-1UTF\-8,\s0 etc.). .IP "unmime \s-1STRING\s0" 4 .IX Item "unmime STRING" \&\fIFunction, exported.\fR Decode the given \s-1STRING\s0 using the \fIdefault()\fR decoder. See \fIdefault()\fR. .Sp You should consider using the \s-1UTF\-8\s0 decoder instead. It decodes \&\s-1MIME\s0 strings into Perl's internal string format. .IP "mime_to_perl_string" 4 .IX Item "mime_to_perl_string" \&\fIFunction, exported.\fR Decode the given \s-1STRING\s0 into an internal Perl Unicode string. You should use this function in preference to all others. .Sp The result of mime_to_perl_string is likely to have Perl's \&\s-1UTF8\s0 flag set. .SH "SUBCLASSES" .IX Header "SUBCLASSES" .IP "MIME::WordDecoder::ISO_8859" 4 .IX Item "MIME::WordDecoder::ISO_8859" A simple decoder which keeps US-ASCII and the 7\-bit characters of \s-1ISO\-8859\s0 character sets and \s-1UTF8,\s0 and also keeps 8\-bit characters from the indicated character set. .Sp .Vb 2 \& ### Construct: \& $wd = new MIME::WordDecoder::ISO_8859 2; ### ISO\-8859\-2 \& \& ### What to translate unknown characters to (can also use empty): \& ### Default is "?". \& $wd\->unknown("?"); \& \& ### Collapse runs of unknown characters to a single unknown()? \& ### Default is false. \& $wd\->collapse(1); .Ve .Sp According to \fBhttp://czyborra.com/charsets/iso8859.html\fR (ca. November 2000): .Sp \&\s-1ISO 8859\s0 is a full series of 10 (and soon even more) standardized multilingual single-byte coded (8bit) graphic character sets for writing in alphabetic languages: .Sp .Vb 10 \& 1. Latin1 (West European) \& 2. Latin2 (East European) \& 3. Latin3 (South European) \& 4. Latin4 (North European) \& 5. Cyrillic \& 6. Arabic \& 7. Greek \& 8. Hebrew \& 9. Latin5 (Turkish) \& 10. Latin6 (Nordic) .Ve .Sp The \s-1ISO 8859\s0 charsets are not even remotely as complete as the truly great Unicode but they have been around and usable for quite a while (first registered Internet charsets for use with \s-1MIME\s0) and have already offered a major improvement over the plain 7bit US-ASCII. .Sp Characters 0 to 127 are always identical with US-ASCII and the positions 128 to 159 hold some less used control characters: the so-called C1 set from \s-1ISO 6429.\s0 .IP "MIME::WordDecoder::US_ASCII" 4 .IX Item "MIME::WordDecoder::US_ASCII" A subclass of the \s-1ISO\-8859\-1\s0 decoder which discards 8\-bit characters. You're probably better off using \s-1ISO\-8859\-1.\s0 .SH "SEE ALSO" .IX Header "SEE ALSO" MIME::Tools .SH "AUTHOR" .IX Header "AUTHOR" Eryq (\fIeryq@zeegee.com\fR), ZeeGee Software Inc (\fIhttp://www.zeegee.com\fR). David F. Skoll (dfs@roaringpenguin.com) http://www.roaringpenguin.com