From 1ab28217cb086bd04c53c45e400c10198dfc6961 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 15 Dec 2008 20:14:17 -0700 Subject: [PATCH] Fix Bug #7780 - msglist_format hook. --- imp/config/hooks.php.dist | 109 +++++++++++++++++++---------------------- imp/lib/IMAP.php | 3 +- imp/lib/Views/ListMessages.php | 25 +++++++--- imp/mailbox.php | 55 ++++++++++----------- 4 files changed, 95 insertions(+), 97 deletions(-) diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index 708e1b398..fe3524355 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -181,15 +181,12 @@ // display of the message entry based on the X-Priority header. // // INPUT: -// $uids - (array) A list of UIDs/mailboxes. Mailboxes are the keys; values -// are the list of UIDs in the mailbox. -// $mbox - (string) The current mailbox string (may be a search mailbox -// string). +// $mbox - (string) The mailbox. +// $uids - (array) A list of UIDs. // $mode - (string) Either 'imp' or 'dimp'. // // OUTPUT: -// An array with Mailboxes as the keys, and an array of arrays as the value. -// Each array consists of the UID (key) and the following array values: +// An array of arrays, with UIDs as keys and the following array values: // // For IMP: // 'class' - (array) CSS classnames that will be added to the row. @@ -204,65 +201,63 @@ // 'class' - (array) CSS classnames that will be added to the row. // if (!function_exists('_imp_hook_msglist_format')) { -// function _imp_hook_msglist_format($uids, $mbox, $mode) +// function _imp_hook_msglist_format($mbox, $uids, $mode) // { -// $ret = array(); +// try { +// $imap_res = $GLOBALS['imp_imap']->ob->fetch($mbox, array( +// Horde_Imap_Client::FETCH_HEADERS => array(array('headers' => array('x-priority'), 'label' => 'hdr_search', 'parse' => true, 'peek' => true)), +// Horde_Imap_Client::FETCH_STRUCTURE => array('parse' => true) +// ), array('ids' => array_values($uids))); +// } catch (Horde_Imap_Client_Exception $e) { +// return array(); +// } // // $alt_list = IMP_UI_Mailbox::getAttachmentAltList(); // $imp_ui = new IMP_UI_Mailbox($mbox); -// $imp_msg_ui = new IMP_UI_Messsage(); -// -// foreach ($uids as $mailbox => $uid_list) { -// try { -// $imap_res = $GLOBALS['imp_imap']->ob->fetch($mailbox, array( -// Horde_Imap_Client::FETCH_HEADERS => array('headers' => array('x-priority'), 'label' => 'hdr_search', 'parse' => true, 'peek' => false), -// Horde_Imap_Client::FETCH_STRUCTURE => array('parse' => true) -// ), array('ids' => array_values($uid_list))); -// } catch (Horde_Imap_Client_Exception $e) { -// continue; -// } -// -// $ret[$mailbox] = array(); -// -// foreach ($uid_list as $uid) { -// $ret[$mailbox][$uid] = array(); -// $ptr = &$ret[$mailbox][$uid]; -// $res_ptr = &$imap_res[$uid]; -// -// // Add attachment information -// if (($attachment = $imp_ui->getAttachmentType($res_ptr['structure']->getType()))) { -// switch ($mode) { -// case 'imp': -// $alt_text = (isset($list[$attachment])) -// ? $list[$attachment] -// : $list['attachment']; -// $ptr['status'] = Horde::img($attachment . '.png', $alt_text, array('title' => $alt_text)); -// break; -// -// case 'dimp': -// $ptr['atc'] = $attachment; -// break; -// } -// } +// $imp_msg_ui = new IMP_UI_Message(); +// $ret = array(); // -// // Add X-Priority information -// switch ($imp_msg_ui->getXpriority($res_ptr['headers']['hdr_search']->getValue('x-priority'))) { -// case 'high': -// if ($mode == 'imp') { -// $ptr['flagbits'] = IMP::FLAG_FLAGGED; -// $ptr['status'] .= Horde::img('mail_priority_high.png', _("High Priority"), array('title' => _("High Priority"))); -// } -// $ptr['class'][] = 'important'; +// foreach ($uids as $uid) { +// $tmp = array(); +// $res_ptr = &$imap_res[$uid]; +// +// // Add attachment information +// if (($attachment = $imp_ui->getAttachmentType($res_ptr['structure']->getType()))) { +// switch ($mode) { +// case 'imp': +// $alt_text = (isset($list[$attachment])) +// ? $list[$attachment] +// : $list['attachment']; +// $tmp['status'] = Horde::img($attachment . '.png', $alt_text, array('title' => $alt_text)); // break; // -// case 'low': -// if ($mode == 'imp') { -// $ptr['status'] .= Horde::img('mail_priority_low.png', _("Low Priority"), array('title' => _("Low Priority"))); -// } -// $ptr['class'][] = 'unimportant'; +// case 'dimp': +// $tmp['atc'] = $attachment; // break; // } // } +// +// // Add X-Priority information +// switch ($imp_msg_ui->getXpriority($res_ptr['headers']['hdr_search']->getValue('x-priority'))) { +// case 'high': +// if ($mode == 'imp') { +// $tmp['flagbits'] = IMP::FLAG_FLAGGED; +// $tmp['status'] .= Horde::img('mail_priority_high.png', _("High Priority"), array('title' => _("High Priority"))); +// } +// $tmp['class'][] = 'important'; +// break; +// +// case 'low': +// if ($mode == 'imp') { +// $tmp['status'] .= Horde::img('mail_priority_low.png', _("Low Priority"), array('title' => _("Low Priority"))); +// } +// $tmp['class'][] = 'unimportant'; +// break; +// } +// +// if (!empty($tmp)) { +// $ret[$uid] = $tmp; +// } // } // // return $ret; @@ -325,7 +320,6 @@ // $box = preg_replace("/^{[^}]+}/", "", $box); // if ((strpos($box, "INBOX/Calendar") !== false) || // preg_match("!^user/[^/]+/Calendar!", $box)) { -// // Use this example for IMP 4.2.x+. // $newmailboxes[$box] = array( // 'icon' => 'kronolith.png', // 'icondir' => $GLOBALS['registry']->getImageDir('kronolith') @@ -333,7 +327,6 @@ // ); // } elseif ((strpos($box, "INBOX/Tasks") !== false) || // preg_match("!^user/[^/]+/Tasks!", $box)) { -// // Use this example for IMP 4.2.x+. // $newmailboxes[$box] = array( // 'icon' => 'nag.png', // 'icondir' => $GLOBALS['registry']->getImageDir('nag') @@ -341,7 +334,6 @@ // ); // } elseif ((strpos($box, "INBOX/Notes") !== false) || // preg_match("!^user/[^/]+/Notes!", $box)) { -// // Use this example for IMP 4.2.x+. // $newmailboxes[$box] = array( // 'icon' => 'mnemo.png', // 'icondir' => $GLOBALS['registry']->getImageDir('mnemo') @@ -349,7 +341,6 @@ // ); // } elseif ((strpos($box, "INBOX/Contacts") !== false) || // preg_match("!^user/[^/]+/Contacts!", $box)) { -// // Use this example for IMP 4.2.x+. // $newmailboxes[$box] = array( // 'icon' => 'turba.png', // 'icondir' => $GLOBALS['registry']->getImageDir('turba') diff --git a/imp/lib/IMAP.php b/imp/lib/IMAP.php index fe061dc15..1f1f341c4 100644 --- a/imp/lib/IMAP.php +++ b/imp/lib/IMAP.php @@ -242,8 +242,7 @@ class IMP_IMAP */ public function logException($e) { - // TODO - Clean this up a bit. - Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); + Horde::logMessage($e, $e->getFile(), $e->getLine(), PEAR_LOG_ERR); } /** diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index 583074691..00c1faccd 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -271,7 +271,7 @@ class IMP_Views_ListMessages */ private function _getOverviewData($imp_mailbox, $folder, $msglist, $search) { - $msgs = array(); + $lookup = $msgs = array(); if (empty($msglist)) { return $msgs; @@ -347,15 +347,24 @@ class IMP_Views_ListMessages } else { $msgs[$ob['uid']] = $msg; } + + if (!isset($lookup[$ob['mailbox']])) { + $lookup[$ob['mailbox']] = array(); + } + $lookup[$ob['mailbox']][] = $ob['uid']; } /* Add user supplied information from hook. */ - if (!empty($GLOBALS['conf']['dimp']['hooks']['msglist_format'])) { - $ob_f = Horde::callHook('_imp_hook_msglist_format', array($ob['mailbox'], $ob['uid']), 'dimp'); - - foreach ($ob_f as $mbox => $uids) { - foreach ($uids as $uid => $val) { - $ptr =& $search ? ($uid . $mbox) : $uid; + if (!empty($GLOBALS['conf']['imp']['hooks']['msglist_format'])) { + foreach (array_keys($lookup) as $mbox) { + $ob_f = Horde::callHook('_imp_hook_msglist_format', array($mbox, $lookup[$mbox], 'dimp'), 'imp'); + + foreach ($ob_f as $uid => $val) { + if ($search) { + $ptr = &$msgs[$uid . $mbox]; + } else { + $ptr = &$msgs[$uid]; + } if (!empty($val['atc'])) { $ptr['atc'] = $val['atc']; @@ -369,7 +378,7 @@ class IMP_Views_ListMessages } /* Allow user to alter template array. */ - if (!empty($GLOBALS['conf']['dimp']['hooks']['mailboxarray'])) { + if (!empty($GLOBALS['conf']['imp']['dimp']['hooks']['mailboxarray'])) { $msgs = Horde::callHook('_imp_hook_dimp_mailboxarray', array($msgs), 'imp'); } diff --git a/imp/mailbox.php b/imp/mailbox.php index 239e516a1..8ef6b2a70 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -9,12 +9,33 @@ * * @package IMP * @author Chuck Hagenbuch + * @author Michael Slusarz */ -function _outputSummaries($msgs) +function _outputSummaries($msgs, $mbox, &$ids) { static $template; + if (!empty($GLOBALS['conf']['hooks']['msglist_format'])) { + $ob_f = Horde::callHook('_imp_hook_msglist_format', array($mbox, array_keys($msgs), 'imp'), 'imp'); + + foreach ($ob_f as $uid => $val) { + $ptr = &$msgs[$uid]; + + if (!empty($val['class'])) { + $ptr['bg'] = array_merge($ptr['bg'], $val['class']); + } + + if (!empty($val['flagbits'])) { + $ids[$ptr['id']] |= $val['flagbits']; + } + + if (!empty($val['status'])) { + $ptr['status'] .= $val['status']; + } + } + } + if (!isset($template)) { $template = new IMP_Template(); $template->setOption('gettext', true); @@ -685,7 +706,7 @@ while (list($seq, $ob) = each($mbox_info['overview'])) { if ($search_mbox) { if (empty($lastMbox) || ($ob['mailbox'] != $lastMbox)) { if (!empty($lastMbox)) { - _outputSummaries($msgs); + _outputSummaries($msgs, $lastMbox, $ids); $msgs = array(); } $folder_link = Horde::url(Util::addParameter('mailbox.php', 'mailbox', $ob['mailbox'])); @@ -703,9 +724,10 @@ while (list($seq, $ob) = each($mbox_info['overview'])) { $mh_template->set('mh_count', $mh_count++); echo $mh_template->fetch(IMP_TEMPLATES . '/mailbox/message_headers.html'); } - $lastMbox = $ob['mailbox']; } + $lastMbox = $ob['mailbox']; + /* Initialize the header fields. */ $msg = array( 'bg' => '', @@ -831,33 +853,10 @@ while (list($seq, $ob) = each($mbox_info['overview'])) { } } - $msgs[$ob['uid'] . $ob['mailbox']] = $msg; -} - -/* Add user supplied information from hook. */ -if (!empty($conf['hooks']['msglist_format'])) { - $ob_f = Horde::callHook('_imp_hook_msglist_format', array($mbox_info['uids'], $imp_mbox['mailbox'], 'imp'), 'imp'); - - foreach ($ob_f as $mbox => $uids) { - foreach ($uids as $uid => $val) { - $ptr = &$msgs[$uid . $mbox]; - - if (!empty($val['class'])) { - $ptr['bg'] = array_merge($ptr['bg'], $val['class']); - } - - if (!empty($val['flagbits'])) { - $ids[$ptr['id']] |= $val['flagbits']; - } - - if (!empty($val['status'])) { - $ptr['status'] .= $val['status']; - } - } - } + $msgs[$ob['uid']] = $msg; } -_outputSummaries($msgs); +_outputSummaries($msgs, $lastMbox, $ids); /* Prepare the message footers template. */ $mf_template = new IMP_Template(); -- 2.11.0