Solved

decode mime email message

Posted on 2013-01-12
10
661 Views
Last Modified: 2013-01-17
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
Comment
Question by:rgb192
  • 6
  • 3
10 Comments
 
LVL 20

Expert Comment

by:edster9999
ID: 38770110
Read the help forum of that package.
For example :
http://www.phpclasses.org/discuss/package/3169/thread/138/
0
 

Author Comment

by:rgb192
ID: 38770195
do I comment this line
'SkipBody'=>0,


and how do I call my message file
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 38770611
Please post the code exactly as you have it installed on your server.  The link is not usable for me.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:rgb192
ID: 38770869
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
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 38770951
Let me please try this simple request again:

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

0
 

Author Comment

by:rgb192
ID: 38771101
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
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 38772202
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
 

Author Comment

by:rgb192
ID: 38772564
>>
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
 

Author Comment

by:rgb192
ID: 38773285
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
 

Author Closing Comment

by:rgb192
ID: 38790217
thank you

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

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question