Solved

POP3 email, parse message body

Posted on 2004-08-08
5
281 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now