?
Solved

POP3 email, parse message body

Posted on 2004-08-08
5
Medium Priority
?
311 Views
Last Modified: 2012-05-05
I need to analyse a messagebody in this form:

<Start of Bodytext>
SpamContent       123
LocalDeliver     456
RemoteDeliver    789

---
text following, not important
<End of Bodytext>

I need the first 3 lines to put into an array, based on the name, it's possible this gets more than three lines with other data.
After that i wan't to put this data along with the date of the email into a mySQL database (sits on the same linux box), how can I do this..?
Final result would be a webpage (PHP) with an overview of this data, but is no problemo.

So:
Each line into an array, based on line description, data ends with spaced line and next '---' line
Extra array zone with date of the email
Put this in a mySQL database (add record with this data), based on the date of the email (so if date already exists iverwrite record otherwise create new record.

Thanks
0
Comment
Question by:driesmans
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:ren_b
ID: 11748834
> I need the first 3 lines to put into an array, based on the name, it's possible this gets more than three lines with other data.

is it possible that the 3 lines will be out of a set order? also, what is your sql query for putting it into mysql?
0
 

Author Comment

by:driesmans
ID: 11770190
Those data lines will always be in the same order, because the mail is automatically generated.

The SQL query will be an insert or update query . Didn't start on that one yet.
0
 
LVL 6

Accepted Solution

by:
ren_b earned 500 total points
ID: 11774761
ok, well this should be enough to get you going...

#!/usr/bin/perl
$readdata = 0;
while(<>){
  chomp;
  $readdata = 0 if $_ eq '';
  $data[++$#data] = (split(/\s+/,$_,2))[1] if $readdata;
  $readdata = 1 if $_ eq "<Start of Bodytext>";
  $date = $1 if $_ =~ /^date: (.*?)$/i;
}
$" = ", ";
$sqlquery = "insert into some_table values ( \"$date\", @data )";
print "$sqlquery\n";

if they'll always be in the same order, then they'll be read into the @data array as they come, and print them into the sql query. this should give you some ideas.
0
 

Author Comment

by:driesmans
ID: 11966060
Thanks Ren_b, with a few adjustments it did the job...

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question