For MIMP, prefer text/plain parts in multipart/alternative parts
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 16 Mar 2010 03:39:29 +0000 (21:39 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 16 Mar 2010 03:39:29 +0000 (21:39 -0600)
imp/lib/Mime/Viewer/Alternative.php

index fd7ccd2..ef2825b 100644 (file)
@@ -59,33 +59,44 @@ class IMP_Horde_Mime_Viewer_Alternative extends Horde_Mime_Viewer_Driver
     /**
      * Render out the currently set contents.
      *
-     * @param boolean $inline  Are we viewing inline?
+     * @param boolean $inline        Are we viewing inline?
+     * @param boolean $prefer_plain  For MIMP, prefer text/plain part over
+     *                               all others.
      *
      * @return array  See Horde_Mime_Viewer_Driver::render().
      */
-    protected function _IMPrender($inline)
+    protected function _IMPrender($inline, $prefer_plain = true)
     {
         $base_id = $this->_mimepart->getMimeId();
         $subparts = $this->_mimepart->contentTypeMap();
 
         $base_ids = $display_ids = $ret = array();
 
+        $is_mimp = (IMP::getViewMode() == 'mimp');
+
         /* Look for a displayable part. RFC: show the LAST choice that can be
          * displayed inline. If an alternative is itself a multipart, the user
          * agent is allowed to show that alternative, an earlier alternative,
          * or both. If we find a multipart alternative that contains at least
          * one viewable part, we will display all viewable subparts of that
          * alternative. */
-        foreach (array_keys($subparts) as $mime_id) {
+        foreach ($subparts as $mime_id => $type) {
             $ret[$mime_id] = null;
             if ((strcmp($base_id, $mime_id) !== 0) &&
                 $this->_params['contents']->canDisplay($mime_id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL)) {
-                $display_ids[strval($mime_id)] = true;
+                if (!$is_mimp ||
+                    !$prefer_plain ||
+                    ($type == 'text/plain')) {
+                    $display_ids[strval($mime_id)] = true;
+                }
             }
         }
 
         /* If we found no IDs, return now. */
         if (empty($display_ids)) {
+            if ($is_mimp && $prefer_plain) {
+                return $this->_IMPRender($inline, false);
+            }
             $ret[$base_id] = array(
                 'data' => '',
                 'status' => array(