1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24: class IMP_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain
25: {
26: 27: 28: 29: 30:
31: protected function _render()
32: {
33: $data = $this->_impRender(false);
34: $item = reset($data);
35: Horde::startBuffer();
36: $GLOBALS['page_output']->includeStylesheetFiles();
37: $item['data'] = '<html><head>' . Horde::endBuffer() . '</head><body>' . $item['data'] . '</body></html>';
38: $data[key($data)] = $item;
39: return $data;
40: }
41:
42: 43: 44: 45: 46:
47: protected function _renderInline()
48: {
49: return $this->_impRender(true);
50: }
51:
52: 53: 54: 55: 56: 57: 58:
59: protected function _impRender($inline)
60: {
61: global $injector, $prefs, $registry;
62:
63: $cache = $this->getConfigParam('imp_contents')->getViewCache();
64: $mime_id = $this->_mimepart->getMimeId();
65:
66: if (isset($cache->plain[$mime_id])) {
67: return array($mime_id => null);
68: }
69:
70:
71: $charset = $this->_mimepart->getCharset();
72: $text = trim($this->_mimepart->getContents());
73: if ($text == '') {
74: return array(
75: $mime_id => array(
76: 'data' => '',
77: 'type' => 'text/html; charset=' . $charset
78: )
79: );
80: }
81:
82:
83: if ($inline) {
84: $text = Horde_String::convertCharset($text, $charset, 'UTF-8');
85: $charset = $this->getConfigParam('charset');
86: }
87: $type = 'text/html; charset=' . $charset;
88:
89:
90: if ($this->_mimepart->getContentTypeParameter('format') == 'flowed') {
91: $text = $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp'));
92: } else {
93: 94: 95: 96: 97:
98: $text = preg_replace('/(\n+)> ?From(\s+)/', "$1From$2", $text);
99: }
100:
101: $text = IMP::filterText($text);
102:
103:
104: if ($registry->getView() == Horde_Registry::VIEW_MINIMAL) {
105: $filters = array(
106: 'text2html' => array(
107: 'charset' => $charset,
108: 'parselevel' => Horde_Text_Filter_Text2html::NOHTML_NOBREAK
109: )
110: );
111:
112: $text = $this->_textFilter($text, array_keys($filters), array_values($filters));
113:
114: return array(
115: $mime_id => array(
116: 'data' => $text,
117: 'type' => $type
118: )
119: );
120: }
121:
122:
123: $filters = array(
124: 'text2html' => array(
125: 'charset' => $charset,
126: 'parselevel' => $inline ? Horde_Text_Filter_Text2html::MICRO : Horde_Text_Filter_Text2html::MICRO_LINKURL
127: ),
128: 'tabs2spaces' => array(),
129: );
130:
131:
132: if ($prefs->getValue('highlight_text')) {
133: $hideBlocks = $js_blocks = false;
134: if ($registry->getView() !== $registry::VIEW_SMARTMOBILE) {
135: $js_blocks = $inline;
136: if ($inline) {
137: $show = $prefs->getValue('show_quoteblocks');
138: $hideBlocks = (($show == 'hidden') ||
139: (($show == 'thread') && ($injector->getInstance('Horde_Variables')->page == 'thread')));
140: if (!$hideBlocks &&
141: in_array($show, array('list', 'listthread'))) {
142: $header = $this->getConfigParam('imp_contents')->getHeader();
143: $list_info = $injector->getInstance('IMP_Message_Ui')->getListInformation($header);
144: $hideBlocks = $list_info['exists'];
145: }
146: }
147: }
148:
149: if ($js_blocks) {
150: $filters['highlightquotes'] = array(
151: 'hideBlocks' => $hideBlocks,
152: 'noJS' => ($registry->getView() == Horde_Registry::VIEW_DYNAMIC)
153: );
154: } else {
155: $filters['Horde_Text_Filter_Highlightquotes'] = array(
156: 'hideBlocks' => $hideBlocks
157: );
158: }
159: }
160:
161:
162: if ($prefs->getValue('highlight_simple_markup')) {
163: $filters['simplemarkup'] = array();
164: }
165:
166:
167: if ($prefs->getValue('dim_signature')) {
168: $filters['dimsignature'] = array();
169: }
170:
171: if ($prefs->getValue('emoticons')) {
172: $filters['emoticons'] = array('entities' => true);
173: }
174:
175:
176: $status = array();
177: $text = $this->_textFilter($text, array_keys($filters), array_values($filters));
178:
179: if (strlen($text)) {
180:
181: $text = str_replace(array(' ', "\n "), array(' ', "\n "), $text);
182: if (!strncmp($text, ' ', 1)) {
183: $text = ' ' . substr($text, 1);
184: }
185: } else {
186: $error = new IMP_Mime_Status_RenderIssue(array(
187: _("Cannot display message text."),
188: _("The message part may contain incorrect character set information preventing correct display.")
189: ));
190: $error->action(IMP_Mime_Status::ERROR);
191: $status[] = $error;
192: }
193:
194: return array(
195: $mime_id => array(
196: 'data' => "<div class=\"fixed leftAlign\">\n" . $text . '</div>',
197: 'status' => $status,
198: 'type' => $type
199: )
200: );
201: }
202:
203: 204: 205: 206: 207: 208:
209: public function embeddedMimeParts()
210: {
211: return ($this->getConfigParam('pgp_inline') ||
212: $this->getConfigParam('uudecode'));
213: }
214:
215: 216: 217: 218: 219: 220: 221:
222: protected function _getEmbeddedMimeParts()
223: {
224: $ret = $this->getConfigParam('pgp_inline')
225: ? $this->_parsePGP()
226: : null;
227:
228: return (is_null($ret) && $this->getConfigParam('uudecode'))
229: ? $this->_parseUUencode()
230: : $ret;
231: }
232:
233: 234: 235: 236: 237: 238:
239: protected function _parsePGP()
240: {
241: $part = $GLOBALS['injector']->getInstance('Horde_Crypt_Pgp_Parse')->parseToPart(
242: new Horde_Stream_Existing(array(
243: 'stream' => $this->_mimepart->getContents(array('stream' => true))
244: )),
245: $this->_mimepart->getCharset()
246: );
247:
248: if (!is_null($part)) {
249: $cache = $this->getConfigParam('imp_contents')->getViewCache();
250: $cache->plain[$this->_mimepart->getMimeId()] = true;
251: }
252:
253: return $part;
254: }
255:
256: 257: 258: 259: 260: 261:
262: protected function _parseUUencode()
263: {
264: $text = Horde_String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset(), 'UTF-8');
265:
266: $files = new Horde_Mime_Uudecode($text);
267: if (!count($files)) {
268: return null;
269: }
270:
271: $new_part = new Horde_Mime_Part();
272: $new_part->setType('multipart/mixed');
273:
274: $text_part = new Horde_Mime_Part();
275: $text_part->setType('text/plain');
276: $text_part->setCharset($this->getConfigParam('charset'));
277: $text_part->setContents(preg_replace("/begin [0-7]{3} .+\r?\n.+\r?\nend/Us", "\n", $text));
278: $new_part->addPart($text_part);
279:
280: foreach ($files as $file) {
281: $uupart = new Horde_Mime_Part();
282: $uupart->setType('application/octet-stream');
283: $uupart->setContents($file['data']);
284: $uupart->setName(strip_tags($file['name']));
285: $new_part->addPart($uupart);
286: }
287:
288: return $new_part;
289: }
290:
291: 292: 293: 294: 295: 296:
297: public function overLimitText()
298: {
299: $stream = $this->_mimepart->getContents(array('stream' => true));
300: rewind($stream);
301:
302:
303: $filters = array(
304: 'text2html' => array(
305: 'parselevel' => Horde_Text_Filter_Text2html::MICRO
306: ),
307: 'tabs2spaces' => array(),
308: );
309:
310: return '<div class="fixed">' .
311: $this->_textFilter(Horde_String::convertCharset(fread($stream, 1024), $this->_mimepart->getCharset(), 'UTF-8'), array_keys($filters), array_values($filters)) .
312: ' [...]</div>';
313: }
314:
315: }
316: