#!/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 regex/value pairs to a config file. # I also need to do more with error handling than send a message to STDError. 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 at a time. my $msg = $pop->get($msgnum) or die "Cannot read message " + $msgnum; foreach my $msgline (@$msg) { if ($msgline =~ /^Subject:/) { $subject = $msgline; $subject =~ s/^Subject: //; chomp($subject); #chomp = trim } elsif ($msgline =~ /Case Title:/) #Just finding the characters that tell me I'm in the body for sure. { $payload = $msgline; if ($payload =~ m|(Index #: )(.*)(
Case Title)|) { $xmloutput->dataElement("Index Number", $2); } if ($payload =~ m|(Case Title: )(.*)(
Venue)|) { $xmloutput->dataElement("Case Title", $2); } if ($payload =~ m|(Venue: )(.*)(
Court)|) { $xmloutput->dataElement("Venue", $2); } if ($payload =~ m|(Court: )(.*)(
Date Filed)|) { $xmloutput->dataElement("Court", $2); } if ($payload =~ m|(Date Filed: )(.*)(
Date entered)|) { $xmloutput->dataElement("Date Filed", $2); } if ($payload =~ m|(Date entered: )(.*)(
Document Type)|) { $xmloutput->dataElement("Date Entered", $2); } if ($payload =~ m|(Document Type: )(.*)(
Filing Party)|) { $xmloutput->dataElement("Document Type", $2) } if ($payload =~ m|(Filing Party: )(.*)(
Attorney)|) { $xmloutput->dataElement("Filing Party", $2) } if ($payload =~ m|(Attorney: )(.*)(
Order Outcome)|) { $xmloutput->dataElement("Attorney", $2) } if ($payload =~ m|(Order Outcome: )(.*)(
Comments)|) { $xmloutput->dataElement("Order Outcome", $2) } if ($payload =~ m|(Comments: )(.*)()|) { $xmloutput->dataElement("Comments", $2); } } } $xmloutput->endTag(); } $pop->quit; $xmloutput->endTag(); $xmloutput->end();