Parsing a message with Manuel Lemos' PHP POP3 and MIME Parser classes
hostname="localhost"; /* 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="username"; /* Authentication user name */
$password="password"; /* 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=1; /* Output debug information */
$pop3->html_debug=1; /* Debug information is in HTML */
$pop3->join_continuation_header_lines=1; /* Concatenate headers split in multiple lines */
if(($error=$pop3->Open())=="")
{
echo "Connected to the POP3 server "".$pop3->hostname."".
\n";
if(($error=$pop3->Login($user,$password,$apop))=="")
{
echo "User "$user" logged in.
\n";
if(($error=$pop3->Statistics($messages,$size))=="")
{
echo "There are $messages messages in the mail box with a total of $size bytes.
\n";
if($messages>0)
{
$pop3->GetConnectionName($connection_name);
$message=1;
$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);
if(!$success)
echo 'MIME message decoding error: '.HtmlSpecialChars($mime->error)."
\n";
else
{
echo 'MIME message decoding successful
'."\n";
echo 'Message structure
'."\n";
echo '';
var_dump($decoded[0]);
echo '
';
if($mime->Analyze($decoded[0], $results))
{
echo 'Message analysis
'."\n";
echo '';
var_dump($results);
echo '
';
}
else
echo 'MIME message analyse error: '.$mime->error."\n";
}
}
if($error==""
&& ($error=$pop3->Close())=="")
echo "Disconnected from the POP3 server "".$pop3->hostname."".
\n";
}
}
}
if($error!="")
echo "Error: ",HtmlSpecialChars($error),"
";
?>