PHP Classes

email piping -> mysql

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  email piping -> mysql  >  (Un) Subscribe thread alerts  
Subject:email piping -> mysql
Summary:Do you have an example of parsing an email to mysql db?
Messages:6
Author:Paul Godard
Date:2012-01-30 19:23:50
Update:2012-02-01 04:46:42
 

  1. email piping -> mysql   Reply   Report abuse  
Picture of Paul Godard Paul Godard - 2012-01-30 19:23:50
I want to move away from IMAP and use email piping to store email into a temporary mysql table.
My idea is to store every received email in a temp table 'EmailRaw' and at the same time brake the email into pieces (plain, html, multipart embedded images) and store it properly into different fields, even tables (attachments) and files on the server.
What is the best approach for doing this?
Does your mime parse can handle all kind of format (character sets, embedded images, encoded/encrypted messages, attachments…)?
Can you help me with some examples and some advice?
Thank you, Paul.

  2. Re: email piping -> mysql   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-01-31 01:31:06 - In reply to message 1 from Paul Godard
Yes, it should handle all formats. Feel free to show me any kind of message you may encounter difficulties to parse.

  3. Re: email piping -> mysql   Reply   Report abuse  
Picture of Paul Godard Paul Godard - 2012-01-31 08:16:09 - In reply to message 2 from Manuel Lemos
Thank you for your quick reply Manuel and also for sharing this class!

My php programming skills are definitely as strong as yours, so I would appreciate a bit more help to start using your class.

Every email sent to my script via email piping will be in a variable ($MyRawMessage = raw email including header).

I guess I will have to insert the following code…

require_once('rfc822_addresses.php');
require_once('mime_parser.php');
$mime=new mime_parser_class;
$mime->mbox = 0;
$mime->decode_bodies = 1;
$mime->ignore_syntax_errors = 1;
$mime->track_lines = 1;
$mime->use_part_file_names = 0;
$parameters=array('Data'=>$MyRawMessage);

So what do I do next? Where are the different parts?
from address & name
to address & name
subject
other headers parts
plain text body
multipart html body with embedded images
attachments

Sorry, but I need some help here.

  4. Re: email piping -> mysql   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-01-31 09:20:16 - In reply to message 3 from Paul Godard
Just look at the example scripts. They use the Decode and Analyze functions which extract the message data in a way that is easier for you to get what you want.

  5. Re: email piping -> mysql   Reply   Report abuse  
Picture of Paul Godard Paul Godard - 2012-01-31 15:14:15 - In reply to message 4 from Manuel Lemos
I have done that but I am a bit lost.
I used your sample (test_message_decoder.php) to read a raw email stored in a mysql table after being piped to my first php script.
I get the following results in the test section at the bottom.
How do I get the different parts into different variables so I can store them into another mysql table?
Please explain to me? At least with one example… thank you!
-----------
$mime->mbox = 0;
$mime->decode_bodies = 1;
$mime->ignore_syntax_errors = 1;
$mime->track_lines = 1;
$mime->use_part_file_names = 0;

$parameters = array('Data'=>$EmailRaw,'SkipBody'=>1);

MIME message decoding successful.
1 message was found.
Message 1:

array(5) {
["Headers"]=> array(0) { }
["Parts"]=> array(0) { }
["Position"]=> int(0)
["BodyPart"]=> int(1)
["BodyLength"]=> int(2452)
}

array(3) {
["Type"]=> string(4) "text"
["Description"]=> string(12) "Text message"
["DataLength"]=> int(2452)
}

  6. Re: email piping -> mysql   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-02-01 04:46:42 - In reply to message 5 from Paul Godard
You cannot pass the SkipBody parameter to the Decode function if you want it to parse the message bodies.

Take a look at the documentation file for more details about what you can do.