1: <?php
2: /**
3: * Copyright 2012-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2012-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Provides logic to format compose message data for delivery to the browser.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2012-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Compose_View
24: {
25: protected $_compose;
26:
27: public function __construct($cache_id)
28: {
29: $this->_compose = $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create($cache_id);
30: }
31:
32: /**
33: * @throws IMP_Exception
34: */
35: public function composeAttachPreview($id, $autodetect = false,
36: $ctype = null)
37: {
38: if (!($atc = $this->_compose[$id]) || !($mime = $atc->getPart(true))) {
39: $e = new IMP_Exception(_("Could not display attachment data."));
40: $e->logged = true;
41: throw $e;
42: }
43: $mime->setMimeId($id);
44:
45: $contents = new IMP_Contents($mime);
46: $render = $contents->renderMIMEPart($id, $contents::RENDER_RAW_FALLBACK, array(
47: 'autodetect' => $autodetect,
48: 'type' => $ctype
49: ));
50:
51: if (!empty($render)) {
52: return reset($render);
53: } elseif ($autodetect) {
54: $e = new IMP_Exception(_("Could not display attachment data."));
55: $e->logged = true;
56: throw $e;
57: }
58:
59: return array();
60: }
61:
62: }
63: