PoorLuzer has asked for the wisdom of the Perl Monks concerning the following question:
What I want to understand are: 1. how to map strings like these:
=?iso-8859-1?Q?Communiqu=E9?= =?iso-8859-1?Q?Telef=F3nica?= =?ISO-8859-1?Q?Montre=E1l?= =?iso-8859-1?Q?Minist=E8re?=
to these:
Communique Telefonica Montreal Ministere
I get the same, unhelpful (does not help me get the desired mappings above), results regardless of whether I use:
or I use:use MIME::Words qw(:all); my $rawSub = $head->get( 'subject' ); my $mailSubject = decode_mimewords( $rawSub );
use MIME::WordDecoder; my $wd = supported MIME::WordDecoder "US-ASCII"; ### Decode a MIME string (e.g., into Latin1) via the default decod +er: my $str = $wd->decode( $rawSub ); print $str, "\n";
For some reason that I am unable to understand, the following fails completely (the output shows me the unknown character designator '_' for any character!):
use MIME::WordDecoder; my $wd = new MIME::WordDecoder::US_ASCII; $wd->unknown( '_' ); # What to translate unknown characters to $wd->collapse( 1 ); # Collapse runs of unknown characters to a sin +gle unknown print $wd->decode( $rawSub ), "\n";
Here is some code:
use Date::Manip; Date_Init( "ConvTZ=IGNORE", "TZ=GMT" ); # We don't want time conve +rsions happening. GMailBackup ignores timezone conformance and keeps +timestamps as they were # If using Date::Transform, you can use '%g' that is short for %a, + %d %b %Y %H:%M:%S %z - Fri, 28 Apr 1995 17:23:15 EDT; For eg : Sat, +9 Feb 2008 17:04:08 -0330 $mailDate = UnixDate( $mailDate , '%Y_%m_%Q-%H%M%S' ); # 2008_02_2 +0080209-170408
For this example, consider the date string:
Sat, 9 Feb 2008 17:04:08 -0380
The timezone in the string is clearly bogus (minutes value > 60); yet this happens in "real life".
As evident from the code, I don't need the timezone information anyways. So how do I "lop it off" (is it recommended?) reliably?
I would rather have someone tell me a magic flag that I am unaware of that makes the UnixDate ignore the timezone as "chopping it off" promises to complicate life even more (time zones can be in different formats. Eg : EET, -330, +710, etc)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Transcoding MIME Strings
by zwon (Abbot) on Oct 09, 2009 at 18:24 UTC | |
by PoorLuzer (Beadle) on Oct 09, 2009 at 23:11 UTC | |
by almut (Canon) on Oct 10, 2009 at 00:29 UTC | |
by PoorLuzer (Beadle) on Oct 10, 2009 at 02:11 UTC | |
|
Re: Transcoding MIME Strings
by PoorLuzer (Beadle) on Oct 10, 2009 at 02:12 UTC |