NAME
MIME::Words - deal with RFC-1522 encoded words
SYNOPSIS
Before reading further, you should see MIME::Tools to make sure that you understand where this module fits into the grand scheme of things. Go on, do it now. I'll wait. Ready? Ok...use MIME::Words qw(:all);
### Decode the string into another string, forgetting the charsets:
$decoded = decodemimewords(
'To: =?ISO-8859-1?Q?KeldJ=F8rnSimonsen?=
);', ### Split string into array of decoded [DATA,CHARSET] pairs:
@decoded = decodemimewords('To: =?ISO-8859-1?Q?KeldJ=F8rnSimonsen?=
);', ### Encode a single unsafe word:
$encoded = encodemimeword("\xABFran\xE7ois\xBB");
### Encode a string, trying to find the unsafe words inside it:
$encoded = encodemimewords("Me and \xABFran\xE7ois\xBB in town");
DESCRIPTION
Fellow Americans, you probably won't know what the hell this module isfor. Europeans, Russians, et al, you probably do. ":-)".
For example, here's a valid MIME header you might get:From: =?US-ASCII?Q?KeithMoore?=
To: =?ISO-8859-1?Q?KeldJ=F8rnSimonsen?=
CC: =?ISO-8859-1?Q?Andr=E9?= Pirard
Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=
=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=
=?US-ASCII?Q?..cool!?=
The fields basically decode to (sorry, I can only approximate the Latin characters with 7 bit sequences /o and 'e): From: Keith MooreTo: Keld J/orn Simonsen CC: Andr'e Pirard Subject: If you can read this you understand the example... cool! PPUUBBLLIICC IINNTTEERRFFAACCEE decodemimewords ENCODED, [OPTS...] Function. Go through the string looking for RFC-1522-style "Q"
(quoted-printable, sort of) or "B" (base64) encoding, and decode
them. IInn aann aarrrraayy ccoonntteexxtt,, splits the ENCODED string into a list of decoded "[DATA, CHARSET]" pairs, and returns that list. Unencodeddata are returned in a 1-element array "[DATA]", giving an
effective CHARSET of "undef".$enc = '=?ISO-8859-1?Q?KeldJ=F8rnSimonsen?=
'; foreach (decodemimewords($enc)) {
print "", ($[1] || 'US-ASCII'), ": ", $[0], "\n";
} IInn aa ssccaallaarr ccoonntteexxtt,, joins the "data" elements of the above listtogether, and returns that. Warning: this is information-lossy,
and probably not what you want, but if you know that all charsets in the ENCODED string are identical, it might be useful to you. (Before you use this, please see "unmime" in MIME::WordDecoder, which is probably what you want.)In the event of a syntax error, $@ will be set to a description of
the error, but parsing will continue as best as possible (so as toget something back when decoding headers). $@ will be false if no
error was detected. Any arguments past the ENCODED string are taken to define a hash of options: Field Name of the mail field this string came from. Currently ignored. encodemimeword RAW, [ENCODING], [CHARSET] Function. Encode a single RAW "word" that has unsafe characters. The "word" will be encoded in its entirety.### Encode "<
>": $encoded = encodemimeword("\xABFran\xE7ois\xBB");
You may specify the ENCODING ("Q" or "B"), which defaults to "Q".You may specify the CHARSET, which defaults to "iso-8859-1".
encodemimewords RAW, [OPTS] Function. Given a RAW string, try to find and encode all "unsafe" sequences of characters:### Encode a string with some unsafe "words":
$encoded = encodemimewords("Me and \xABFran\xE7ois\xBB");
Returns the encoded string. Any arguments past the RAW string are taken to define a hash of options: Charset Encode all unsafe stuff with this charset. Default is'ISO-8859-1', a.k.a. "Latin-1".
Encoding The encoding to use, "q" or "b". The default is "q". Field Name of the mail field this string will be used in. Currently ignored.WWaarrnniinngg:: this is a quick-and-dirty solution, intended for character
sets which overlap ASCII. IItt ddooeess nnoott ccoommppllyy wwiitthh tthhee RRFFCC-11552222
rruulleess rreeggaarrddiinngg tthhee uussee ooff eennccooddeedd wwoorrddss iinn mmeessssaaggee hheeaaddeerrss. You may want to roll your own variant, using "encodedmimeword()", for your application. Thanks to Jan Kasprzak for reminding me about this problem. NNOOTTEESS Exports its principle functions by default, in keeping with MIME::Base64 and MIME::QuotedPrint. AUTHOR Eryq (eryq@zeegee.com), ZeeGee Software Inc (http://www.zeegee.com). David F. Skoll (dfs@roaringpenguin.com) http://www.roaringpenguin.com All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Thanks also to... Kent Boortz For providing the idea, and the baselineRFC-1522-decoding code!
KJJ at PrimeNet For requesting that this be split into its own module. Stephane Barizien For reporting a nasty bug. VVEERRSSIIOONN$Revision: 1.14 $ $Date: 2006/03/17 21:03:23 $
perl v5.8.8 2006-03-17 MIME::Words(3)