Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
A co-worker of mine has 600,000+ .EML files which contain some UTF-8 encoded text. Here's a sample:
To: =?utf-8?B?Q2FuY2VsbGF0aW9uIDxDYW5jZWxsYXRpb25Abm9ydmVyZ2VuY2UuY29t +Pg==?= CC: =?utf-8?B?VGltIEhpbGtlIChSVlApIDx0aW0uaGlsa2VAbm9ydmVyZ2VuY2UuY29t +PiwgQmVybmFyZCBDb3lsZSBNVlAgb2 YgREMgPGJlcm5hcmQuY295bGVAbm9ydmVyZ2VuY2UuY29tPiwgRGF2aWQgQnV0bGVyIChB +VlApIDxkYXZpZC5idXRsZXJAbm9ydm VyZ2VuY2UuY29tPiwgVGltb3RoeSBDYXNleSA8dGltb3RoeS5jYXNleUBub3J2ZXJnZW5j +ZS5jb20+?= Microsoft Mail Internet Headers Version 2.0 Received: from SERVER.REMOVED ([IP.RE.MO.VED]) by SERVER.REMOVED with Microsoft SMTPSVC(5.0.2195.6713); Thu, 24 Jun 2004 13:47:45 -0400 X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1 content-class: urn:content-classes:message MIME-Version: 1.0 Subject: SOME EMAIL SUBJECT Date: Thu, 24 Jun 2004 13:47:44 -0400 Message-ID: <F237EF3B2E3F5E47BAA4F33B79DB0AB502764A95@SERVER.REMOVED> X-MS-Has-Attach: X-MS-TNEF-Correlator: <F237EF3B2E3F5E47BAA4F33B79DB0AB502764A95@SERVER +.REMOVED> Thread-Topic: SOME THREAD TOPIC Thread-Index: AcRaE1qu8p4j/zoYQ4WJdDsPJbcodg== From: "NAME REMOVED" <NAME.REMOVED@EMAIL.REMOVED Return-Path: NAME.REMOVED@EMAIL.REMOVED
He'd like to decode the To: and Cc: lines. What tools are necessary to do this?
Update: Upon examining MIME::Parser, I've tracked down the necessary code in MIME::Words. My solution is:
#!/usr/bin/perl use MIME::Words 'decode_mimewords'; use strict; use warnings; my @files = @ARGV; for my $file (@files) { local @ARGV = ($file); local $^I = ".bak"; local $/; print scalar decode_mimewords($_) while <>; }

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

In reply to Decoding UTF-8 charset in an .EML file by japhy

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 examining the Monastery: (9)
As of 2024-04-19 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found