You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.8 KiB

  1. <?php
  2. /*
  3. * This is a simple email viewer.
  4. * make sure that $filename points to a file containing an email message and
  5. * load this page in your browser.
  6. * You will be able to choose a part to view.
  7. * */
  8. #$filename = "/home/CLIENTWEB/worlddo/mimetests/namib.rfc822";
  9. $filename = "/home/CLIENTWEB/worlddo/mimetests/uumsg";
  10. #$filename = "/home/CLIENTWEB/worlddo/mimetests/segblob.txt";
  11. #$filename = "yourmessage.txt";
  12. /* parse the message and return a mime message resource */
  13. $mime = mailparse_msg_parse_file($filename);
  14. /* return an array of message parts - this contsists of the names of the parts
  15. * only */
  16. $struct = mailparse_msg_get_structure($mime);
  17. echo "<table>\n";
  18. /* print a choice of sections */
  19. foreach($struct as $st) {
  20. echo "<tr>\n";
  21. echo "<td><a href=\"$PHP_SELF?showpart=$st\">$st</a></td>\n";
  22. /* get a handle on the message resource for a subsection */
  23. $section = mailparse_msg_get_part($mime, $st);
  24. /* get content-type, encoding and header information for that section */
  25. $info = mailparse_msg_get_part_data($section);
  26. echo "\n";
  27. echo "<td>" . $info["content-type"] . "</td>\n";
  28. echo "<td>" . $info["content-disposition"] . "</td>\n";
  29. echo "<td>" . $info["disposition-filename"] . "</td>\n";
  30. echo "<td>" . $info["charset"] . "</td>\n";
  31. echo "</tr>";
  32. }
  33. echo "</table>";
  34. /* if we were called to display a part, do so now */
  35. if ($showpart) {
  36. /* get a handle on the message resource for the desired part */
  37. $sec = mailparse_msg_get_part($mime, $showpart);
  38. echo "<table border=1><tr><th>Section $showpart</th></tr><tr><td>";
  39. ob_start();
  40. /* extract the part from the message file and dump it to the output buffer
  41. * */
  42. mailparse_msg_extract_part_file($sec, $filename);
  43. $contents = ob_get_contents();
  44. ob_end_clean();
  45. /* quote the message for safe display in a browser */
  46. echo nl2br(htmlentities($contents)) . "</td></tr></table>";;
  47. }
  48. ?>