Solved

decode mime email message

Posted on 2013-01-12
10
671 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 110

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 110

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

627 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