PHP Classes

problem when storing message into file

Recommend this page to a friend!

      POP3 e-mail client  >  All threads  >  problem when storing message into file  >  (Un) Subscribe thread alerts  
Subject:problem when storing message into file
Summary:Not able to store the received messages in local directories.
Messages:7
Author:VmanAsh
Date:2006-08-09 07:01:03
Update:2008-01-21 00:38:52
 

  1. problem when storing message into file   Reply   Report abuse  
Picture of VmanAsh VmanAsh - 2006-08-09 07:01:03
Hi,

Iam using mime parser and pop3 classes for getting the messsages from pop3 server and then trying to store the messages into my local directory in eml format. For storing in local directories I have added some 5 lines in outputdebug function in pop3 class.

Iam using PHPEdit IDE as the debugger.
Iam able to store the recieved messages in the specified directory if iam in debugger mode.
Till here it is good and fine.

But problem is coming if Iam running the php scripts from the browser.(http://localhost/test_pop3.php) Iam not able to store the messages in the specified path. But the files are getting created with 0 file size.(No data is present in that files)

Thanks in advance,
Regards
Ashok.V

  2. Re: problem when storing message into file   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-08-09 19:04:11 - In reply to message 1 from VmanAsh
You should not be modifying the class for that. You just need to retrieve the message data with the class public functions and store it in the local files you want.

  3. Re: problem when storing message into file   Reply   Report abuse  
Picture of mike mike - 2007-05-02 13:43:23 - In reply to message 1 from VmanAsh
Hello;

I am looking to do something similar as you. Could you send me you files?

Thanks

kesz
kesz1@yahoo.com

  4. Re: problem when storing message into file   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-05-02 16:20:36 - In reply to message 3 from mike
All you need to do is to use the OpenMessage function to sepcify the message you want to read and GetMessage function to retrieve the data of the message as it is stored in the server which is commonly referred as the .eml format.

  5. Re: problem when storing message into file   Reply   Report abuse  
Picture of Namida Namida - 2007-12-10 04:55:51 - In reply to message 4 from Manuel Lemos
First things first, kuddos to Mr. Lemos for this SUPERB class ;)

Now on to bussiness...

Here's a little code that might get you going, first copy/paste the example code at tet_pop3.php and after it gets the Statistics (line #46) replace the ENTIRE if (up to line #89) with this...


$id = 1 // id of the message to read

if(($error=$pop3->OpenMessage($id,-1))=="")
{
$eml_file = time() . "_" . uniqid() . ".eml"; //output file name
$file_handler = fopen($eml_file, 'wb') or die("can't open file");
while(!$eof)
{
if(($error=$pop3->GetMessage(100000,$data,$eof))=="");
else $eof = true;
fwrite($file_handler,$data);
}
fclose($file_handler);
}

this way you read the message and output it into a file ($eml_file).
I almost forgot, notice that

else $eof = true;

the thing is, if you get an error while reading the message, you'll have a broken file, so that else will break the while statement (I'm not sure, but, most likely, GetMessage returns $eof=true upon error, I should try that...), so now the only thing left is to unlink the broken file, so in the

if($error!="") at the end of the example you should add...

if(isset($eml_file)) unlink($eml_file);

and that's it ;)
it worked for me, hope anyone finds it useful!

  6. Re: problem when storing message into file   Reply   Report abuse  
Picture of Anton Rifco Anton Rifco - 2008-01-20 08:52:04 - In reply to message 5 from Namida
great...

very helpful for me and all.

I will correct a little

name of file is test_pop3.php , not tet_pop3.php :p

and, there should be a semicolon (;) after this code :

$id = 1 // id of the message to read



  7. Re: problem when storing message into file   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-01-21 00:38:52 - In reply to message 5 from Namida
Since the latest release, there is a simpler way to copy messages to files. After you call the Login() function you can do this:
$pop3->GetConnectionName($connection_name);
$message=1; $message_file='pop3://'.$connection_name.'/'.$message;
copy($message_file, $message.'.eml');

The error handling was omitted to simplify the example:

First make sure you register the pop3:// stream wrapper in the beginning of your script after you include the POP3 class like this:

stream_wrapper_register('pop3', 'pop3_stream');