MIME::WordDecoder 5.420 review
DownloadMIME::WordDecoder is a Perl module to decode RFC-1522 encoded words to a local representation. SYNOPSIS See MIME::Words for the
|
|
MIME::WordDecoder is a Perl module to decode RFC-1522 encoded words to a local representation.
SYNOPSIS
See MIME::Words for the basics of encoded words. See "DESCRIPTION" for how this class works.
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('To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= ');
### Decode a string using the default decoder, non-OO style:
$str = unmime('To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= ');
A MIME::WordDecoder consists, fundamentally, of a hash which maps a character set name (US-ASCII, ISO-8859-1, 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 MIME strings directly to Big5, that's your own decision.
The subroutine will be invoked with two arguments: DATA (the data in the given character set), and CHARSET (the upcased character set name).
For example:
### Keep 7-bit characters as-is, convert 8-bit characters to '#':
sub keep7bit {
local $_ = shift;
tr/x00-x7F/#/c;
$_;
}
Here's a decoder which uses that:
### Construct a decoder:
$wd = MIME::WordDecoder->new({'US-ASCII' => "KEEP", ### sub { $_[0] }
'ISO-8859-1' => &keep7bit,
'ISO-8859-2' => &keep7bit,
'Big5' => "WARN",
'*' => "DIE"});
### Convert some MIME text to a pure ASCII string...
$ascii = $wd->decode('To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= < keld >');
### ...which will now hold: "To: Keld J#rn Simonsen < keld >"
Requirements:
Perl
MIME::WordDecoder 5.420 search tags