[ Index ]
 

Code source de IMP H3 (4.1.5)

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/lib/MIME/Viewer/ -> status.php (source)

   1  <?php
   2  /**
   3   * The IMP_MIME_Viewer_status class handles multipart/report messages
   4   * that refer to mail system administrative messages (RFC 3464).
   5   *
   6   * $Horde: imp/lib/MIME/Viewer/status.php,v 1.17.10.10 2007/01/02 13:55:00 jan Exp $
   7   *
   8   * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu>
   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@bigworm.colorado.edu>
  14   * @since   IMP 4.0
  15   * @package Horde_MIME_Viewer
  16   */
  17  class IMP_MIME_Viewer_status extends MIME_Viewer {
  18  
  19      /**
  20       * Render out the currently set contents.
  21       *
  22       * @param array $params  An array with a reference to a MIME_Contents
  23       *                       object.
  24       *
  25       * @return string  The rendered text in HTML.
  26       */
  27      function render($params)
  28      {
  29          $contents = &$params[0];
  30  
  31          /* If this is a straight message/delivery-status part, just output
  32             the text. */
  33          if ($this->mime_part->getType() == 'message/delivery-status') {
  34              $part = &new MIME_Part('text/plain');
  35              $part->setContents($this->mime_part->getContents());
  36              return '<pre>' . $contents->renderMIMEPart($part) . '</pre>';
  37          }
  38  
  39          global $registry;
  40  
  41          /* RFC 3464 [2]: There are three parts to a delivery status
  42             multipart/report message:
  43               (1) Human readable message
  44               (2) Machine parsable body part (message/delivery-status)
  45               (3) Returned message (optional)
  46  
  47             Information on the message status is found in the 'Action' field
  48             located in part #2 (RFC 2464 [2.3.3]). It can be either 'failed',
  49             'delayed', 'delivered', 'relayed', or 'expanded'. */
  50          $action = null;
  51          $part2 = $contents->getDecodedMIMEPart($this->mime_part->getRelativeMIMEId(2));
  52          if (empty($part2)) {
  53              return $this->_errorMsg($contents);
  54          }
  55  
  56          foreach (explode("\n", $part2->getContents()) as $line) {
  57              if (strstr($line, 'Action:') !== false) {
  58                  $pos = strpos($line, ':') + 1;
  59                  $action = strtolower(trim(substr($line, $pos)));
  60                  break;
  61              }
  62          }
  63          if (strpos($action, ' ') !== false) {
  64              $action = substr($action, 0, strpos($action, ' '));
  65          }
  66  
  67          /* Get the correct text strings for the action type. */
  68          switch ($action) {
  69          case 'failed':
  70          case 'delayed':
  71              $graphic = 'alerts/error.png';
  72              $alt = _("Error");
  73              $msg = array(
  74                  _("ERROR: Your message could not be delivered."),
  75                  _("The mail server generated the following error message:")
  76              );
  77              $detail_msg =  _("Additional message error details can be viewed %s.");
  78              $detail_msg_status = _("Additional message error details");
  79              $msg_link = _("The text of the returned message can be viewed %s.");
  80              $msg_link_status = _("The text of the returned message");
  81              break;
  82  
  83          case 'delivered':
  84          case 'expanded':
  85          case 'relayed':
  86              $graphic = 'alerts/success.png';
  87              $alt = _("Success");
  88              $msg = array(
  89                  _("Your message was successfully delivered."),
  90                  _("The mail server generated the following message:")
  91              );
  92              $detail_msg =  _("Additional message details can be viewed %s.");
  93              $detail_msg_status = _("Additional message details");
  94              $msg_link = _("The text of the message can be viewed %s.");
  95              $msg_link_status = _("The text of the message");
  96              break;
  97  
  98          default:
  99              $graphic = '';
 100              $alt = '';
 101              $msg = '';
 102              $detail_msg = '';
 103              $detail_msg_status = '';
 104              $msg_link = '';
 105              $msg_link_status = '';
 106          }
 107  
 108          /* Print the human readable message. */
 109          $part = $contents->getDecodedMIMEPart($this->mime_part->getRelativeMIMEId(1));
 110          if (empty($part)) {
 111              return $this->_errorMsg($contents);
 112          }
 113  
 114          $statusimg = Horde::img($graphic, $alt, 'height="16" width="16"', $registry->getImageDir('horde'));
 115          $text = $contents->formatStatusMsg($msg, $statusimg);
 116          $text .= '<blockquote>' . $contents->renderMIMEPart($part) . '</blockquote>' . "\n";
 117  
 118          /* Display a link to more detailed error message. */
 119          $detailed_msg = array(
 120              sprintf($detail_msg, $contents->linkViewJS($part2, 'view_attach', _("HERE"), $detail_msg_status))
 121          );
 122  
 123          /* Display a link to the returned message. Try to download the
 124             text of the message/rfc822 part first, if it exists. */
 125          if (($part = $contents->getDecodedMIMEPart($this->mime_part->getRelativeMIMEId(3))) ||
 126              ($part = $contents->getDecodedMIMEPart($this->mime_part->getRelativeMIMEId('3.0')))) {
 127              $detailed_msg[] = sprintf($msg_link, $contents->linkViewJS($part, 'view_attach', _("HERE"), $msg_link_status, null, array('ctype' => 'message/rfc822')));
 128          }
 129  
 130          $infoimg = Horde::img('info_icon.png', _("Info"), 'height="16" width="16"', $registry->getImageDir('horde'));
 131          $text .= $contents->formatStatusMsg($detailed_msg, $infoimg, false);
 132  
 133          return $text;
 134      }
 135  
 136  
 137      /**
 138       * Return the content-type.
 139       *
 140       * @return string  The content-type of the message.
 141       */
 142      function getType()
 143      {
 144          return 'text/html; charset=' . NLS::getCharset();
 145      }
 146  
 147      /**
 148       * Returns an error string for a malformed RFC 3464 message.
 149       *
 150       * @param MIME_Contents &$contents  The MIME_Contents object for this
 151       *                                  message.
 152       *
 153       * @return string  The error message string.
 154       */
 155      function _errorMsg(&$contents)
 156      {
 157          $err_msg = array(
 158              _("This message contains mail delivery status information, but the format of this message is unknown."),
 159              _("Below is the raw text of the status information message.")
 160          );
 161          $img = Horde::img('alerts/error.png', _("Error"), 'height="16" width="16"', $GLOBALS['registry']->getImageDir('horde'));
 162  
 163          $text = $contents->formatStatusMsg($err_msg, $img);
 164  
 165          /* There is currently no BC way to obtain all parts from a message
 166           * and display the summary of each part.  So instead, display the
 167           * entire raw contents of the message. See Bug 3757. */
 168          $text .= '<pre>';
 169          if (is_a($contents, 'IMP_Contents')) {
 170              $contents->rebuildMessage();
 171              $message = $contents->getMIMEMessage();
 172              $text .= $contents->toString($message, true);
 173          } else {
 174              $text .= htmlspecialchars($this->mime_part->getContents());
 175          }
 176  
 177          return $text . '</pre>';
 178      }
 179  
 180  }


Généré le : Thu Nov 29 12:30:07 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics