I'm trying to parse some e-mail. I started with one and it came back MIME encoded. So I went poking around online for an hour or so and found a tutorial that set up a group of use statements and then continued on. I wanted to make certain the modules were installed, so I ran after typing in the using.

Then, as if by magic, the message was plain text. I thought it was something else I'd done, so I commented out those using statements. Still plain text. So I did the stupid thing and deleted them.

Now I've put two more messages in the box and they come back MIME encoded. Any clue what the magic using statements are? I've attached my code (such that it is) below.

#!/usr/bin/perl use Net::POP3; use strict; use warnings; use diagnostics; use DateTime; use XML::Writer; #DateTime and XML::Writer are not installed by default. #Notes: # If for some insane reason this becomes more than throwaway code and + isn't redone in C# # I want to break the component parts out to methods and move the reg +ex/value pairs to a config file. # I also need to do more with error handling than send a message to S +TDError. my $rundate = DateTime->today; # Prepare to write the XML. my $xmloutput = new XML::Writer( ); $xmloutput->xmlDecl('UTF-8'); $xmloutput->startTag( 'CaseList', 'transactiondate'=>$rundate); #The +root element my $pop = Net::POP3->new('pop.secureserver.net', Timeout => 60); $pop->login('alm@ivyreisner.com','xxxx') > 0 or die "Cannot log into e +-mail"; my $msgnums = $pop->list or die "Cannot fetch messages"; foreach my $msgnum (keys %$msgnums) { $xmloutput->startTag("Case"); my $payload; my $subject; my $rundate = DateTime->today; $xmloutput->dataElement("Subject", $subject); #Now that we have the messages in an array, we can parse the one a +t a time. my $msg = $pop->get($msgnum) or die "Cannot read message " + $msgn +um; foreach my $msgline (@$msg) { if ($msgline =~ /^Subject:/) { $subject = $msgline; $subject =~ s/^Subject: //; chomp($subject); #chomp = trim } elsif ($msgline =~ /Case Title:/) #Just finding the character +s that tell me I'm in the body for sure. { $payload = $msgline; if ($payload =~ m|(Index #: </b>)(.*)(<br><b>Case Title)|) { $xmloutput->dataElement("Index Number", $2); } if ($payload =~ m|(Case Title: </b>)(.*)(<br><b>Venue)|) { $xmloutput->dataElement("Case Title", $2); } if ($payload =~ m|(Venue: </b>)(.*)(<br><b>Court)|) { $xmloutput->dataElement("Venue", $2); } if ($payload =~ m|(Court: </b>)(.*)(<br><b>Date Filed)|) { $xmloutput->dataElement("Court", $2); } if ($payload =~ m|(Date Filed: </b>)(.*)(<br><b>Date enter +ed)|) { $xmloutput->dataElement("Date Filed", $2); } if ($payload =~ m|(Date entered: </b>)(.*)(<br><b>Document + Type)|) { $xmloutput->dataElement("Date Entered", $2); } if ($payload =~ m|(Document Type: </b>)(.*)(<br><b>Filing +Party)|) { $xmloutput->dataElement("Document Type", $2) } if ($payload =~ m|(Filing Party: </b>)(.*)(<br><b>Attorney +)|) { $xmloutput->dataElement("Filing Party", $2) } if ($payload =~ m|(Attorney: </b>)(.*)(<br><b>Order Outcom +e)|) { $xmloutput->dataElement("Attorney", $2) } if ($payload =~ m|(Order Outcome: </b>)(.*)(<br><b>Comment +s)|) { $xmloutput->dataElement("Order Outcome", $2) } if ($payload =~ m|(Comments: </b>)(.*)(<o:p>)|) { $xmloutput->dataElement("Comments", $2); } } } $xmloutput->endTag(); } $pop->quit; $xmloutput->endTag(); $xmloutput->end();

Thank you very much.


In reply to parsing mime encoded e-mails by IvyR

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.