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

   1  <?php
   2  
   3  require_once 'Horde/MIME/Viewer/plain.php';
   4  
   5  /**
   6   * The IMP_MIME_Viewer_plain class renders out text/plain MIME parts
   7   * with URLs made into hyperlinks.
   8   *
   9   * $Horde: imp/lib/MIME/Viewer/plain.php,v 1.58.8.18 2007/01/12 14:40:51 jan Exp $
  10   *
  11   * Copyright 1999-2007 Anil Madhavapeddy <anil@recoil.org>
  12   * Copyright 2002-2007 Michael Slusarz <slusarz@horde.org>
  13   *
  14   * See the enclosed file COPYING for license information (GPL). If you
  15   * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  16   *
  17   * @author  Anil Madhavapeddy <anil@recoil.org>
  18   * @author  Michael Slusarz <slusarz@horde.org>
  19   * @since   IMP 4.0
  20   * @package Horde_MIME_Viewer
  21   */
  22  class IMP_MIME_Viewer_plain extends MIME_Viewer_plain {
  23  
  24      /**
  25       * Render out the currently set contents.
  26       *
  27       * @param array $params  An array with a reference to a MIME_Contents
  28       *                       object.
  29       *
  30       * @return string  The rendered text in HTML.
  31       */
  32      function render($params)
  33      {
  34          $contents = &$params[0];
  35  
  36          global $conf, $prefs;
  37  
  38          $flowed = ($this->mime_part->getContentTypeParameter('format') == 'flowed');
  39          $text = $this->mime_part->getContents();
  40  
  41          // If calling as an attachment from view.php, we do not want to alter
  42          // the text in any way with HTML.
  43          if ($contents->viewAsAttachment()) {
  44              // Check for 'flowed' text data.
  45              if ($flowed) {
  46                  $text = $this->_formatFlowed($text, 90, null, $this->mime_part->getContentTypeParameter('delsp'));
  47              }
  48              return $text;
  49          }
  50  
  51          if ($text === false) {
  52              return $contents->formatStatusMsg(_("There was an error displaying this message part"));
  53          }
  54  
  55          // Trim extra whitespace in the text.
  56          $text = rtrim($text);
  57          if ($text == '') {
  58              return '';
  59          }
  60  
  61          // If requested, scan the message for PGP data.
  62          if (!empty($conf['utils']['gnupg']) &&
  63              $prefs->getValue('pgp_scan_body') &&
  64              preg_match('/-----BEGIN PGP ([^-]+)-----/', $text)) {
  65              require_once  IMP_BASE . '/lib/Crypt/PGP.php';
  66              $imp_pgp = &new IMP_PGP();
  67              if (($out = $imp_pgp->parseMessageOutput($this->mime_part, $contents))) {
  68                  return $out;
  69              }
  70          }
  71  
  72          // If requested, scan the message for UUencoded data.
  73          if ($this->getConfigParam('uuencode')) {
  74              require_once 'Mail/mimeDecode.php';
  75              $files = &Mail_mimeDecode::uudecode($text);
  76          }
  77  
  78          // Check for 'flowed' text data.
  79          if ($flowed) {
  80              $text = $this->_formatFlowed($text, 90, (IMP::printMode()) ? 0 : null, $this->mime_part->getContentTypeParameter('delsp'));
  81          }
  82  
  83          // Build filter stack. Starts with HTML markup and tab expansion.
  84          require_once 'Horde/Text/Filter.php';
  85          $filters = array('text2html', 'tabs2spaces');
  86          $filter_params = array(array('parselevel' => TEXT_HTML_MICRO,
  87                                       'charset' => $this->mime_part->getCharset()),
  88                                 array());
  89  
  90          /* A "From" located at the beginning of a line in the body text will
  91           * be escaped with a '>' by the IMAP server.  Remove this escape
  92           * character or else the line will display as being quoted. Flowed
  93           * conversion would have already taken care of this for us. */
  94          if (!$flowed) {
  95              $text = preg_replace('/(\n+)> ?From(\s+)/', "$1From$2", $text);
  96          }
  97  
  98          // Highlight quoted parts of an email.
  99          if ($prefs->getValue('highlight_text')) {
 100              $filters[] = 'highlightquotes';
 101              $hideBlocks = ($prefs->getValue('show_quoteblocks') == 'hidden') ||
 102                  ($prefs->getValue('show_quoteblocks') == 'thread' &&
 103                   basename(Horde::selfUrl()) == 'thread.php');
 104              $filter_params[] = array('hideBlocks' => $hideBlocks);
 105          }
 106  
 107          // Highlight simple markup of an email.
 108          if ($prefs->getValue('highlight_simple_markup')) {
 109              $filters[] = 'simplemarkup';
 110              $filter_params[] = array();
 111          }
 112  
 113          // Dim signatures.
 114          if ($prefs->getValue('dim_signature')) {
 115              $filters[] = 'dimsignature';
 116              $filter_params[] = array();
 117          }
 118  
 119          // Filter bad language.
 120          if ($prefs->getValue('filtering')) {
 121              $filters[] = 'words';
 122              $filter_params[] = array('words_file' => $conf['msgsettings']['filtering']['words'],
 123                                       'replacement' => $conf['msgsettings']['filtering']['replacement']);
 124          }
 125  
 126          // Run filters.
 127          $text = Text_Filter::filter($text, $filters, $filter_params);
 128  
 129          // Wordwrap.
 130          $text = str_replace('  ', ' &nbsp;', $text);
 131          $text = str_replace("\n ", "\n&nbsp;", $text);
 132          if ($text{0} == ' ') {
 133              $text = '&nbsp;' . substr($text, 1);
 134          }
 135          $text = '<div class="fixed leftAlign">' . "\n" . $text . '</div>';
 136  
 137          // Replace UUencoded data with links now.
 138          if ($this->getConfigParam('uuencode') && !empty($files)) {
 139              foreach ($files as $file) {
 140                  $uupart = &new MIME_Part();
 141                  $uupart->setContents($file['filedata']);
 142                  $uupart->setName(strip_tags($file['filename']));
 143  
 144                  $uumessage = &MIME_Message::convertMIMEPart($uupart);
 145                  $mc = &new MIME_Contents($uumessage, array('download' => 'download_attach', 'view' => 'view_attach'), array(&$contents));
 146                  $mc->buildMessage();
 147  
 148                  $text = preg_replace("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", '<table>' . $mc->getMessage(true) . '</table>', $text, 1);
 149              }
 150          }
 151  
 152          return $text;
 153      }
 154  
 155  }


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