Tweak some elements to ensure compose attach previews work in all cases
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 31 Aug 2009 21:50:59 +0000 (15:50 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 31 Aug 2009 21:51:06 +0000 (15:51 -0600)
imp/lib/Contents.php
imp/lib/Mime/Viewer/Images.php
imp/view.php

index 5079d36..1a1be0f 100644 (file)
@@ -49,6 +49,14 @@ class IMP_Contents
     static protected $_instances = array();
 
     /**
+     * Internal counter for ensuring Horde_Mime_Part objects passed to
+     * singleton() are given unique objects.
+     *
+     * @var integer
+     */
+    static protected $_mimepartid = 1;
+
+    /**
      * The IMAP index of the message.
      *
      * @var integer
@@ -92,7 +100,7 @@ class IMP_Contents
     static public function singleton($in)
     {
         $sig = ($in instanceof Horde_Mime_Part)
-            ? hash('md5', serialize($in))
+            ? 'horde_mime_part_' . self::$_mimepartid++
             : $in;
 
         if (empty(self::$_instances[$sig])) {
@@ -358,7 +366,9 @@ class IMP_Contents
      * @param array $options   Additional options:
      * <pre>
      * 'mime_part' - (Horde_Mime_Part) The MIME part to render.
-     * 'params' - (array) Additional params to set.
+     * 'params' - (array) Additional params to set. Special params:
+     *            'raw' - The calling code wants display of the raw data,
+     *            without any additional formatting.
      * 'type' - (string) Use this MIME type instead of the MIME type
      *          identified in the MIME part.
      * </pre>
index b1929a6..ce7d179 100644 (file)
@@ -43,7 +43,8 @@ class IMP_Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Images
     protected function _render()
     {
         $view = Horde_Util::getFormData('imp_img_view');
-        if (Horde_Util::getFormData('related_data')) {
+        if (Horde_Util::getFormData('related_data') ||
+            !empty($this->_params['raw'])) {
             $view = 'data';
         }
 
index 6ce5e7b..0e6d0d2 100644 (file)
@@ -67,12 +67,11 @@ if ($actionID == 'compose_attach_preview') {
     /* Initialize the IMP_Compose:: object. */
     $imp_compose = IMP_Compose::singleton(Horde_Util::getFormData('composeCache'));
     $mime = $imp_compose->buildAttachment($id);
+    $mime->setMimeId($id);
 
     /* Create a dummy IMP_Contents() object so we can use the view code below.
      * Then use the 'view_attach' handler to output. */
     $contents = IMP_Contents::singleton($mime);
-    $actionID = 'view_attach';
-    $id = $mime->getMimeId();
 } else {
     $uid = Horde_Util::getFormData('uid');
     $mailbox = Horde_Util::getFormData('mailbox');
@@ -158,8 +157,9 @@ case 'download_render':
     }
     exit;
 
+case 'compose_attach_preview':
 case 'view_attach':
-    $render = $contents->renderMIMEPart($id, Horde_Util::getFormData('mode', IMP_Contents::RENDER_FULL), array('type' => $ctype));
+    $render = $contents->renderMIMEPart($id, Horde_Util::getFormData('mode', IMP_Contents::RENDER_FULL), array('params' => array('raw' => ($actionID == 'compose_attach_preview'), 'type' => $ctype)));
     if (!empty($render)) {
         reset($render);
         $key = key($render);