[ 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/ -> tnef.php (source)

   1  <?php
   2  
   3  require_once 'Horde/MIME/Viewer/tnef.php';
   4  
   5  /**
   6   * The IMP_MIME_Viewer_tnef class allows MS-TNEF attachments to be displayed.
   7   *
   8   * $Horde: imp/lib/MIME/Viewer/tnef.php,v 1.25.10.9 2007/01/02 13:55:00 jan Exp $
   9   *
  10   * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu>
  11   *
  12   * See the enclosed file COPYING for license information (GPL). If you
  13   * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  14   *
  15   * @author  Michael Slusarz <slusarz@bigworm.colorado.edu>
  16   * @since   IMP 4.0
  17   * @package Horde_MIME_Viewer
  18   */
  19  class IMP_MIME_Viewer_tnef extends MIME_Viewer_tnef {
  20  
  21      /**
  22       * The contentType of the attachment.
  23       *
  24       * @var string
  25       */
  26      var $_contentType = 'application/octet-stream';
  27  
  28      /**
  29       * Render out the currently set contents.
  30       *
  31       * @param array $params  An array with a reference to a MIME_Contents
  32       *                       object.
  33       *
  34       * @return string  Either the list of tnef files or the data of an
  35       *                 individual tnef file.
  36       */
  37      function render($params)
  38      {
  39          $contents = &$params[0];
  40  
  41          $text = '';
  42  
  43          /* Get the data from the attachment. */
  44          $tnefData = $this->_getSubparts();
  45  
  46          /* Display the requested file. Its position in the $tnefData
  47             array can be found in 'tnef_attachment'. */
  48          if (Util::getFormData('tnef_attachment')) {
  49              $tnefKey = Util::getFormData('tnef_attachment') - 1;
  50              /* Verify that the requested file exists. */
  51              if (isset($tnefData[$tnefKey])) {
  52                  $text = $tnefData[$tnefKey]['stream'];
  53                  if (empty($text)) {
  54                      $text = $contents->formatStatusMsg(_("Could not extract the requested file from the MS-TNEF attachment."));
  55                  } else {
  56                      $this->mime_part->setName($tnefData[$tnefKey]['name']);
  57                      $this->mime_part->setType($tnefData[$tnefKey]['type'] . '/' . $tnefData[$tnefKey]['subtype']);
  58                  }
  59              } else {
  60                  $text = $contents->formatStatusMsg(_("The requested file does not exist in the MS-TNEF attachment."));
  61              }
  62          } else {
  63              $text = $this->renderAttachmentInfo(array($params[0]));
  64          }
  65  
  66          return $text;
  67      }
  68  
  69      /**
  70       * Render out TNEF attachment information.
  71       *
  72       * @param array $params  An array with a reference to a MIME_Contents
  73       *                       object.
  74       *
  75       * @return string  The rendered text in HTML.
  76       */
  77      function renderAttachmentInfo($params)
  78      {
  79          $contents = &$params[0];
  80  
  81          $text = '';
  82  
  83          /* Make sure the contents are in the MIME_Part object. */
  84          if (!$this->mime_part->getContents()) {
  85              $this->mime_part->setContents($contents->getBodyPart($this->mime_part->getMIMEId()));
  86          }
  87  
  88          /* Get the data from the attachment. */
  89          $tnefData = $this->_getSubparts();
  90  
  91          if (!count($tnefData)) {
  92              $text = $contents->formatStatusMsg(_("No attachments found."));
  93          } else {
  94              $text = $contents->formatStatusMsg(_("The following files were attached to this part:")) . '<br />';
  95              foreach ($tnefData as $key => $data) {
  96                  $temp_part = $this->mime_part;
  97                  $temp_part->setName($data['name']);
  98                  $temp_part->setDescription($data['name']);
  99  
 100                  /* Short-circuit MIME-type guessing for winmail.dat parts;
 101                     we're showing enough entries for them already. */
 102                  require_once 'Horde/MIME/Magic.php';
 103                  $type = $data['type'] . '/' . $data['subtype'];
 104                  if (($type == 'application/octet-stream') ||
 105                      ($type == 'application/base64')) {
 106                      $type = MIME_Magic::filenameToMIME($data['name']);
 107                  }
 108                  $temp_part->setType($type);
 109  
 110                  $link = $contents->linkView($temp_part, 'view_attach', $data['name'], array('jstext' => sprintf(_("View %s"), $data['name']), 'viewparams' => array('tnef_attachment' => ($key + 1))));
 111                  $text .= _("Attached File:") . '&nbsp;&nbsp;' . $link . '&nbsp;&nbsp;(' . $data['type'] . '/' . $data['subtype'] . ")<br />\n";
 112              }
 113          }
 114  
 115          return $text;
 116      }
 117  
 118      /**
 119       * List any embedded attachments in the TNEF part.
 120       *
 121       * @access private
 122       *
 123       * @return array  An array of any embedded attachments.
 124       */
 125      function _getSubparts()
 126      {
 127          require_once 'Horde/Compress.php';
 128          $tnef = &Horde_Compress::singleton('tnef');
 129          return $tnef->decompress($this->mime_part->transferDecode());
 130      }
 131  
 132      /**
 133       * Return the content-type.
 134       *
 135       * @return string  The content-type of the output.
 136       */
 137      function getType()
 138      {
 139          if (Util::getFormData('tnef_attachment')) {
 140              return $this->_contentType;
 141          } else {
 142              return 'text/html; charset=' . NLS::getCharset();
 143          }
 144      }
 145  
 146  }


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