Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 681
  • Last Modified:

decode mime email message

http://www.phpclasses.org/package/3169-PHP-Decode-MIME-e-mail-messages.html


want 3 variables

how to echo
email address that sent message
body
subject
0
rgb192
Asked:
rgb192
  • 6
  • 3
1 Solution
 
edster9999Commented:
Read the help forum of that package.
For example :
http://www.phpclasses.org/discuss/package/3169/thread/138/
0
 
rgb192Author Commented:
do I comment this line
'SkipBody'=>0,


and how do I call my message file
0
 
Ray PaseurCommented:
Please post the code exactly as you have it installed on your server.  The link is not usable for me.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
rgb192Author Commented:
for this question, I am not using Ray's email pipe code (which is another question)

this link is for a library, there is nothing on my server yet
http://www.phpclasses.org/package/3169-PHP-Decode-MIME-e-mail-messages.html
0
 
Ray PaseurCommented:
Let me please try this simple request again:

Please post the code exactly as you have it installed on your server.

0
 
rgb192Author Commented:
these files are on
test/sample/

q-encoding.eml
noendbreak.eml
mixedlinebreaks.eml
missingheaderseparator.eml
message.eml
mbox.eml
longheader.eml

<?php
/*
 * test_message_decoder.php
 *
 * @(#) $Header: /opt2/ena/metal/mimeparser/test_message_decoder.php,v 1.13 2012/04/11 09:28:19 mlemos Exp $
 *
 */

  require_once('rfc822_addresses.php');
  require_once('mime_parser.php');

  
  $message_file=((IsSet($_SERVER['argv']) && count($_SERVER['argv'])>1) ? $_SERVER['argv'][1] : 'test/sample/'.$_GET[file].'.eml');
  $mime=new mime_parser_class;
  
  /*
   * Set to 0 for parsing a single message file
   * Set to 1 for parsing multiple messages in a single file in the mbox format
   */
  $mime->mbox = 0;
  
  /*
   * Set to 0 for not decoding the message bodies
   */
  $mime->decode_bodies = 1;

  /*
   * Set to 0 to make syntax errors make the decoding fail
   */
  $mime->ignore_syntax_errors = 1;

  /*
   * Set to 0 to avoid keeping track of the lines of the message data
   */
  $mime->track_lines = 1;

  /*
   * Set to 1 to make message parts be saved with original file names
   * when the SaveBody parameter is used.
   */
  $mime->use_part_file_names = 0;

  /*
   * Set this variable with entries that define MIME types not yet
   * recognized by the Analyze class function.
   */
  $mime->custom_mime_types = array(
    'application/vnd.openxmlformats-officedocument.wordprocessingml.document'=>array(
      'Type' => 'ms-word',
      'Description' => 'Word processing document in Microsoft Office OpenXML format'
    )
  );

  $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,*/
  );

/*
 * The following lines are for testing purposes.
 * Remove these lines when adapting this example to real applications.
 */
  if(defined('__TEST'))
  {
    if(IsSet($__test_options['parameters']))
      $parameters=$__test_options['parameters'];
    if(IsSet($__test_options['mbox']))
      $mime->mbox=$__test_options['mbox'];
    if(IsSet($__test_options['decode_bodies']))
      $mime->decode_bodies=$__test_options['decode_bodies'];
    if(IsSet($__test_options['use_part_file_names']))
      $mime->use_part_file_names=$__test_options['use_part_file_names'];
  }

  if(!$mime->Decode($parameters, $decoded))
  {
    echo 'MIME message decoding error: '.$mime->error.' at position '.$mime->error_position;
    if($mime->track_lines
    && $mime->GetPositionLine($mime->error_position, $line, $column))
      echo ' line '.$line.' column '.$column;
    echo "\n";
  }
  else
  {
    echo 'MIME message decoding successful.'."\n";
    echo (count($decoded)==1 ? '1 message was found.' : count($decoded).' messages were found.'),"\n";
    for($message = 0; $message < count($decoded); $message++)
    {
      echo 'Message ',($message+1),':',"\n";
      var_dump($decoded[$message]);
      if($mime->decode_bodies)
      {
        if($mime->Analyze($decoded[$message], $results))
          var_dump($results);
        else
          echo 'MIME message analyse error: '.$mime->error."\n";
      }
    }
    for($warning = 0, Reset($mime->warnings); $warning < count($mime->warnings); Next($mime->warnings), $warning++)
    {
      $w = Key($mime->warnings);
      echo 'Warning: ', $mime->warnings[$w], ' at position ', $w;
      if($mime->track_lines
      && $mime->GetPositionLine($w, $line, $column))
        echo ' line '.$line.' column '.$column;
      echo "\n";
    }
  }
?>

Open in new window


http://hrblock.host22.com/mimeparser/test_message_decoder-rgb192.php?file=message

the only lines I changed are
line 13:
  $message_file=((IsSet($_SERVER['argv']) && count($_SERVER['argv'])>1) ? $_SERVER['argv'][1] : 'test/sample/'.$_GET[file].'.eml');
and
line 64:
    /*'SkipBody'=>1,*/
0
 
Ray PaseurCommented:
Maybe Mr. Lemos can help with this one - it looks like he wrote the code.  All we have here at EE is a code fragment.  We are missing any test data, and we do not have the contents of these files:

  require_once('rfc822_addresses.php');
  require_once('mime_parser.php');

That missing information makes it impossible to proceed.

Please make a visit to http://sscce.org and read up on the best ways to ask a technical question.  I promise it will make your engagement with Experts Exchange much richer and more fruitful.

Best regards, ~Ray
0
 
rgb192Author Commented:
>>
http://sscce.org 

I will try to self contain all the information in the question (and questions in the future)


 >>
We are missing any test data, and we do not have the contents of these files:


or the test eml files are on

http://hrblock.host22.com/mimeparser/test/sample/



I ran a similar script parsing gmail eml on localhost
and I can see the print_r more clearly even though I do not have a pre statement


I am looking to save the subject,body,email address of sender from print_r to a variable

so I can insert in mysql later
0
 
rgb192Author Commented:
I copy paste folder on hostgator and output looks same disorganized

but
I copy paste the folder and run on wamp localhost
and output looks cleaner (even though no changes were made)
I copy paste the folder and run on wamp localhost


want to save $variables (subject,body,email address of sender)
 instead of doing print_r
0
 
rgb192Author Commented:
thank you

Maybe Mr. Lemos can help with this one - it looks like he wrote the code
was the answer that worked
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now