From f0504c8b3362219d1a6c77af4bb5f89db23a1109 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 25 Nov 2008 22:45:26 -0700 Subject: [PATCH] Improve/Fix MIMP message rendering. --- imp/lib/Contents.php | 2 +- imp/lib/Mime/Viewer/plain.php | 12 ++------ imp/lib/UI/Message.php | 43 +++++++++++++++++++---------- imp/lib/api.php | 6 ---- imp/message-mimp.php | 64 ++++++++++++++++++++++++++++++++----------- 5 files changed, 81 insertions(+), 46 deletions(-) diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index 0d0ca7fd3..3b25db8ec 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -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. */ diff --git a/imp/lib/Mime/Viewer/plain.php b/imp/lib/Mime/Viewer/plain.php index e9c26b431..748f8e457 100644 --- a/imp/lib/Mime/Viewer/plain.php +++ b/imp/lib/Mime/Viewer/plain.php @@ -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); } diff --git a/imp/lib/UI/Message.php b/imp/lib/UI/Message.php index bdcd570ee..6b60ab559 100644 --- a/imp/lib/UI/Message.php +++ b/imp/lib/UI/Message.php @@ -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 .= ' ' . htmlspecialchars(sprintf('[%s %s %s]', $date_str, $time_str, $tz)) . ''; + $local_date = sprintf('[%s %s %s]', $date_str, $time_str, $tz); } else { /* Else, it's today, use the time only. */ - $date .= ' ' . htmlspecialchars(sprintf('[%s %s]', $time_str, $tz)) . ''; + $local_date = sprintf('[%s %s]', $time_str, $tz); } + + $date .= ($_SESSION['imp']['view'] == 'mimp') + ? ' ' . $local_date + : ' ' . htmlspecialchars($local_date) . ''; } 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)) { diff --git a/imp/lib/api.php b/imp/lib/api.php index 51d45f4da..8b68c958b 100644 --- a/imp/lib/api.php +++ b/imp/lib/api.php @@ -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'; diff --git a/imp/message-mimp.php b/imp/message-mimp.php index 625f5a8d2..81595c040 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -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)) { -- 2.11.0