From: Michael M Slusarz Date: Wed, 10 Nov 2010 23:14:03 +0000 (-0700) Subject: Optimize display of attachment flag icon X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=fccb2396a4ee9e22da1e2feeee766051f242f421;p=horde.git Optimize display of attachment flag icon We only need the Content-Type header of the base part, not the entire structure of the message. --- diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index 1e4d31d7f..d9bb74ccf 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -1263,13 +1263,11 @@ $_prefs['from_link'] = array( ); // Display attachment information in mailbox list. -// Disabled by default, and not shown to user, because this display requires -// substantial overhead to parse the message structures of all message in -// the mailbox list at view time. +// Disabled by default since display requires a bit of extra overhead to +// obtain the MIME Content-Type of the base portion of the message. $_prefs['atc_flag'] = array( 'value' => 0, - // Locked by default - 'locked' => true, + 'advanced' => true, 'type' => 'checkbox', 'desc' => _("Display attachment information about a message in the mailbox listing?") ); diff --git a/imp/lib/Imap/Flags.php b/imp/lib/Imap/Flags.php index 513638d45..2ed8a833c 100644 --- a/imp/lib/Imap/Flags.php +++ b/imp/lib/Imap/Flags.php @@ -259,20 +259,17 @@ class IMP_Imap_Flags * * @param array $options Additional options: *
-     * 'atc' - (Horde_Mime_Part) Attachment info. A Horde_Mime_Part object
-     *         representing the message structure.
-     *         DEFAULT: not parsed
      * 'div' - (boolean) If true, return a DIV tag containing the code
      *         necessary to display the icon.
      *         DEFAULT: false
      * 'flags' - (array) [REQUIRED] IMAP flag info. A lowercase list of flags
      *           returned by the IMAP server.
+     * 'headers' - (Horde_Mime_Headers) Determines attachment and priority
+     *             information from a headers object.
      * 'personal' - (mixed) Personal message info. Either an array of to
      *              addresses as returned by
      *              Horde_Mime_Address::getAddressesFromObject(), or the
      *              identity that matched the address list.
-     * 'priority' - (Horde_Mime_Headers) Determines priority information from
-     *              a headers object.
      * 
* * @return array A list of flags with the following keys: @@ -309,9 +306,9 @@ class IMP_Imap_Flags } } - if (!empty($options['priority'])) { + if (!empty($options['headers'])) { $imp_hdr_ui = new IMP_Ui_Headers(); - switch ($imp_hdr_ui->getPriority($options['priority'])) { + switch ($imp_hdr_ui->getPriority($options['headers'])) { case 'high': $process['highpri'] = $f['highpri']; break; @@ -320,12 +317,12 @@ class IMP_Imap_Flags $process['lowpri'] = $f['lowpri']; break; } - } - if (!empty($options['atc'])) { - $imp_mbox_ui = new IMP_Ui_Mailbox(); - if ($type = $imp_mbox_ui->getAttachmentType($options['atc']->getType())) { - $process[$type] = $f[$type]; + if ($ctype = $options['headers']->getValue('content-type', Horde_Mime_Headers::VALUE_BASE)) { + $imp_mbox_ui = new IMP_Ui_Mailbox(); + if ($type = $imp_mbox_ui->getAttachmentType($ctype)) { + $process[$type] = $f[$type]; + } } } diff --git a/imp/lib/Mailbox/List.php b/imp/lib/Mailbox/List.php index 6570a4d96..bcfd92702 100644 --- a/imp/lib/Mailbox/List.php +++ b/imp/lib/Mailbox/List.php @@ -85,16 +85,16 @@ class IMP_Mailbox_List implements Countable, Serializable * @param array $msgnum An array of message sequence numbers. * @param array $options Additional options: *
-     * 'headers' - (boolean) Return info on the non-envelope headers
-     *             'Importance', 'List-Post', and 'X-Priority'.
-     *             DEFAULT: false (only envelope headers returned)
-     * 'preview' - (mixed) Include preview information?  If empty, add no
-     *                     preview information. If 1, uses value from prefs.
-     *                     If 2, forces addition of preview info.
-     *                     DEFAULT: No preview information.
-     * 'structure' - (boolean) Get structure information from server.
-     *               Contained in the 'structure' entry.
-     *               DEFAULT: false
+     * headers - (boolean) Return info on the non-envelope headers
+     *           'Importance', 'List-Post', and 'X-Priority'.
+     *           DEFAULT: false (only envelope headers returned)
+     * preview - (mixed) Include preview information?  If empty, add no
+     *                   preview information. If 1, uses value from prefs.
+     *                   If 2, forces addition of preview info.
+     *                   DEFAULT: No preview information.
+     * type - (boolean) Return info on the MIME Content-Type of the base
+     *        message part ('Content-Type' header).
+     *        DEFAULT: false
      * 
* * @return array An array with the following keys: @@ -104,17 +104,14 @@ class IMP_Mailbox_List implements Countable, Serializable * server. See Horde_Imap_Client::fetch() for format. * flags - (array) The list of IMAP flags returned from the server. * See Horde_Imap_Client::fetch() for the format. - * headers - (array) Any headers requested in $options['headers']. - * Horde_Mime_Headers objects are returned. See - * Horde_Imap_Client::fetch() for the format. + * headers - (array) Horde_Mime_Headers objects containing header data + * if either $options['headers'] or $options['type'] are + * true. See Horde_Imap_Client::fetch() for the format. * mailbox - (string) The mailbox containing the message. * preview - (string) If requested in $options['preview'], the preview * text. * previewcut - (boolean) Has the preview text been cut? * size - (integer) The size of the message in bytes. - * structure - (array) The structure of the message. Only set if - * $options['structure'] is true. See - * Horde_Imap_Client::fetch() for format. * uid - (string) The unique ID of the message. * uids - (IMP_Indices) An indices object. * @@ -123,7 +120,7 @@ class IMP_Mailbox_List implements Countable, Serializable { $this->_buildMailbox(); - $overview = $to_process = $uids = array(); + $headers = $overview = $to_process = $uids = array(); /* Build the list of mailboxes and messages. */ foreach ($msgnum as $i) { @@ -146,11 +143,25 @@ class IMP_Mailbox_List implements Countable, Serializable ); if (!empty($options['headers'])) { - $fetch_criteria[Horde_Imap_Client::FETCH_HEADERS] = array(array('cache' => true, 'headers' => array('importance', 'list-post', 'x-priority'), 'label' => 'imp', 'parse' => true, 'peek' => true)); + $headers = array_merge($headers, array( + 'importance', + 'list-post', + 'x-priority' + )); } - if (!empty($options['structure'])) { - $fetch_criteria[Horde_Imap_Client::FETCH_STRUCTURE] = array('parse' => true); + if (!empty($options['type'])) { + $headers[] = 'content-type'; + } + + if (!empty($headers)) { + $fetch_criteria[Horde_Imap_Client::FETCH_HEADERS] = array(array( + 'cache' => true, + 'headers' => $headers, + 'label' => 'imp', + 'parse' => true, + 'peek' => true + )); } $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); diff --git a/imp/lib/Ui/Headers.php b/imp/lib/Ui/Headers.php index 31b84b8e6..20c43c66a 100644 --- a/imp/lib/Ui/Headers.php +++ b/imp/lib/Ui/Headers.php @@ -24,13 +24,15 @@ class IMP_Ui_Headers */ public function getPriority($header) { - if (preg_match('/\s*(\d+)\s*/', $header->getValue('x-priority'), $matches)) { + if (($xpriority = $header->getValue('x-priority')) && + (preg_match('/\s*(\d+)\s*/', $xpriority, $matches))) { if (in_array($matches[1], array(1, 2))) { return 'high'; } elseif (in_array($matches[1], array(4, 5))) { return 'low'; } - } elseif (preg_match('/:\s*(\w+)\s*/', $header->getValue('importance'), $matches)) { + } elseif (($importance = $header->getValue('importance')) && + preg_match('/:\s*(\w+)\s*/', $importance, $matches)) { if (strcasecmp($matches[1], 'high') === 0) { return 'high'; } elseif (strcasecmp($matches[1], 'low') === 0) { diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index 8d1659389..c18d2a0e6 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -399,7 +399,10 @@ class IMP_Views_ListMessages } /* Get mailbox information. */ - $overview = $imp_mailbox->getMailboxArray($msglist, array('headers' => true, 'structure' => $GLOBALS['prefs']->getValue('atc_flag'))); + $overview = $imp_mailbox->getMailboxArray($msglist, array( + 'headers' => true, + 'type' => $GLOBALS['prefs']->getValue('atc_flag') + )); $charset = 'UTF-8'; $imp_ui = new IMP_Ui_Mailbox($folder); $no_flags_hook = false; @@ -423,10 +426,9 @@ class IMP_Views_ListMessages } $flag_parse = $GLOBALS['injector']->getInstance('IMP_Imap_Flags')->parse(array( - 'atc' => isset($ob['structure']) ? $ob['structure'] : null, 'flags' => $ob['flags'], - 'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to'], array('charset' => $charset)), - 'priority' => $ob['headers'] + 'headers' => $ob['headers'], + 'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to'], array('charset' => $charset)) )); if (!empty($flag_parse)) { diff --git a/imp/mailbox.php b/imp/mailbox.php index 65d092cd4..1613d7aa3 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -231,7 +231,11 @@ $imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->creat $pageOb = $imp_mailbox->buildMailboxPage($vars->page, $start); $show_preview = $prefs->getValue('preview_enabled'); -$mbox_info = $imp_mailbox->getMailboxArray(range($pageOb['begin'], $pageOb['end']), array('preview' => $show_preview, 'headers' => true, 'structure' => $prefs->getValue('atc_flag'))); +$mbox_info = $imp_mailbox->getMailboxArray(range($pageOb['begin'], $pageOb['end']), array( + 'headers' => true, + 'preview' => $show_preview, + 'type' => $prefs->getValue('atc_flag') +)); /* Determine sorting preferences. */ $sortpref = IMP::getSort(IMP::$mailbox); @@ -743,11 +747,10 @@ while (list(,$ob) = each($mbox_info['overview'])) { } catch (Horde_Exception_HookNotSet $e) {} $flag_parse = $imp_flags->parse(array( - 'atc' => isset($ob['structure']) ? $ob['structure'] : null, 'div' => true, 'flags' => $ob['flags'], - 'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to'], array('charset' => 'UTF-8')), - 'priority' => $ob['headers'] + 'headers' => $ob['headers'], + 'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to'], array('charset' => 'UTF-8')) )); $subject_flags = array();