Solved

POP3 email, parse message body

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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