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