Hello Monks, I am parsing emails with my script just fine. However I need to output some of the headers to an xml document. I will give you the example XML and my pop script below. I need to write the to, from, cc, and subject fields into the xmlk format you see below. what is the best way to do this and can you give an example Thanks
- <Index> - <Fields> - <Field> <Name>From</Name> <Value>"Sam man" <sam.man@sam.com></Value> </Field> - <Field> <Name>To</Name> <Value><network@etp.us.blackberry.net></Value> </Field> - <Field> <Name>Date</Name> <Value>01/02/2005</Value> </Field> - <Field> <Name>Subject</Name> <Value>RIM_bca28a80-e9c0-11d1-87fe-00600811c6a2</Value> </Field> - <Field> <Name>CC</Name> <Value /> </Fields> </Index>

Here is the script

#CaptureMail Script use Net::POP3; use Mail::Header; # Configure Sever Login Info here # $postoffice='pop.mail.yahoo.com'; # fill in this with something like p +ostoffice.isp.com $user=''; # fill this in with your mail user name $password=''; # fill this in with your mail server password $verbose=1; # Call scan_header with the Mail::Header object. If it returns a value +, then # that value is the reason the mail should be Captured. # If it returns undef, the mail is not Captured; # # NOTE: Edit the Email addresses below to specify who's mail to Captur +e' sub scan_header { my $head, @rec, $r, @tags, $t, $msgsize; ($head, $msgsize) = @_; @tags = $head->tags(); $DefinedUser = 0; foreach $t (@tags) { if ($t=~/^X-Advertisement/i) { return "Found X-Advertisement header"; } if ($DefinedUser == 0) { if (($t=~/From/i) || ($t=~/To/i) || ($t=~/Cc/i)) { @rec = $head->get($t); foreach $r (@rec) { if ($r=~/extra\@ediets\.com/i) { return "Found User in $t header"; } if ($r=~/savetrees\.com/i) { return "Found User in $t header"; } if ($r=~/earthlinking\.net/i) { return "Found User in $t header"; } if ($r=~/\@shoppingplanet\.com/i) { return "Found User in $t header"; $DefinedUser = 1; } } } } } if ($DefinedUser == 1) { return "Processing First Header Pass"; } return undef; } # Call Get_First_Header_Pass with postoffice, user, password to be sca +nned. # sub Get_First_Header_Pass { my $postoffice, $user, $password, $pop, $msgcount, $i, $head, $reas +on, $subj, $from, $CaptureCount; ($postoffice, $user, $password) = @_; $pop = Net::POP3->new($postoffice) ; if (! defined($pop)) { die "Net::POP3::new failed for postoffice $postoffice\n"; } $msgcount = $pop->login($user, $password); if (! defined($msgcount)) { die "Cannot login to mailbox at $postoffice\n"; } ($msgcount, $msgsize) = $pop->popstat(); $CaptureCount = 0; for ($i = 1; $i <= $msgcount; ++$i) { $msgsize = $pop->list($i); $head = new Mail::Header $pop->top($i, 0); if ($reason = &scan_header($head, $msgsize)) { if ($verbose) { $subj = $head->get('Subject'); $from = $head->get('From'); if (! defined($subj)) { $subj = "<no subject>\n"; } if (! defined($from)) { $from = "<no from address>\n"; } print "Capturing mail:\n"; print " From: $from"; print " Subject: $subj"; print " Reason: $reason\n"; } #$pop->delete($i); ++$CaptureCount; } } $pop->quit(); if ($verbose && ($msgcount > 0)) { print "Looked at $msgcount message(s), Captured $CaptureCount\n" +; } } # Actually do everything. # &Get_First_Header_Pass($postoffice, $user, $password);

In reply to parse email output to a formatted XML document by johnajb

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.