Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have been handling some email related process recently, mainly with processing information from the raw mail headers.

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:

use MIME::Words qw(:all); my $rawSub = $head->get( 'subject' ); my $mailSubject = decode_mimewords( $rawSub );
or I use:

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";

2. How do I make Date::Manip::UnixDate completely ignore the timezone part of the date string?

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)


In reply to Transcoding MIME Strings by PoorLuzer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-18 00:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found