james nahon - 2013-02-20 13:37:39 -
In reply to message 6 from Manuel Lemos
Hey,
I have pasted the whole code that i am using below. The problem is two fold:
1) only the first three messages are processed correctly, after which i get the error below. No matter what the messages are or how many there are, the first three only work.
"MIME message decoding error: could not open the message file to decode pop3://0/4"
"MIME message decoding error: could not open the message file to decode pop3://0/5"
2) when calling $error=$pop3->Close() i get the following error which means the messages are not removed:
Error: Could not get quit command response
Here is the code:
==============================================================
if(($error=$pop3->Open())=="")
{
//echo "<PRE>Connected to the POP3 server "".$pop3->hostname."".</PRE>\n";
if(($error=$pop3->Login($user,$password,$apop))=="")
{
//echo "<PRE>User "$user" 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)
{
$pop3->GetConnectionName($connection_name);
for ($i=1;$i<=$messages;$i++){
print $i;
$message_file='pop3://'.$connection_name.'/'.$i;
$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'=>0,
);
$success=$mime->Decode($parameters, $decoded);
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);
$pos = strpos($results['Subject'],"UID:ID");
$id = substr($results['Subject'],$pos+6);
//print "Client ID : <pre>$id</pre>";
$body = mysql_real_escape_string($results['Data']);
$query = "INSERT INTO alerts (client,subject,message,status) VALUES ('$id','$results[Subject]','$body','1')";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
//DeleteMessage($i);
$pop3->DeleteMessage('$i');
//print "Body is: <pre>$results[Data]</pre>";
print "complete <br />";
//echo '</pre>';
}
else
echo 'MIME message analyse error: '.$mime->error."\n";
}
}
}
if($error==""
&& ($error=$pop3->Close())=="")
echo "<PRE>Disconnected from the POP3 server "".$pop3->hostname."".</PRE>\n";
}
}
}
if($error!="")
echo "<H2>Error: ",HtmlSpecialChars($error),"</H2>";
?>