Request #6711: pref to choose preferred multipart/alternative display part
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 27 Sep 2010 20:40:27 +0000 (14:40 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 27 Sep 2010 20:40:27 +0000 (14:40 -0600)
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/lib/Mime/Viewer/Alternative.php
imp/lib/Prefs/Ui.php

index 0f5d773..923e98e 100644 (file)
@@ -752,10 +752,11 @@ $prefGroups['viewing'] = array(
     'label' => _("Message Viewing"),
     'desc' => _("Configure how messages are displayed."),
     'members' => array(
-        'filtering', 'strip_attachments', 'html_image_replacement',
-        'html_image_addrbook', 'highlight_text', 'highlight_simple_markup',
-        'show_quoteblocks', 'dim_signature', 'emoticons', 'parts_display',
-        'mail_hdr', 'default_msg_charset', 'disposition_send_mdn'
+        'filtering', 'strip_attachments', 'alternative_display',
+        'html_image_replacement', 'html_image_addrbook', 'highlight_text',
+        'highlight_simple_markup', 'show_quoteblocks', 'dim_signature',
+        'emoticons', 'parts_display', 'mail_hdr', 'default_msg_charset',
+        'disposition_send_mdn'
     )
 );
 
@@ -773,6 +774,18 @@ $_prefs['strip_attachments'] = array(
     'type' => 'checkbox',
     'desc' => _("Show an icon to allow stripping of attachments from messages?"));
 
+// multipart/alternative part display choice
+$_prefs['alternative_display'] = array(
+    'value' => 'html',
+    'advanced' => true,
+    'type' => 'enum',
+    'enum' => array(
+        'html' => _("HTML part"),
+        'text' => _("Plaintext part")
+    ),
+    'desc' => _("For messages with alternative representations of the text part, which part should we display?")
+);
+
 // Replace image tags in inline viewed HTML messages with blank images?
 $_prefs['html_image_replacement'] = array(
     'value' => 1,
index 6c82f01..a033974 100644 (file)
@@ -2,6 +2,8 @@
 v5.0-git
 --------
 
+[mms] Add preference to control displayed content for multipart/alternative
+      parts (Request #6711).
 [mms] Allow multiple messages to be forwarded in a single outgoing message
       (DIMP) (Request #9132).
 [mms] Add personal recipient message filter (Request #8659).
index f5f42b9..a57475c 100644 (file)
@@ -62,19 +62,21 @@ class IMP_Mime_Viewer_Alternative extends Horde_Mime_Viewer_Base
      * Render out the currently set contents.
      *
      * @param boolean $inline        Are we viewing inline?
-     * @param boolean $prefer_plain  For MIMP, prefer text/plain part over
-     *                               all others.
+     * @param boolean $prefer_plain  Prefer text/plain part over all others.
      *
      * @return array  See parent::render().
      */
-    protected function _IMPrender($inline, $prefer_plain = true)
+    protected function _IMPrender($inline, $prefer_plain = null)
     {
         $base_id = $this->_mimepart->getMimeId();
         $subparts = $this->_mimepart->contentTypeMap();
 
         $base_ids = $display_ids = $ret = array();
 
-        $is_mimp = (IMP::getViewMode() == 'mimp');
+        if (is_null($prefer_plain) &&
+            ($GLOBALS['prefs']->getValue('alternative_display') == 'text')) {
+            $prefer_plain = true;
+        }
 
         /* Look for a displayable part. RFC: show the LAST choice that can be
          * displayed inline. If an alternative is itself a multipart, the user
@@ -85,20 +87,22 @@ class IMP_Mime_Viewer_Alternative extends Horde_Mime_Viewer_Base
         foreach ($subparts as $mime_id => $type) {
             $ret[$mime_id] = null;
             if ((strcmp($base_id, $mime_id) !== 0) &&
-                $this->getConfigParam('imp_contents')->canDisplay($mime_id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL)) {
-                if (!$is_mimp ||
-                    !$prefer_plain ||
-                    ($type == 'text/plain')) {
-                    $display_ids[strval($mime_id)] = true;
-                }
+                $this->getConfigParam('imp_contents')->canDisplay($mime_id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL) &&
+                /* Show HTML if $prefer_plain is false-y or if
+                 * alternative_display is not 'html'. */
+                (!$prefer_plain ||
+                 (($type != 'text/html') &&
+                  (strpos($type, 'text/') === 0)))) {
+                $display_ids[strval($mime_id)] = true;
             }
         }
 
         /* If we found no IDs, return now. */
         if (empty($display_ids)) {
-            if ($is_mimp && $prefer_plain) {
+            if ($prefer_plain && (IMP::getViewMode() == 'mimp')) {
                 return $this->_IMPRender($inline, false);
             }
+
             $ret[$base_id] = array(
                 'data' => '',
                 'status' => array(
index 719052b..d961c5a 100644 (file)
@@ -313,6 +313,7 @@ class IMP_Prefs_Ui
             $v = $GLOBALS['injector']->getInstance('IMP_Mime_Viewer')->getViewer($mock_part);
 
             if (!$v->canRender('inline')) {
+                $ui->suppress[] = 'alternative_display';
                 $ui->suppress[] = 'html_image_replacement';
                 $ui->suppress[] = 'html_image_addrbook';
             }