Solved

POP3 email, parse message body

Posted on 2004-08-08
5
304 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 125 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

733 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