Location: PHPKode > scripts > Mime Decode > mime-decode/example.php
<?php
    /**
    * o------------------------------------------------------------------------------o
    * | This package is licensed under the Phpguru license. A quick summary is       |
    * | that for commercial use, there is a small one-time licensing fee to pay. For |
    * | registered charities and educational institutes there is a reduced license   |
    * | fee available. You can read more  at:                                        |
    * |                                                                              |
    * |                  http://www.phpguru.org/static/license.html                  |
    * o------------------------------------------------------------------------------o
    *
    * © Copyright 2008,2009 Richard Heyes
    */

/***************************************
** Filename.......: example.php
** Project........: Mime Decoder
** Last Modified..: 08 October 2001
***************************************/

/***************************************
** This script shows how to use the mime
** decoding class. All it does is take
** the input, decode it, and show it on
** screen.
***************************************/

	include('./mimeDecode.php');

	$filename = './example.email.txt';
	$message  = fread(fopen($filename, 'r'), filesize($filename));

	header('Content-Type: text/plain');
	header('Content-Disposition: inline; filename="stuff.txt"');

	$params = array(
					'input'          => $message,
					'crlf'           => "\r\n",
					'include_bodies' => TRUE,
					'decode_headers' => TRUE,
					'decode_bodies'  => TRUE
					);

	$output = Mail_mimeDecode::decode($params);


/***************************************
** Below is a basic function to parse
** the output of the class. It will 
** produce:
** $parts['text'] - Indexed array of plain text parts
***************************************/

	$parts = array();

	function parse_output(&$obj, &$parts){

		if(!empty($obj->parts)){
			for($i=0; $i<count($obj->parts); $i++)
				parse_output($obj->parts[$i], $parts);

		}else{
			$ctype = $obj->ctype_primary.'/'.$obj->ctype_secondary;
			switch($ctype){
				case 'text/plain':
					if(!empty($obj->disposition) AND $obj->disposition == 'attachment'){
						$parts['attachments'][] = $obj->body;
					}else{
						$parts['text'][] = $obj->body;
					}
					break;

				case 'text/html':
					if(!empty($obj->disposition) AND $obj->disposition == 'attachment'){
						$parts['attachments'][] = $obj->body;
					}else{
						$parts['html'][] = $obj->body;
					}
					break;

				default:
					$parts['attachments'][] = $obj->body;
			}
		}
	}

	header('Content-Type: text/plain');
	parse_output($output, $parts);
	print_r($parts);
//	print_r($output);
?>
Return current item: Mime Decode