PHP Classes

Parsing messages within messages

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Parsing messages within messages  >  (Un) Subscribe thread alerts  
Subject:Parsing messages within messages
Summary:Parsing messages within messages
Messages:8
Author:asdfghjkl
Date:2007-07-26 09:10:10
Update:2007-08-16 21:54:59
 

  1. Parsing messages within messages   Reply   Report abuse  
Picture of asdfghjkl asdfghjkl - 2007-07-26 09:10:11
I want to be able to parse e-mail messages that are attachments to a single e-mail messages.

I have selected multiple e-mails in Outlook Express and forwarded them to an e-mail address so they all exist as 1 e-mail message. When I use your parser on the e-mail it puts all of the bodies of all the messages into 1 array value.

Is your class capable of parsing these individually?

Regards,

  2. Re: Parsing messages within messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-26 11:24:38 - In reply to message 1 from asdfghjkl
The class parses any kind of message with as many attachments as you want and of any type.

It returns a nested array structure that describes all the message parts. You just need to traverse that array to locate each message part.

Attached messages usually have the content-type of message/rfc822 .

  3. Re: Parsing messages within messages   Reply   Report abuse  
Picture of asdfghjkl asdfghjkl - 2007-07-26 12:24:11 - In reply to message 2 from Manuel Lemos
OK that's good to hear.

I'm trying to integrate your class into my POP fetch script at the moment. I have collected the body of my e-mail and saved it to an variable and now I want your class to read from that integer.

In my previous post I had used imap_savebody and then manually set your script to read from that file.

I am getting 'NULL' returned from the integer $decoded now though.

This is a small piece of my code which I am using:

for ($i = 1; $i <= $numMessages; $i++) {

$attachNum = 0;
$struct = imap_fetchstructure($mailbox, $i);
$body = imap_body($mailbox, $i);

$mime=new mime_parser_class;
$mime->mbox = 1;
$mime->decode_bodies = 0;
$mime->ignore_syntax_errors = 1;
$parameters=array(
'Data'=>$body
);
var_dump($decoded[$message]);


There is more code below that but it's code which wouldn't affect your class.

The $body variable does contain an e-mail message if I print_r it.

Regards,

  4. Re: Parsing messages within messages   Reply   Report abuse  
Picture of asdfghjkl asdfghjkl - 2007-07-26 12:34:48 - In reply to message 3 from asdfghjkl
Sorry, the above was my fault as is now fixed. The class still isn't breaking down the messages that are within the 1 message.

Can I e-mail you the array structure of what I'm seeing?

Regards,

  5. Re: Parsing messages within messages   Reply   Report abuse  
Picture of asdfghjkl asdfghjkl - 2007-07-30 08:32:58 - In reply to message 4 from asdfghjkl
Hello again.

I've tried all options within your class to try and break down the individual messages into separate parts but it's unsuccessful.

I'm thinking the following options should be doing this, which are:

$mime->mbox = 1;
$mime->decode_bodies = 1;
$parameters=array('SaveBody'=>'./tmp')

But for the 2 messages within my 1 message it puts ALL of the messages bodies into $decoded[0]['Body']

There is no $decoded[1]['Body'] or $decoded[2]['Body'] which is what I was expecting for each of the attached messages.


  6. Re: Parsing messages within messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-30 23:34:25 - In reply to message 5 from asdfghjkl
Can you paste the var_dump output of the $decoded array?

  7. Re: Parsing messages within messages   Reply   Report abuse  
Picture of asdfghjkl asdfghjkl - 2007-07-31 08:11:32 - In reply to message 6 from Manuel Lemos
I have replied to your e-mail with the array structure as it's very long and would spam this message board and it also contains some information I would not like to be public. I will be checking here for replies though as I'd like other people to see a solution.

  8. Re: Parsing messages within messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-08-16 21:54:59 - In reply to message 7 from asdfghjkl
It seems that imap_fetchbody does not include the message headers. In that case you need to also use the imap_fetchheader function and concatenate the message headers and body before passing it to the MIME parser class.