Improve/Fix MIMP message rendering.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 26 Nov 2008 05:45:26 +0000 (22:45 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 26 Nov 2008 05:45:51 +0000 (22:45 -0700)
imp/lib/Contents.php
imp/lib/Mime/Viewer/plain.php
imp/lib/UI/Message.php
imp/lib/api.php
imp/message-mimp.php

index 0d0ca7f..3b25db8 100644 (file)
@@ -548,7 +548,7 @@ class IMP_Contents
                 ? $this->linkViewJS($mime_part, 'view_attach', htmlspecialchars($description), array('jstext' => sprintf(_("View %s [%s]"), $description, $mime_type), 'params' => $param_array))
                 : htmlspecialchars($description);
         } elseif ($mask & self::SUMMARY_DESCRIP_NOLINK) {
-            $part['description'] = htmlspecialchars($description);
+            $part['description'] = $description;
         }
 
         /* Download column. */
index e9c26b4..748f8e4 100644 (file)
@@ -53,11 +53,13 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain
             $text = preg_replace('/(\n+)> ?From(\s+)/', "$1From$2", $text);
         }
 
+        $text = IMP::filterText($text);
+
         /* Done processing if in mimp mode. */
         if ($_SESSION['imp']['view'] == 'mimp') {
             return array(
                 $mime_id => array(
-                    'data' => IMP::filterText($text),
+                    'data' => $text,
                     'status' => array(),
                     'type' => $type
                 )
@@ -98,14 +100,6 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain
             $filters['dimsignature'] = array();
         }
 
-        // Filter bad language.
-        if ($prefs->getValue('filtering')) {
-            $filters['words'] = array(
-                'words_file' => $conf['msgsettings']['filtering']['words'],
-                'replacement' => $conf['msgsettings']['filtering']['replacement']
-            );
-        }
-
         if ($prefs->getValue('emoticons')) {
             $filters['emoticons'] = array('entities' => true);
         }
index bdcd570..6b60ab5 100644 (file)
@@ -111,15 +111,20 @@ class IMP_UI_Message
             $date_str = strftime($GLOBALS['prefs']->getValue('date_format'), $ltime);
             $time_str = strftime($GLOBALS['prefs']->getValue('time_format'), $ltime);
             $tz = strftime('%Z');
+
             if ((date('Y') != @date('Y', $ltime)) ||
                 (date('M') != @date('M', $ltime)) ||
                 (date('d') != @date('d', $ltime))) {
                 /* Not today, use the date. */
-                $date .= ' <small>' . htmlspecialchars(sprintf('[%s %s %s]', $date_str, $time_str, $tz)) . '</small>';
+                $local_date = sprintf('[%s %s %s]', $date_str, $time_str, $tz);
             } else {
                 /* Else, it's today, use the time only. */
-                $date .= ' <small>' . htmlspecialchars(sprintf('[%s %s]', $time_str, $tz)) . '</small>';
+                $local_date = sprintf('[%s %s]', $time_str, $tz);
             }
+
+            $date .= ($_SESSION['imp']['view'] == 'mimp')
+                ? ' ' . $local_date
+                : ' <small>' . htmlspecialchars($local_date) . '</small>';
         }
 
         return $date;
@@ -266,28 +271,26 @@ class IMP_UI_Message
     {
         global $prefs, $registry;
 
-        $add_link = null;
-
         /* Make sure this is a valid object address field. */
         if (empty($addrlist) || !is_array($addrlist)) {
             return null;
         }
 
+        $add_link = null;
+        $addr_array = array();
+        $mimp_view = ($_SESSION['imp']['view'] == 'mimp');
+
         /* Set up the add address icon link if contact manager is
          * available. */
         if (!is_null($addURL) && $link && $prefs->getValue('add_source')) {
             $add_link = $registry->link('contacts/add', array('source' => $prefs->getValue('add_source')));
             if (is_a($add_link, 'PEAR_Error')) {
-                if ($registry->hasMethod('contacts/import')) {
-                    $add_link = Util::addParameter($addURL, 'actionID', 'add_address');
-                } else {
-                    $add_link = null;
-                }
+                $add_link = $registry->hasMethod('contacts/import')
+                    ? Util::addParameter($addURL, 'actionID', 'add_address')
+                    : null;
             }
         }
 
-        $addr_array = array();
-
         foreach (Horde_Mime_Address::getAddressesFromObject($addrlist) as $ob) {
             if (isset($ob['groupname'])) {
                 $group_array = array();
@@ -296,7 +299,9 @@ class IMP_UI_Message
                         continue;
                     }
 
-                    $ret = htmlspecialchars($ad->display);
+                    $ret = $mimp_view
+                        ? $ad->display
+                        : htmlspecialchars($ad->display);
 
                     /* If this is an incomplete e-mail address, don't link to
                      * anything. */
@@ -317,9 +322,15 @@ class IMP_UI_Message
                     $group_array[] = $ret;
                 }
 
-                $addr_array[] = htmlspecialchars($ob['groupname']) . ':' . (count($group_array) ? ' ' . implode(', ', $group_array) : '');
+                if (!$mimp_view) {
+                    $ob['groupname'] = htmlspecialchars($ob['groupname']);
+                }
+
+                $addr_array[] = $ob['groupname'] . ':' . (count($group_array) ? ' ' . implode(', ', $group_array) : '');
             } elseif (!empty($ob['address']) && !empty($ob['inner'])) {
-                $ret = htmlspecialchars($ob['display']);
+                $ret = $mimp_view
+                    ? $ob['display']
+                    : htmlspecialchars($ob['display']);
 
                 /* If this is an incomplete e-mail address, don't link to
                  * anything. */
@@ -341,6 +352,10 @@ class IMP_UI_Message
             }
         }
 
+        if ($_SESSION['imp']['view'] == 'mimp') {
+            return implode(', ', $addr_array);
+        }
+
         /* If left with an empty address list ($ret), inform the user that the
          * recipient list is purposely "undisclosed". */
         if (empty($addr_array)) {
index 51d45f4..8b68c95 100644 (file)
@@ -185,12 +185,6 @@ function _imp_compose($args = array(), $extra = array())
  */
 function _imp_batchCompose($args = array(), $extra = array())
 {
-    // TODO: Fix
-    if (isset($_SESSION['imp']['view']) &&
-        $_SESSION['imp']['view'] != 'imp') {
-        return $GLOBALS['registry']->callByPackage($_SESSION['imp']['view'], 'batchCompose', array($args, $extra));
-    }
-
     $GLOBALS['authentication'] = 'none';
     $GLOBALS['noset_view'] = true;
     require_once dirname(__FILE__) . '/base.php';
index 625f5a8..81595c0 100644 (file)
@@ -180,7 +180,6 @@ case 'low':
 /* Set the status information of the message. */
 $status = '';
 $identity = null;
-$addresses = array();
 if (!$use_pop) {
     if (!empty($msgAddresses)) {
         $identity = $user_identity->getMatchingIdentity($msgAddresses);
@@ -217,17 +216,54 @@ if ($prev_msg) {
 }
 $next_msg = $imp_mailbox->getIMAPIndex(1);
 if ($next_msg) {
-    $next_link = IMP::generateIMPUrl('message.php', $imp_mbox['mailbox'], $next_msg['index'], $next_msg['mailbox']);
+    $next_link = IMP::generateIMPUrl('message-mimp.php', $imp_mbox['mailbox'], $next_msg['index'], $next_msg['mailbox']);
 }
 
 /* Create the body of the message. */
-// TODO
-//$msgText = $mimp_contents->getMessage();
-$msgText = 'TODO';
+$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;
+        }
+
+        $body_shown = true;
+        $msg_text = $info['data'];
+    }
+}
 
 /* Display the first 250 characters, or display the entire message? */
 if ($prefs->getValue('mimp_preview_msg') && !Util::getFormData('fullmsg')) {
-    $msgText = String::substr($msgText, 0, 250) . " [...]\n";
+    $msg_text = String::substr($msg_text, 0, 250) . " [...]\n";
     $fullmsg_link = new Horde_Mobile_link(_("View Full Message"), Util::addParameter($self_link, array('fullmsg' => 1)));
 } else {
     $fullmsg_link = null;
@@ -313,18 +349,14 @@ foreach ($display_headers as $head => $val) {
     $t->set('linebreaks', true);
 }
 
-/* TODO
-foreach (array_keys($this->_atc) as $key) {
-$part = $this->_message->getPart($key);
-if ($part !== false) {
-$hb->add(new Horde_Mobile_text(_("Attachment") . ': ', array('b')));
-$t = &$hb->add(new Horde_Mobile_text(sprintf('%s (%s KB)', $part->getName(true, true), $part->getSize()) . "\n"));
-$t->set('linebreaks', true);
-}
+foreach ($atc_parts as $key) {
+    $summary = $imp_contents->getSummary($key, IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_DESCRIP_NOLINK);
+    $hb->add(new Horde_Mobile_text(_("Attachment") . ': ', array('b')));
+    $t = &$hb->add(new Horde_Mobile_text(sprintf('%s %s', $summary['description'], $summary['size']) . "\n"));
+    $t->set('linebreaks', true);
 }
- */
 
-$t = &$c->add(new Horde_Mobile_text($msgText));
+$t = &$c->add(new Horde_Mobile_text($msg_text));
 $t->set('linebreaks', true);
 
 if (!is_null($fullmsg_link)) {