tags:

views:

182

answers:

2

Hello,

I have a third party program which basically allows users to send email and then it displays it in the system. But the problem is that it is generating an output like this: I want to just take this data and format it to something presentable. I would like to avoid REGEX. Are there any options or standard ways of displaying the content below in a more presentable fashion. Basically I will associate everything below as $text and then call a function clean($text) of sorts.

> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--B_3331365494_4098727
Content-type: text/plain;
charset="US-ASCII"
Content-transfer-encoding: 7bit

test

--B_3331365494_4098727
Content-type: text/html;
charset="US-ASCII"
Content-transfer-encoding: quoted-printable

<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>test</SPAN></FONT>
</BODY>
</HTML>


--B_3331365494_4098727--
+3  A: 

PEAR::Mail_mimeDecode is a great class to decode MIME messages. Once installed, you can use it as such:

$message = new Mail_mimeDecode($text);

$params['include_bodies'] = true;
$params['decode_bodies']  = true;
$params['decode_headers'] = true;

$messageStruct = $message->decode($params);
//messageStruct is now an array representing the message
// with all the parts properly included.
Andrew Moore
any direct php file which I can include instead of installing this?
Alec Smart
Download both `Mail_Mime` and `Mail_mimeDecode` using Download > Manual Installation. Extract both, correct the includes, and you should be good to go!
Andrew Moore
A: 

you can use this class

download :

http://code.google.com/p/php-mime-mail-parser/wiki/RequirementsAndInstallation

http://code.google.com/p/php-mime-mail-parser/

Haim Evgi
**@haim evgi:** That class requires a 3rd party compiled extension to be installed (`MailParse` to be precise).
Andrew Moore