Hi Monks,
I'm a newbie to Perl. I seek the wisdom from you for the following problem:

I want to parse the incoming emails. These emails have three attachments. First I assumed that the email attachments are in the format of text/html
but later found that the attachments are in ".mhtml" format.
I wrote a script which parses the email, gets the attachment names and writes the content-type into a /tmp file

#!/usr/local/bin/perl -w use MIME::Parser; use File::Basename; use strict; # derive the base filenames of extracted parts from # the name of the script. my ($parsed) = (basename($0))[0]; #Create a Parser object my $parser = MIME::Parser->new(); # output directory for parsed files $parser->output_dir("/tmp"); # Basenames for parsed files $parser->output_prefix($parsed); $parser->output_to_core(); open(INPUT, "/tmp/email-test/AuthenticationReport.msg") or die("Input +error: $!"); my $entity = $parser->read(\*INPUT) or die "couldn't parse MIME stream"; close(INPUT); # Tell us about the MIME entities! this is for debugging $entity->dump_skeleton;
Running the above script results in a /tmp file with the following results:

------=_Part_64_24417480.1094663686411 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: BASE64 ------=_Part_64_24417480.1094663686411 Content-Type: application/octet-stream; name=User_Logins_UnitDaily_Test_User_09_08_2004_10_14_45_DAY20 +04-9-8_18.mhtml Content-Transfer-Encoding: BASE64 Content-Disposition: attachment; filename=User_Logins_UnitDaily_Test_User_09_08_2004_10_14_45_D +AY2004-9-8_18.mhtml ------=_Part_64_24417480.1094663686411 Content-Type: application/octet-stream; name=Admin_Logins_UnitDaily_Test_User_09_08_2004_10_14_45_DAY2 +004-9-8_18.mhtml Content-Transfer-Encoding: BASE64 Content-Disposition: attachment; filename=Admin_Logins_UnitDaily_Test_User_09_08_2004_10_14_45_ +DAY2004-9-8_18.mhtml ------=_Part_64_24417480.1094663686411 Content-Type: application/octet-stream; name=Disabled_Logins_UnitDaily_Test_User_09_08_2004_10_14_45_D +AY2004-9-8_18.mhtml Content-Transfer-Encoding: BASE64 Content-Disposition: attachment; filename=Disabled_Logins_UnitDaily_Test_User_09_08_2004_10_14_ +45_DAY2004-9-8_18.mhtml ------=_Part_64_24417480.1094663686411--
Moving on, I want to parse the three attachments and the data within them and insert the data into the database (Oracle).
The data within the email attachment comes in a fixed format which will like something like below
The following is a sample for the attachment "Disabled_Logins_UnitDaily...."
Cisco Reports ------------- Scheduled report for Cisco at IP address 18.187.12.10(Test1 - 0002321) ------------------------------------------------------------------- Disabled Logins for 2004-10-02 Time Address 10.10.58 18.188.10.12 10.12.34 17.199.13.100
IF there is not activity then the attachment displays "No Data" instead of "Time" and "Address".
The fields that I essentially need to extract are the IP address in the title, Date, Time and Address
Can anyone let me know how do I parse a ".mhtml" attachment and extract the required data.

Thanks well in advance.

In reply to Parsing mhtml attachment reports by chanakya

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.