PHP Classes

sort out messages

Recommend this page to a friend!

      POP3 e-mail client  >  All threads  >  sort out messages  >  (Un) Subscribe thread alerts  
Subject:sort out messages
Summary:how to sort it out
Messages:62
Author:vlad
Date:2008-12-11 04:38:15
Update:2009-03-20 04:16:29
 
  1 - 10   11 - 20   21 - 30   31 - 40   41 - 50   51 - 60   61 - 62  

  51. Re: sort out messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-02-13 04:21:41 - In reply to message 50 from vlad
You should not use the SkipBody option if you want to get the main message parts. Anyway, that is not the problem.

It is hard to tell what is the problem without a real example of message in a real mailbox, as the problem can be in the size of the message or in the networking speed access, so we never know without benchmarking.

Can you provide a test account in the POP3 server you are using and leave a message that with the usual size you are trying, and the actual script you are using so I can benchmark it?

  52. Re: sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2009-02-16 00:31:17 - In reply to message 51 from Manuel Lemos
hello Manuel

the test account is:
test@axo.cc
pass: Pink

the actual script is below:
(the mail box now has 2 emails:
one with very little attachment, another with big one 6mb, it takes around 4-5 minute for script below to process)
i test it here:
worldwideprojectinfo.com/test/MimeP ...


<?php

require('mime_parser.php');
require('rfc822_addresses.php');
require("pop3.php");

/* Uncomment when using SASL authentication mechanisms */
/*
require("sasl.php");
*/

stream_wrapper_register('pop3', 'pop3_stream'); /* Register the pop3 stream handler class */

$pop3=new pop3_class;
$pop3->hostname="email.axo.cc"; /* POP 3 server host name */
$pop3->port=110; /* POP 3 server host port,
usually 110 but some servers use other ports
Gmail uses 995 */
$pop3->tls=0; /* Establish secure connections using TLS */
$user="test@axo.cc"; /* Authentication user name */
$password="Pink"; /* Authentication password */
//$pop3->realm=""; /* Authentication realm or domain */
//$pop3->workstation=""; /* Workstation for NTLM authentication */
$apop=0; /* Use APOP authentication */
//$pop3->authentication_mechanism="USER"; /* SASL authentication mechanism */
$pop3->debug=0; /* Output debug information */
$pop3->html_debug=0; /* Debug information is in HTML */
$pop3->join_continuation_header_lines=1; /* Concatenate headers split in multiple lines */

if(($error=$pop3->Open())=="")
{
echo "<PRE>Connected to the POP3 server &quot;".$pop3->hostname."&quot;.</PRE>\n";
if(($error=$pop3->Login($user,$password,$apop))=="")
{
echo "<PRE>User &quot;$user&quot; logged in.</PRE>\n";
if(($error=$pop3->Statistics($messages,$size))=="")
{
echo "<PRE>There are $messages messages in the mail box with a total of $size bytes.</PRE>\n";
if($messages>0)
{

##### MY START LOOP FROM HERE (loop $messages)
##### MY START LOOP FROM HERE (loop $messages)
##### MY START LOOP FROM HERE (loop $messages)
##### MY START LOOP FROM HERE (loop $messages)
##### MY START LOOP FROM HERE (loop $messages)
##### MY START LOOP FROM HERE (loop $messages)
##### *************************************
for($i=1; $i <= $messages; $i++)
{



$pop3->GetConnectionName($connection_name);
$message=$i;
$message_file='pop3://'.$connection_name.'/'.$message;
$mime=new mime_parser_class;

/*
* Set to 0 for not decoding the message bodies
*/
$mime->decode_bodies = 1;

$parameters=array(
'File'=>$message_file,

/* Read a message from a string instead of a file */
//'Data'=>'My message data string',

/* Save the message body parts to a directory */
'SaveBody'=>'tmp',

/* Do not retrieve or save message body parts */
// 'SkipBody'=> 1,
);

$success=$mime->Decode($parameters, $decoded); //// this stroke is important !!!! wihtout it nothing works






/*
echo '<pre>';
print_r($decoded); ##### this array displays all headers i can extract headers i need from here
echo '</pre>';
*/

echo 'Date::: '.$decoded[0]['Headers']['date:'].'<br>'; #### email date
echo 'Subject::: '.$decoded[0]['Headers']['subject:'].'<br>'; #### email subject
$emailFrom = $decoded[0]['ExtractedAddresses']['from:'][0][address];
echo 'Email-From::: '.$emailFrom.'<br>'; #### my from what email addres it is coming
///// loop for attachments detecting
///// loop for attachments detecting
///// loop for attachments detecting
///// loop for attachments detecting
for($t=0; $t<=10; $t++)
{
if ($decoded[0]['Parts'][$t]['FileName'])
{
echo '<strong>Attachment Info:::</strong> '.$decoded[0]['Parts'][$t]['FileName'].'<br>'; #### atatchment info
}
}




#### one of these below will display body message
####
echo '<br><br><span style="color:red">HTML::</span><br>'.file_get_contents($decoded[0]['Parts'][0]['BodyFile']);
echo '<br><span style="color:red">Plain-2::</span><br>'.file_get_contents($decoded[0]['Parts'][0]['Parts'][0]['BodyFile']);
echo '<br><span style="color:blue">PLAIN::</span><br>'.file_get_contents($decoded[0]['BodyFile']);



echo '<hr size="1" color="#000000">';








}////end for MY LOOP
////end for MY LOOP
////end for MY LOOP
////end for MY LOOP
////end for MY LOOP
////end for MY LOOP
////end for MY LOOP
////end for MY LOOP








if(!$success)
echo '<h2>MIME message decoding error: '.HtmlSpecialChars($mime->error)."</h2>\n";
else
{

//echo '<h2>MIME message decoding successful</h2>'."\n";
//echo '<h2>Message structure</h2>'."\n";
//echo '<pre>';
//var_dump($decoded[0]);
//echo '</pre>';
if($mime->Analyze($decoded[0], $results))
{
//echo '<h2>Message analysis</h2>'."\n";
//echo '<pre>';
//var_dump($results);
//echo '</pre>';
}
else
echo 'MIME message analyse error: '.$mime->error."\n";
}
}
if($error==""
&& ($error=$pop3->Close())=="")
echo "<PRE>Disconnected from the POP3 server &quot;".$pop3->hostname."&quot;.</PRE>\n";




}
}
}
if($error!="")
echo "<H2>Error: ",HtmlSpecialChars($error),"</H2>";
?>

  53. Re: sort out messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-02-16 02:13:37 - In reply to message 52 from vlad
I tried this script and it took about 5 minutes to download and process the message.

I also tried downloading the message to files and then run the same script making it read the messages from the files and it just took 5 seconds.

Conclusion, the overhead is in downloading the message from the server that is in a distant network.

  54. Re: sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2009-02-16 02:28:47 - In reply to message 53 from Manuel Lemos
"Conclusion, the overhead is in downloading the message from the server that is in a distant network."

so what does it mean? can i change it somehow?

  55. Re: sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2009-02-16 03:24:50 - In reply to message 54 from vlad
i tried to run the script from the other server and it is still very slow

  56. Re: sort out messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-02-16 03:38:51 - In reply to message 54 from vlad
It means that the problem is not in PHP, but rather in the the speed that server provides you the message data.

Of 300 seconds pulling the message data, only 5 were taken processing iy by the MIME parser class.

If you use a regular mail program you can see it takes about the same time to serve the message. There seems to be nothing that can be done on the PHP side to minimize the download time.

  57. Re: sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2009-02-16 04:01:14 - In reply to message 56 from Manuel Lemos
i use just shared hosting so probably it cannot provide enough speed?
websitesource.com/

what kind of hosting or server do you use?

i was thinking to switch from shared to virtual server it should give me more speed what do you think?

  58. Re: sort out messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-02-16 04:11:00 - In reply to message 57 from vlad
The problem is not on the PHP hosting server, but rather on the server that has the POP3 mailbox as it is in a distant network and the sending messages over the network is slow.

If you have the POP3 mailbox in the same server or network on which PHP is running, it will be much faster.

  59. Re: sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2009-02-16 04:20:25 - In reply to message 58 from Manuel Lemos
ah! i understand now! of course!
my the hosting for php is in america but the mail server is located in NZ....

this is why the speed is so slow...

so you are saying if i relocate either php to NZ or emails to america it will work faster!

ok! that is very interesting!
thanks

  60. Re: sort out messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-02-16 04:40:08 - In reply to message 59 from vlad
Yes, you can configure your mail server to forward your messages to a closer POP3 server.

 
  1 - 10   11 - 20   21 - 30   31 - 40   41 - 50   51 - 60   61 - 62