PHP Classes

working with parser's output

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  working with parser's output  >  (Un) Subscribe thread alerts  
Subject:working with parser's output
Summary:I'm having problems figuring out how to get to the decoded data
Messages:41
Author:Lee Willmann
Date:2006-12-20 03:52:59
Update:2009-02-26 06:08:12
 
  1 - 10   11 - 20   21 - 30   31 - 40   41 - 41  

  11. Re: working with parser's output   Reply   Report abuse  
Picture of Lee Willmann Lee Willmann - 2007-01-05 00:46:17 - In reply to message 10 from Dominique
I am writing functions to extract either the text or HTML part of the message, and to pull the attachments from the decoded message object as well.

  12. Re: working with parser's output   Reply   Report abuse  
Picture of Dominique Dominique - 2007-01-22 13:02:59 - In reply to message 11 from Lee Willmann
Lee Willmann,
Can you share with me your code ?

I have code very badly (my skill level in PHP is not very good :)).

Thanks

regards.

my mail : [email protected]

  13. Re: working with parser's output   Reply   Report abuse  
Picture of Angelo Zanetti Angelo Zanetti - 2007-02-19 12:04:48 - In reply to message 12 from Dominique
Hi guys,

im doing something similiar. Im using the pop3 class to open up a pop account and get a list of all the messages that are to be processed. I loop through the messages and for each message I want to use the mime class to decode it. Now in the mime class you can parse a message 2 ways (1. as a file, like the example with the class bundle or 2. as a string ) now for the 2 option (string parse) you need to get use the following functions to get that string (this is in the loop of messages)... OpenMessage and GetMessage functions then parse the String to the MIME parse class to process the message. In my case I want to extract the attachment from the email.

Now my problem is the part where I have to get the string from those 2 functions I have the following.


. . . //connect to pop class, get list of emails, and loop through them.

for($message=0;$message<count($result);$message++) {

now here is where I have to call those 2 functions but Im not sure how to do that correctly to get the string, I tried something like this:

$pop3->OpenMessage($message+1, -1);
$str = $pop3->GetMessage(51024, $message+1);


but i get this error message from the GetMessage function call...

Fatal error: Cannot pass parameter 2 by reference in /srv/www/htdocs/pop3class/test_pop3.php on line 77

can anyone help me with this error and how am I meant to define the argument and secondly am I calling these classes correctly?

Thanks in advance
Angelo

  14. Re: working with parser's output   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-02-19 18:35:05 - In reply to message 13 from Angelo Zanetti
The second parameter of GetMessage function is not the message number. It is just a variable passed by reference that will be changed by the GetMessage function to store the contents of the message that is being retrieved.

You also need to pass a third parameter, $end_of_message, that is a boolean variable also passed by reference. The GetMessage function sets that variable to 1 or 0 depending on whether it has already read the whole message or not.

The GetMessage function does not necessarily read the whole message at once. It reads chunks of limited size. You need to call that function in a loop until the $end_of_message parameter is set to 1 , meaning it reached the end of message and there is no more data to retrieve for that message.

  15. Re: working with parser's output   Reply   Report abuse  
Picture of Angelo Zanetti Angelo Zanetti - 2007-02-20 15:31:01 - In reply to message 14 from Manuel Lemos
Hi Manuel.

thanks for the reply. I have changed my code to the following:

$pop3->OpenMessage($message+1, -1);
$pop3->GetMessage(51024, $msg, $end_of_message);

echo "Message: " . $msg;


and it seems to be working, the output of the msg is echo'd successfully.

In your opinion if I want to receive emails with attachments (zip file) should I parse the message as a string or as a file to the mime parser for processing. It seems that emails with an attachment the GetMessage gets the contents of the files (attachments) and inserts that text into the $msg variable.

Angelo

  16. Re: working with parser's output   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-02-20 19:12:52 - In reply to message 15 from Angelo Zanetti
It depends on the memory limits set in the PHP configuration and how you read the message.

If you load a message all at once on string, it may exceed the PHP memory limits set in php.ini. Usually the limit is 8MB, so you may not be able to decode messages from strings with 4MB or even with less.

If you read messages from files, it just reads the necessary data in chunks, so it does not need much memory.

You could read the message and store it in a temporary file, but that could waste too much disk space and may not work in safe mode if you do not have the right directory permissions.

You can also use the POP3 class stream wrapper to emulate reading messages from a POP3 mailbox as if it were files, but that way it opens the POP3 connection, reads one message in chunks, and closes the connection.

That is not good if you want to reuse a POP3 connection to process and delete several messages. Soon I will enhance the POP3 stream wrapper to reuse an already opened connection.

  17. Re: working with parser's output   Reply   Report abuse  
Picture of Angelo Zanetti Angelo Zanetti - 2007-02-21 09:52:01 - In reply to message 16 from Manuel Lemos
So Say for instance I want to read one message a day, use the mime parser to get and extract the attachments it will work?

Im just confused as to how to get the messages, as the 2 functions I need to perform are:

1->connect to the mailbox, get the msg.

2->extract the attachment of the msg and delete the message. (Done using mime_parser class

So the confusion is basically what I should be ussing to get the messages from the mailbox. I can do this already using the POP3 class but just connecting the mail message received to the mime_parser is my concern.

The ways of parsing the message I understand: either a string or as a file. The attachment is a zip file about 1.2 MB in size so should I rather be using the file method of parsing? Also the example in the parse_message is a little unclear.

Thanks for your help again, its very much appreciated.

  18. Re: working with parser's output   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-02-27 21:48:29 - In reply to message 17 from Angelo Zanetti
If you load the whole message at once into a string and then pass it to the MIME parser class, it will work if the message size does not exceed the PHP memory limits.

For large messages it is better to use POP3 stream wrapper and pass the pop3:// URL to the MIME parser class as it will read and parse the message in small chunks instead of loading the whole message into the memory.

  19. Re: working with parser's output   Reply   Report abuse  
Picture of Angelo Zanetti Angelo Zanetti - 2007-03-06 12:21:20 - In reply to message 18 from Manuel Lemos
Hi Manuel.

Thanks again. I am understanding more about it, I think that I must use the POP3 way.

Now you declare the POP3 as follows:

$message_file='pop3://'.$user.':'.$password.'@localhost/'.$message.
'?debug='.$debug.'&html_debug='.$html_debug.'&realm='.$realm.'&workstation='.$workstation.
'&apop='.$apop.'&authentication_mechanism='.$authentication_mechanism;


Now I understand most of the variables in the string...

However the @localhost is that meant to be the URL of the domain? eg @mydomain.com/

And the $message is that the messageID for that message? In your example you hardcode $message=1;

Now when I connect to the mail account and loop through the messages eg:

for($message=0;$message<count($result);$message++)

can I use the above $message for the variable above? but it would have to ($message+1) as the loop is starting from 0?



  20. Re: working with parser's output   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-03-06 16:37:43 - In reply to message 19 from Angelo Zanetti
Yes, localhost should be replaced by your POP3 host domain.

$message is the number of the message in the mailbox. 1 is the first message.

 
  1 - 10   11 - 20   21 - 30   31 - 40   41 - 41