/lib/MIME/Viewer/partial.php

https://github.com/Excito/imp · PHP · 85 lines · 41 code · 11 blank · 33 comment · 6 complexity · a0cb543cd0f3a9f18d8b8793591639bd MD5 · raw file

  1. <?php
  2. /**
  3. * The IMP_MIME_Viewer_partial class allows multipart/partial messages to be
  4. * displayed (RFC 2046 [5.2.2]).
  5. *
  6. * $Horde: imp/lib/MIME/Viewer/partial.php,v 1.17.10.14 2009/01/06 15:24:09 jan Exp $
  7. *
  8. * Copyright 2003-2009 The Horde Project (http://www.horde.org/)
  9. *
  10. * See the enclosed file COPYING for license information (GPL). If you
  11. * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  12. *
  13. * @author Michael Slusarz <slusarz@horde.org>
  14. * @package Horde_MIME_Viewer
  15. */
  16. class IMP_MIME_Viewer_partial extends MIME_Viewer {
  17. /**
  18. * Render out the currently set contents.
  19. *
  20. * @param array $params An array with a reference to a MIME_Contents
  21. * object.
  22. *
  23. * @return string The rendered text in HTML.
  24. */
  25. function render($params)
  26. {
  27. $contents = &$params[0];
  28. $base_ob = &$contents->getBaseObjectPtr();
  29. $curr_index = $base_ob->getMessageIndex();
  30. $id = $this->mime_part->getContentTypeParameter('id');
  31. $parts = array();
  32. require_once IMP_BASE . '/lib/IMAP/Search.php';
  33. require_once 'Horde/MIME/Contents.php';
  34. require_once 'Horde/MIME/Structure.php';
  35. /* Perform the search to find the other parts of the message. */
  36. $imap_search = &IMP_IMAP_Search::singleton(array('pop3' => ($_SESSION['imp']['base_protocol'] == 'pop3')));
  37. $query = new IMP_IMAP_Search_Query();
  38. $query->header('Content-Type', $id);
  39. $indices = $imap_search->searchMailbox($query, null, $GLOBALS['imp_mbox']['thismailbox']);
  40. /* If not able to find the other parts of the message, print error. */
  41. if (count($indices) != $this->mime_part->getContentTypeParameter('total')) {
  42. return $contents->formatStatusMsg(sprintf(_("Cannot display - found only %s of %s parts of this message in the current mailbox."), count($indices), $this->mime_part->getContentTypeParameter('total')));
  43. }
  44. /* Get the contents of each of the parts. */
  45. foreach ($indices as $val) {
  46. /* No need to fetch the current part again. */
  47. if ($val == $curr_index) {
  48. $parts[$this->mime_part->getContentTypeParameter('number')] = $this->mime_part->getContents();
  49. } else {
  50. require_once IMP_BASE . '/lib/MIME/Contents.php';
  51. require_once IMP_BASE . '/lib/MIME/Headers.php';
  52. $imp_contents = &IMP_Contents::singleton($val . IMP_IDX_SEP . $GLOBALS['imp_mbox']['thismailbox']);
  53. $part = &$imp_contents->getMIMEPart(0);
  54. $parts[$part->getContentTypeParameter('number')] = $imp_contents->getBody();
  55. }
  56. }
  57. /* Sort the parts in numerical order. */
  58. ksort($parts, SORT_NUMERIC);
  59. /* Combine the parts and render the underlying data. */
  60. $mime_message = &MIME_Structure::parseTextMIMEMessage(implode('', $parts));
  61. $mc = new MIME_Contents($mime_message, array('download' => 'download_attach', 'view' => 'view_attach'), array(&$contents));
  62. $mc->buildMessage();
  63. return '<table>' . $mc->getMessage(true) . '</table>';
  64. }
  65. /**
  66. * Return the content-type of the rendered output.
  67. *
  68. * @return string The content-type of the output.
  69. */
  70. function getType()
  71. {
  72. return 'text/html; charset=' . NLS::getCharset();
  73. }
  74. }