PHP Classes

Decoded array problem

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Decoded array problem  >  (Un) Subscribe thread alerts  
Subject:Decoded array problem
Summary:Having problem with extrating email address from decoded array
Messages:23
Author:Jack J. Utano
Date:2009-02-27 21:42:39
Update:2009-03-06 18:44:31
 
  1 - 10   11 - 20   21 - 23  

  1. Decoded array problem   Reply   Report abuse  
Picture of Jack J. Utano Jack J. Utano - 2009-02-27 21:42:39
First off, I love this script. Nice Work Mr. Manuel!

I am having a problem with the following code in my slightly modified version of browse_mailbox.php:

echo '<h2>MIME message decoding successful</h2>'."\n";
echo '<h2>Message structure</h2>'."\n";
echo '<pre>';
print_r($decoded[0]);
echo '</pre>';
$address=$decoded['Headers']['envelope-to:'];
print "email address = $address<br />";


This is part of the output when I run my script:

Message structure
Array
(
[Headers] => Array
(
[return-path:] =>
[envelope-to:] => [email protected]

.
.
.

enail address =

Message analysis

.
.
.

The variable $address is blank. What is wrong with this line of code?????
$address=$decoded['Headers']['envelope-to:'];


Thanks so much!

Jack

  2. Re: Decoded array problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-02-27 21:53:53 - In reply to message 1 from Jack J. Utano
Are you sure it is blank?

Sometimes you dump the results to a Web page and everything between < and > is interpreted by the browser as an unknown tag, so nothing is displayed, but it is there is the page source.

  3. Re: Decoded array problem   Reply   Report abuse  
Picture of Jack J. Utano Jack J. Utano - 2009-02-27 22:10:15 - In reply to message 2 from Manuel Lemos
Yes I am sure it is not there. I viewed the sources of the web page and here is the reult line below:

</pre>enail address = <br /><h2>Message analysis</h2>



  4. Re: Decoded array problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-02-28 00:27:57 - In reply to message 3 from Jack J. Utano
I would need to process the same message you are seeing to advise.

I also need to know if you made any changes to the classes.

  5. Re: Decoded array problem   Reply   Report abuse  
Picture of Jack J. Utano Jack J. Utano - 2009-02-28 00:50:40 - In reply to message 4 from Manuel Lemos
I have made no changes to teh core classes except for browse_mailbox.php.


Below is the code for browse_mailbox.php:

<?php
/*
* browse_mailbox.php
*
* @(#) $Header: /home/mlemos/cvsroot/pop3/browse_mailbox.php,v 1.1 2008/01/09 07:36:25 mlemos Exp $
*
*/

?><html>
<head>
<title>Parsing a POP3 email message</title>
</head>
<body>
<center><h1>Parsing a POP3 email message</h1></center>
<hr />
<?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="mail.alhloghomes.com"; /* 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="[email protected]"; /* Authentication user name */
$password="gizmo1251!"; /* 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=1; /* 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)
{
$i=1;
while ( $i <= $messages ) {
$pop3->GetConnectionName($connection_name);
$message=1;
$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'=>1,
'extract_addresses'=>1,
);
var_dump($parameters);
$success=$mime->Decode($parameters, $decoded);
// $addresses=ParseAddressList($addresses,$addresses);
var_dump($addresses);
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>';
print_r($decoded[0]);
echo '</pre>';
$address=$decoded['Headers']['envelope-to:'];
print "enail address = $address<br />";
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";

}
$i++;
}
}
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>";
?>

</body>
</html>

  6. Re: Decoded array problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-02-28 06:00:27 - In reply to message 5 from Jack J. Utano
You are trying to retrieve the e-mail address of the envelope-to: header but the class does not parse it unless you add it to the address_headers variable like this:

$mime->address_headers['envelope-to:'] = 1;

  7. Re: Decoded array problem   Reply   Report abuse  
Picture of Jack J. Utano Jack J. Utano - 2009-02-28 15:12:27 - In reply to message 6 from Manuel Lemos
Thanks for your patience. I Added your line of code beloe:


$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,
'extract_addresses'=>1,
);
$success=$mime->Decode($parameters, $decoded);
if(!$success)
echo '<h2>MIME message decoding error: '.HtmlSpecialChars($mime->error)."</h2>\n";
else
{
$mime->address_headers['envelope-to:']=1;
echo '<h2>MIME message decoding successful</h2>'."\n";
echo '<h2>Message structure</h2>'."\n";
echo '<pre>';
print_r($decoded[0]);
print_r($address_headers);
echo '</pre>';
$address=$decoded['Headers']['envelope-to:'];
print "enail address = $address<br />";

and it did not work. What is the name of the array that contains the envelope-to: email address?

  8. Re: Decoded array problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-02-28 17:49:29 - In reply to message 7 from Jack J. Utano
That is because you are adding the after you already called the Decode function.

  9. Re: Decoded array problem   Reply   Report abuse  
Picture of Jack J. Utano Jack J. Utano - 2009-03-01 23:35:24 - In reply to message 8 from Manuel Lemos
Ok:

I switched the line before the decode

$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,
'extract_addresses'=>1,
);
$mime->address_headers['envelope-to:']=1;
$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>';
print_r($decoded[0]);
print_r($address_headers);
echo '</pre>';


and I still am not sure of the name of the array that contains the extracted email addresses.

Again, thanks for your patience!

  10. Re: Decoded array problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-03-02 01:11:52 - In reply to message 9 from Jack J. Utano
When in doubt, check the documentation. It is ExtractedAddresses .

 
  1 - 10   11 - 20   21 - 23