Add preference to allow viewing of all inline parts by default (MIMP)
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 15 Mar 2010 21:06:06 +0000 (15:06 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 15 Mar 2010 21:40:37 +0000 (15:40 -0600)
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/lib/Ui/Message.php
imp/lib/Views/ShowMessage.php
imp/message-mimp.php
imp/message.php
imp/templates/message/download-mimp.html [deleted file]
imp/templates/message/message-mimp.html
imp/templates/message/part-mimp.html [new file with mode: 0644]

index 8dc7df0..eabbce5 100644 (file)
@@ -204,7 +204,8 @@ $prefGroups['mimp'] = array(
     'column' => _("Other Options"),
     'label' => _("Minimalist View Options"),
     'desc' => _("Configure options for the minimalist view."),
-    'members' => array('mimp_preview_msg', 'mimp_download_confirm')
+    'members' => array('mimp_preview_msg', 'mimp_download_confirm',
+                       'mimp_inline_all')
 );
 
 $prefGroups['standard'] = array(
@@ -1635,12 +1636,22 @@ $_prefs['mimp_preview_msg'] = array(
 
 $_prefs['mimp_download_confirm'] = array(
     'value' => 0,
+    // Locked by default
     'locked' => true,
     'shared' => false,
     'type' => 'number',
     'desc' => _("Only show download confirmation page if message part is greater than this size, in bytes. Set to 0 to always require the confirmation page.")
 );
 
+$_prefs['mimp_inline_all'] = array(
+    'value' => 0,
+    // Locked by default
+    'locked' => true,
+    'shared' => false,
+    'type' => 'checkbox',
+    'desc' => _("Show all inline parts by default in message view? If unchecked, will treat all but the first viewable inline part as attachments.")
+);
+
 // End Minimalist View Options
 
 // Standard View Options
index 7b2596f..e096bcd 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Add preference to allow viewing of all inline parts by default (MIMP).
 [mms] Add hook to alter composed message details before sending.
 [mms] DIMP now honors the 'allow_resume_all' configuration option.
 [mms] Remove 'sort_limit' configuration option.
index 548abf3..d46275f 100644 (file)
@@ -458,14 +458,22 @@ class IMP_Ui_Message
     }
 
     /**
-     * Output inline message display for the imp and dimp views.
+     * Generate inline message display.
      *
-     * @param object $imp_contents      The IMP_Contents object containing the
-     *                                  message data.
-     * @param integer $contents_mask    The mask needed for a
-     *                                  IMP_Contents::getSummary() call.
-     * @param array $part_info_display  The list of summary fields to display.
-     * @param string $show_parts        The value of the 'parts_display' pref.
+     * @param object $imp_contents  The IMP_Contents object containing the
+     *                              message data.
+     * @param array $options        Additional options:
+     * <pre>
+     * 'display_mask' - (integer) The mask of display view type to render
+     *                  inline (DEFAULT: IMP_Contents::RENDER_INLINE_AUTO).
+     * 'mask' - (integer) The mask needed for a IMP_Contents::getSummary()
+     *          call.
+     * 'no_inline_all' - (boolean) If true, only display first inline part.
+     *                   Subsequent inline parts will be treated as
+     *                   attachments.
+     * 'part_info_display' - (array) The list of summary fields to display.
+     * 'show_parts' - (string) The value of the 'parts_display' pref.
+     * </pre>
      *
      * @return array  An array with the following keys:
      * <pre>
@@ -475,13 +483,26 @@ class IMP_Ui_Message
      * 'msgtext' - (string) The rendered HTML code.
      * </pre>
      */
-    public function getInlineOutput($imp_contents, $contents_mask,
-                                    $part_info_display, $show_parts)
+    public function getInlineOutput($imp_contents, $options = array())
     {
         $atc_parts = $display_ids = $js_onload = $wrap_ids = array();
         $msgtext = '';
         $parts_list = $imp_contents->getContentTypeMap();
 
+        $contents_mask = isset($options['mask'])
+            ? $options['mask']
+            : 0;
+        $display_mask = isset($options['display_mask'])
+            ? $options['display_mask']
+            : IMP_Contents::RENDER_INLINE_AUTO;
+        $no_inline_all = !empty($options['no_inline_all']);
+        $part_info_display = isset($options['part_info_display'])
+            ? $options['part_info_display']
+            : array();
+        $show_parts = isset($options['show_parts'])
+            ? $options['show_parts']
+            : $GLOBALS['prefs']->getValue('parts_display');
+
         if ($show_parts == 'all') {
             $atc_parts = array_keys($parts_list);
         }
@@ -491,13 +512,15 @@ class IMP_Ui_Message
                 continue;
             }
 
-            if (!($render_mode = $imp_contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO))) {
+            if (!($render_mode = $imp_contents->canDisplay($mime_id, $display_mask))) {
                 if ($imp_contents->isAttachment($mime_type)) {
                     if ($show_parts == 'atc') {
                         $atc_parts[] = $mime_id;
                     }
 
-                    $msgtext .= $this->formatSummary($imp_contents->getSummary($mime_id, $contents_mask), $part_info_display, true);
+                    if ($contents_mask) {
+                        $msgtext .= $this->formatSummary($imp_contents->getSummary($mime_id, $contents_mask), $part_info_display, true);
+                    }
                 }
                 continue;
             }
@@ -512,13 +535,20 @@ class IMP_Ui_Message
 
             if (empty($render_part)) {
                 if ($imp_contents->isAttachment($mime_type)) {
-                    $msgtext .= $this->formatSummary($imp_contents->getSummary($mime_id, $contents_mask), $part_info_display, true);
+                    if ($contents_mask) {
+                        $msgtext .= $this->formatSummary($imp_contents->getSummary($mime_id, $contents_mask), $part_info_display, true);
+                    }
                 }
                 continue;
             }
 
             reset($render_part);
             while (list($id, $info) = each($render_part)) {
+                if ($no_inline_all === 1) {
+                    $atc_parts[] = $id;
+                    continue;
+                }
+
                 $display_ids[] = $id;
 
                 if (empty($info)) {
@@ -537,20 +567,33 @@ class IMP_Ui_Message
                 }
 
                 if (empty($info['attach'])) {
-                    $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display) .
-                        $this->formatStatusMsg($info['status']) .
-                        '<div class="mimePartData">' . $info['data'] . '</div>';
+                    if ($contents_mask) {
+                        $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display) .
+                            $this->formatStatusMsg($info['status']) .
+                            '<div class="mimePartData">' . $info['data'] . '</div>';
+                    } else {
+                        if ($msgtext && !empty($options['sep'])) {
+                            $msgtext .= $options['sep'];
+                        }
+                        $msgtext .= $info['data'];
+                    }
                 } else {
                     if ($show_parts == 'atc') {
                         $atc_parts[] = $id;
                     }
 
-                    $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display, true);
+                    if ($contents_mask) {
+                        $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display, true);
+                    }
                 }
 
                 if (isset($info['js'])) {
                     $js_onload = array_merge($js_onload, $info['js']);
                 }
+
+                if ($no_inline_all) {
+                    $no_inline_all = 1;
+                }
             }
         }
 
index 8237f80..74b5e42 100644 (file)
@@ -262,7 +262,11 @@ class IMP_Views_ShowMessage
 
         /* Build body text. This needs to be done before we build the
          * attachment list. */
-        $inlineout = $imp_ui->getInlineOutput($imp_contents, $contents_mask, $part_info_display, $show_parts);
+        $inlineout = $imp_ui->getInlineOutput($imp_contents, array(
+            'mask' => $contents_mask,
+            'part_info_display' => $part_info_display,
+            'show_parts' => $show_parts
+        ));
 
         $result['js'] = array_merge($result['js'], $inlineout['js_onload']);
         $result['msgtext'] .= $inlineout['msgtext'];
index ee1807f..e1adb8f 100644 (file)
@@ -75,7 +75,7 @@ case 'ri':
     $msg_delete = (IMP_Spam::reportSpam(array($index_array['mailbox'] => array($index_array['uid'])), $vars->a == 'rs' ? 'spam' : 'innocent') === 1);
     break;
 
-// 'c' = confirm download
+// 'pa' = part action
 // Need to build message information, so don't do action until below.
 }
 
@@ -139,20 +139,29 @@ $self_link = IMP::generateIMPUrl('message-mimp.php', $imp_mbox['mailbox'], $uid,
 $t = $injector->createInstance('Horde_Template');
 $t->setOption('gettext', true);
 
-/* Output download confirmation screen. */
-if (($vars->a == 'c') && isset($vars->atc)) {
-    $summary = $imp_contents->getSummary($vars->atc, IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_DESCRIP_NOLINK_NOHTMLSPECCHARS | IMP_Contents::SUMMARY_DOWNLOAD_NOJS);
+/* Output part action screen. */
+if (($vars->a == 'pa') &&
+    (isset($vars->atc) || isset($vars->id))) {
+    if (isset($vars->atc)) {
+        $summary = $imp_contents->getSummary($vars->atc, IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_DESCRIP_NOLINK_NOHTMLSPECCHARS | IMP_Contents::SUMMARY_DOWNLOAD_NOJS);
 
-    $title = _("Verify Download");
+        $title = _("Download Attachment");
+
+        $t->set('descrip', $summary['description']);
+        $t->set('download', $summary['download']);
+        $t->set('size', $summary['size']);
+        $t->set('type', $summary['type']);
+    } else {
+        $title = _("View Attachment");
+
+        $data = $imp_contents->renderMIMEPart($vars->id, $imp_contents->canDisplay($vars->id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO));
+        $t->set('view_data', $data ? $data : _("This part is empty."));
+    }
 
-    $t->set('descrip', $summary['description']);
-    $t->set('download', $summary['download']);
     $t->set('self_link', $self_link);
-    $t->set('size', $summary['size']);
-    $t->set('type', $summary['type']);
 
     require IMP_TEMPLATES . '/common-header.inc';
-    echo $t->fetch(IMP_TEMPLATES . '/message/download-mimp.html');
+    echo $t->fetch(IMP_TEMPLATES . '/message/part-mimp.html');
 
     exit;
 }
@@ -231,46 +240,13 @@ foreach ($flag_parse as $val) {
 }
 
 /* Create the body of the message. */
-$parts_list = $imp_contents->getContentTypeMap();
-$atc_parts = $display_ids = array();
-$body_shown = false;
-$msg_text = '';
-
-foreach ($parts_list as $mime_id => $mime_type) {
-    if (in_array($mime_id, $display_ids, true)) {
-        continue;
-    }
-
-    if ($body_shown ||
-        !($render_mode = $imp_contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO))) {
-        if ($imp_contents->isAttachment($mime_type)) {
-            $atc_parts[] = $mime_id;
-        }
-        continue;
-    }
-
-    $render_part = $imp_contents->renderMIMEPart($mime_id, $render_mode);
-    if (($render_mode & IMP_Contents::RENDER_INLINE) && empty($render_part)) {
-        /* This meant that nothing was rendered - allow this part to appear
-         * in the attachment list instead. */
-        $atc_parts[] = $mime_id;
-        continue;
-    }
-
-    while (list($id, $info) = each($render_part)) {
-        if ($body_shown) {
-            $atc_parts[] = $id;
-            continue;
-        }
-
-        if (empty($info)) {
-            continue;
-        }
+$inlineout = $imp_ui->getInlineOutput($imp_contents, array(
+    'display_mask' => IMP_Contents::RENDER_INLINE,
+    'no_inline_all' => !$prefs->getValue('mimp_inline_all'),
+    'sep' => '<br /><hr />'
+));
 
-        $body_shown = true;
-        $msg_text = $info['data'];
-    }
-}
+$msg_text = $inlineout['msgtext'];
 
 /* Display the first 250 characters, or display the entire message? */
 if ($prefs->getValue('mimp_preview_msg') &&
@@ -352,7 +328,7 @@ foreach ($display_headers as $head => $val) {
 $t->set('hdrs', $hdrs);
 
 $atc = array();
-foreach ($atc_parts as $key) {
+foreach ($inlineout['atc_parts'] as $key) {
     $summary = $imp_contents->getSummary($key, IMP_Contents::SUMMARY_BYTES | IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_DESCRIP_NOLINK_NOHTMLSPECCHARS | IMP_Contents::SUMMARY_DOWNLOAD_NOJS);
 
     $tmp = array(
@@ -365,10 +341,14 @@ foreach ($atc_parts as $key) {
         /* Preference: if set, only show download confirmation screen if
          * attachment over a certain size. */
         $tmp['download'] = ($summary['bytes'] > $prefs->getValue('mimp_download_confirm'))
-            ? $self_link->copy()->add(array('a' => 'c', 'atc' => $key))
+            ? $self_link->copy()->add(array('a' => 'pa', 'atc' => $key))
             : $summary['download'];
     }
 
+    if ($imp_contents->canDisplay($key, IMP_Contents::RENDER_INLINE_AUTO)) {
+        $tmp['view'] = $self_link->copy()->add(array('a' => 'pa', 'id' => $key));
+    }
+
     $atc[] = $tmp;
 }
 $t->set('atc', $atc);
@@ -379,4 +359,3 @@ $t->set('title', ($status ? $status . ' | ' : '') . $display_headers['subject']
 require IMP_TEMPLATES . '/common-header.inc';
 IMP::status();
 echo $t->fetch(IMP_TEMPLATES . '/message/message-mimp.html');
-
index 28529eb..e7203bc 100644 (file)
@@ -598,7 +598,11 @@ if ($imp_ui->MDNCheck($imp_mbox['mailbox'], $uid, $mime_headers, $vars->mdn_conf
 
 /* Build body text. This needs to be done before we build the attachment list
  * that lives in the header. */
-$inlineout = $imp_ui->getInlineOutput($imp_contents, $contents_mask, $part_info_display, $show_parts);
+$inlineout = $imp_ui->getInlineOutput($imp_contents, array(
+    'mask' => $contents_mask,
+    'part_info_display' => $part_info_display,
+    'show_parts' => $show_parts
+));
 
 /* Build the Attachments menu. */
 $a_template->set('atc', Horde::widget('#', _("Attachments"), 'widget hasmenu', '', '', _("Attachments"), true));
diff --git a/imp/templates/message/download-mimp.html b/imp/templates/message/download-mimp.html
deleted file mode 100644 (file)
index 0975f1f..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-  <p>
-   <gettext>Click to verify download of attachment</gettext>:
-   <a href="<tag:download />"><tag:descrip /></a>
-   [<tag:type />] <tag:size />
-  </p>
-  <p>
-   <a href="<tag:self_link />"><gettext>Return to message view</gettext></a>
-  </p>
- </body>
-</html>
index cb8453c..fcf1073 100644 (file)
@@ -5,7 +5,15 @@
    <div><em><tag:hdrs.label />:</em> <tag:hdrs.val /><if:hdrs.all_to> [<a href="<tag:hdrs.all_to />"><gettext>Show All</gettext></a>]</if:hdrs.all_to></div>
 </loop:hdrs>
 <loop:atc>
-   <div><em><gettext>Attachment</gettext>:</em> <if:atc.download><a href="<tag:atc.download />"><tag:atc.descrip /></a><else:atc.download><tag:atc.descrip /></else:atc.download></if:atc.download> [<tag:atc.type />] <tag:atc.size /></div>
+   <div>
+    <em><gettext>Attachment</gettext>:</em> <tag:atc.descrip /> (<tag:atc.type />) <tag:atc.size />
+<if:atc.view>
+    [<a href="<tag:atc.view />">View</a>]
+</if:atc.view>
+<if:atc.download>
+    [<a href="<tag:atc.download />">Download</a>]
+</if:atc.download>
+   </div>
 </loop:atc>
   </p>
   <p>
diff --git a/imp/templates/message/part-mimp.html b/imp/templates/message/part-mimp.html
new file mode 100644 (file)
index 0000000..322349b
--- /dev/null
@@ -0,0 +1,15 @@
+<if:view_data>
+  <tag:view_data />
+<else:view_data>
+  <p>
+   <gettext>Download attachment</gettext>:
+   <a href="<tag:download />"><tag:descrip /></a>
+   [<tag:type />] <tag:size />
+  </p>
+</else:view_data></if:view_data>
+  <hr />
+  <p>
+   <a href="<tag:self_link />"><gettext>Return to message view</gettext></a>
+  </p>
+ </body>
+</html>