Moloth Posted September 25, 2007 Share Posted September 25, 2007 Hi, I want to decode multipart messages using the mailparse extension.http://au.php.net/mailparse And so far have got this working: <?php /* * This is a simple email viewer. * make sure that $filename points to a file containing an email message and * load this page in your browser. * You will be able to choose a part to view. * */ $filename = "emails/m5.eml"; /* parse the message and return a mime message resource */ $mime = mailparse_msg_parse_file($filename); /* return an array of message parts - this contsists of the names of the parts * only */ $struct = mailparse_msg_get_structure($mime); echo "<table>\n"; /* print a choice of sections */ foreach($struct as $st) { echo "<tr>\n"; echo "<td><a href=\"mail.php?showpart=$st\">$st</a></td>\n"; /* get a handle on the message resource for a subsection */ $section = mailparse_msg_get_part($mime, $st); /* get content-type, encoding and header information for that section */ $info = mailparse_msg_get_part_data($section); echo "\n"; echo "<td>" . $info["content-type"] . "</td>\n"; echo "<td>" . $info["charset"] . "</td>\n"; echo "</tr>"; } echo "</table>"; /* if we were called to display a part, do so now */ if(isset($_GET['showpart'])) { $showpart = $_GET['showpart']; /* get a handle on the message resource for the desired part */ $sec = mailparse_msg_get_part($mime, $showpart); echo "<table border=1><tr><th>Section $showpart</th></tr><tr><td>"; ob_start(); /* extract the part from the message file and dump it to the output buff er * */ mailparse_msg_extract_part_file($sec, $filename); $contents = ob_get_contents(); ob_end_clean(); /* quote the message for safe display in a browser */ echo nl2br(htmlentities($contents)) . "</td></tr></table>";; } ?> Now the question for anyone who has used this... its there a simple way of using the mailparse functions to extract the multipart/alternative section? (The above code will extract this but i am unsure if it can decode it easily too): This is a multi-part message in MIME format. ------=_NextPart_000_0003_01C7EFCC.434D1340 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable TEst sdfsdfsdf TEst=20 TEst=20 ------=_NextPart_000_0003_01C7EFCC.434D1340 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 6.00.2900.3157" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>TEst sdfsdfsdf <DIV><FONT face=3DArial size=3D2>TEst=20 <DIV><FONT face=3DArial size=3D2>TEst=20 </BODY></HTML> ------=_NextPart_000_0003_01C7EFCC.434D1340-- Link to comment https://forums.phpfreaks.com/topic/70634-solved-mailparse-functions/ Share on other sites More sharing options...
Moloth Posted September 25, 2007 Author Share Posted September 25, 2007 I just realised that im an idiot (scratching my head for 3hrs)... looking at the actual email message there is the (1) multipart/alternative section with the (1.1) text/plain (1.2) text/html imbedded within it... so in actual fact there are only 2 different types of messages there. OOps :-X Link to comment https://forums.phpfreaks.com/topic/70634-solved-mailparse-functions/#findComment-355040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.