.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .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. | will give a .\" real vertical bar. \*(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-|\(bv\*(Tr .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" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" 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 3" .TH MIME::WordDecoder 3 "2007-09-27" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" MIME::WordDecoder \- decode RFC 2047 encoded words to a local representation .SH "SYNOPSIS" .IX Header "SYNOPSIS" See MIME::Words for the basics of encoded words. See \*(L"\s-1DESCRIPTION\s0\*(R" for how this class works. .PP .Vb 1 \& use MIME::WordDecoder; .Ve .PP .Vb 2 \& ### Get the default word-decoder (used by unmime()): \& $wd = default MIME::WordDecoder; .Ve .PP .Vb 2 \& ### Get a word-decoder which maps to ISO-8859-1 (Latin1): \& $wd = supported MIME::WordDecoder "ISO-8859-1"; .Ve .PP .Vb 2 \& ### Decode a MIME string (e.g., into Latin1) via the default decoder: \& $str = $wd->decode('To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= '); .Ve .PP .Vb 2 \& ### Decode a string using the default decoder, non-OO style: \& $str = unmime('To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= '); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" A MIME::WordDecoder consists, fundamentally, of a hash which maps a character set name (\s-1US\-ASCII\s0, \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 '#': \& 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({'US-ASCII' => "KEEP", ### sub { $_[0] } \& 'ISO-8859-1' => \e&keep7bit, \& 'ISO-8859-2' => \e&keep7bit, \& 'Big5' => "WARN", \& '*' => "DIE"}); .Ve .PP .Vb 2 \& ### Convert some MIME text to a pure ASCII string... \& $ascii = $wd->decode('To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= '); .Ve .PP .Vb 1 \& ### ...which will now hold: "To: Keld J#rn Simonsen " .Ve .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 initiallize 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('US-ASCII' => "KEEP"); \& $wd->handler('ISO-8859-1' => \e&handle_latin1, \& 'ISO-8859-2' => \e&handle_latin1, \& '*' => "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't 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 \s-1US\-ASCII\s0. 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. .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 .Ve .Sp .Vb 3 \& ### What to translate unknown characters to (can also use empty): \& ### Default is "?". \& $wd->unknown("?"); .Ve .Sp .Vb 3 \& ### 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\s0 8859 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\s0 8859 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 \s-1US\-ASCII\s0. .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\s0 6429. .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 "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