#!/usr/bin/perl -w # # ParseNoticeXML.pl: # # U-sequoyah\crazy (crazy) Fri Sep 19 12:00:40 2003 # # Id: $Id$ # # To do: # 1. Add OpenPGP support to verify email message authenticity # 2. Check message subject line for a standard trigger like "Copyright Notice" # 3. Flesh out database support that allows an XML insert # 4. Error handling use vars qw($opt_h); use Getopt::Std; use Xml::XPath; use Net::POP3; # this is if you plan to push the xml into your database # Perl DBI is probably the right thing to us: # http://search.cpan.org/modlist/Database_Interfaces for ideas #use Win32::ODBC; #$DB = new Win32::ODBC("dsn=PiracyDB;UID=sa;PWD=yourpwd"); # # usage: display usage message # sub usage() { print<new($host, Timeout => 60); # try and get messages from the POP server if ($pop->login($username, $password) > 0) { $msgnums = $pop->list; # hashref of msgnum => size # Loop through all of the messages foreach $msgnum (keys %$msgnums) { $msgRef = $pop->get($msgnum); #print scalar(@$msgRef)."\n"; $xmlString =""; $inXml = 0; # foreach line of the email message foreach(@$msgRef){ # $_ - the default variable becomes the line of the message #print; if(m/<\?xml.*?>/){ $inXml = 1; } if(m##){ $xmlString .= $_;; $inXml = 0; } if ($inXml){ $xmlString .= $_;; } } # ***** now you have the XML data in the var xmlString ***** $xp = XML::XPath->new( xml => $xmlString); print "Here is the Copyright Holder:\n"; print $xp->findvalue("/Infringement/Complainant/Entity") . "\n"; print "Here is the ID:\n"; print $xp->findvalue("/Infringement/Case/ID") . "\n"; print "Here is the Title:\n"; print $xp->findvalue("/Infringement/Content/Item/Title") . "\n"; # write xml to file #open (xmlFile, ">xmlout.txt") || die "Can't open xmlout.txt: $!"; $outFile = $xp->findvalue("/Infringement/Complainant/Entity")."-".$xp->findvalue("/Infringement/Case/ID").".xml"; open (xmlFile, ">$outFile") || die "Can't open xmlout.txt: $!"; print xmlFile "$xmlString"; # insert xml to database - this should give you the framework for doing an insert # there's probably some slick way to push xml directly into a MSSQL database #$sql = "INSERT $sqlTable VALUES ($data)"; #$DB->Sql($sql); #print "Processing: ".Win32::ODBC::Error().$i."\n"; # delete the message now that we're done with it #$pop->delete($msgnum); } } # close pop connection $pop->quit;