Minor cleanups
[squirrelmail.git] / functions / mailbox_display.php
index 9da586e6a0eb31390862161c3af4c564814c1d60..08a513130b575747409682f59df4bd28e5bb6817 100644 (file)
@@ -1,17 +1,17 @@
 <?php
 
 /**
-* mailbox_display.php
-*
-* Copyright (c) 1999-2004 The SquirrelMail Project Team
-* Licensed under the GNU GPL. For full terms see the file COPYING.
-*
-* This contains functions that display mailbox information, such as the
-* table row that has sender, date, subject, etc...
-*
-* @version $Id$
-* @package squirrelmail
-*/
+ * mailbox_display.php
+ *
+ * Copyright (c) 1999-2004 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This contains functions that display mailbox information, such as the
+ * table row that has sender, date, subject, etc...
+ *
+ * @version $Id$
+ * @package squirrelmail
+ */
 
 /** The standard includes.. */
 require_once(SM_PATH . 'functions/strings.php');
@@ -24,18 +24,18 @@ require_once(SM_PATH . 'functions/mime.php');
 require_once(SM_PATH . 'functions/forms.php');
 
 /**
-* default value for page_selector_max
-*/
+ * default value for page_selector_max
+ */
 define('PG_SEL_MAX', 10);
 
 /**
-* The number of pages to cache msg headers
-*/
+ * The number of pages to cache msg headers
+ */
 define('SQM_MAX_PAGES_IN_CACHE',5);
 
 /**
-* Sort constants used for sorting of messages
-*/
+ * Sort constants used for sorting of messages
+ */
 define('SQSORT_NONE',0);
 define('SQSORT_DATE_ASC',1);
 define('SQSORT_DATE_DEC',2);
@@ -63,8 +63,8 @@ define('SQM_MAX_MBX_IN_CACHE',3);
 // define('MBX_PREF_FUTURE',unique integer key);
 
 /**
-* @param mixed $start UNDOCUMENTED
-*/
+ * @param mixed $start UNDOCUMENTED
+ */
 function elapsed($start) {
 
     $end = microtime();
@@ -80,11 +80,11 @@ function elapsed($start) {
 }
 
 /**
-* Displays message header row in messages list
-*
-* @param  array $aMsg contains all message related parameters
-* @return void
-*/
+ * Displays message header row in messages list
+ *
+ * @param  array $aMsg contains all message related parameters
+ * @return void
+ */
 
 function printMessageInfo($aMsg) {
     // FIX ME, remove these globals as well by adding an array as argument for the user settings
@@ -197,8 +197,8 @@ function printMessageInfo($aMsg) {
     }
     // If Sent, prefix with To: but only if not Sent folder
     if ($bHandleAsSent ^ $bSentFolder) {
-        $senderName = _("To:") . ' ' . $senderName;
-        $senderAddress = _("To:") . ' ' . $senderAddress;
+        $senderName = _("To") . ': ' . $senderName;
+        $senderAddress = _("To") . ': ' . $senderAddress;
     }
 
     // this is a column property which can apply to multiple columns. Do not use vars for one column
@@ -300,7 +300,7 @@ function printMessageInfo($aMsg) {
     $sSubject = str_replace('&nbsp;', ' ', decodeHeader($sSubject));
     $subject = processSubject($sSubject, $iIndent);
 
-    echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
+    echo html_tag( 'tr','','','','valign="top"') . "\n";
 
     if (sizeof($index_order)) {
         foreach ($index_order as $index_order_part) {
@@ -710,12 +710,12 @@ function sqm_api_mailbox_select($imapConnection,$mailbox,$aConfig,$aProps) {
 
 
 /**
-* Does the $srt $_GET var to field mapping
-*
-* @param int $srt Field to sort on
-* @param bool $bServerSort Server sorting is true
-* @return string $sSortField Field to sort on
-*/
+ * Does the $srt $_GET var to field mapping
+ *
+ * @param int $srt Field to sort on
+ * @param bool $bServerSort Server sorting is true
+ * @return string $sSortField Field to sort on
+ */
 function getSortField($sort,$bServerSort) {
     switch($sort) {
         case SQSORT_NONE:
@@ -770,9 +770,9 @@ function get_sorted_msgs_list($imapConnection,&$aMailbox,&$error) {
         $aRes = get_thread_sort($imapConnection,$aMailbox['SEARCH'][$iSetIndx]);
         if ($aRes === false) {
             $error = '<b><small><center><font color=red>' .
-                    _("Thread sorting is not supported by your IMAP server.") . '<br />' .
-                    _("Please report this to the system administrator.").
-                    '</center></small></b>';
+                _("Thread sorting is not supported by your IMAP server.") . '<br />' .
+                _("Please contact your system administrator and report this error.") .
+                '</center></small></b>';
             $aMailbox['SORT'] -= SQSORT_THREAD;
         } else {
             $aMailbox['UIDSET'][$iSetIndx] = $aRes[0];
@@ -784,8 +784,8 @@ function get_sorted_msgs_list($imapConnection,&$aMailbox,&$error) {
         $id = sqimap_get_sort_order($imapConnection, $sSortField, $bDirection, $aMailbox['SEARCH'][$iSetIndx]);
         if ($id === false) {
             $error =  '<b><small><center><font color=red>' .
-                _( "Server-side sorting is not supported by your IMAP server.") . '<br />' .
-                _("Please report this to the system administrator.").
+                _("Server-side sorting is not supported by your IMAP server.") . '<br />' .
+                _("Please contact your system administrator and report this error.") .
                 '</center></small></b>';
         } else {
             $aMailbox['UIDSET'][$iSetIndx] = $id;
@@ -932,10 +932,10 @@ function fetchMessageHeaders($imapConnection, &$aMailbox) {
             }
 
             /**
-            * retrieve messages by sequence id's and fetch the UID to retrieve
-            * the UID. for sorted lists this is not needed because a UID FETCH
-            * automaticly add the UID value in fetch results
-            **/
+             * retrieve messages by sequence id's and fetch the UID to retrieve
+             * the UID. for sorted lists this is not needed because a UID FETCH
+             * automaticly add the UID value in fetch results
+             **/
             $aFetchItems[] = 'UID';
 
             //create id range
@@ -999,12 +999,12 @@ function fetchMessageHeaders($imapConnection, &$aMailbox) {
 }
 
 /**
-* This function loops through a group of messages in the mailbox
-* and shows them to the user.
-*
-* @param mixed $imapConnection
-* @param array $aMailbox associative array with mailbox related vars
-*/
+ * This function loops through a group of messages in the mailbox
+ * and shows them to the user.
+ *
+ * @param mixed $imapConnection
+ * @param array $aMailbox associative array with mailbox related vars
+ */
 function showMessagesForMailbox($imapConnection, &$aMailbox) {
     global $color;
 
@@ -1063,15 +1063,15 @@ function showMessagesForMailbox($imapConnection, &$aMailbox) {
 }
 
 /**
-* Function to map an uid list with a msg header array by uid
-* The mapped headers are printed with printMessage
-* aMailbox parameters contains info about the page we are on, the
-* used search criteria, the number of messages to show
-*
-* @param resource $imapConnection socket handle to imap
-* @param array    $aMailbox array with required elements MSG_HEADERS, UIDSET, OFFSET, LIMIT
-* @return void
-**/
+ * Function to map an uid list with a msg header array by uid
+ * The mapped headers are printed with printMessage
+ * aMailbox parameters contains info about the page we are on, the
+ * used search criteria, the number of messages to show
+ *
+ * @param resource $imapConnection socket handle to imap
+ * @param array    $aMailbox array with required elements MSG_HEADERS, UIDSET, OFFSET, LIMIT
+ * @return void
+ **/
 function displayMessageArray($imapConnection, $aMailbox) {
     $iSetIndx    = $aMailbox['SETINDEX'];
     $aId         = $aMailbox['UIDSET'][$iSetIndx];
@@ -1123,22 +1123,22 @@ function displayMessageArray($imapConnection, $aMailbox) {
 }
 
 /**
-* Displays the standard message list header.
-*
-* To finish the table, you need to do a "</table></table>";
-*
-* @param resource $imapConnection
-* @param array    $aMailbox associative array with mailbox related information
-* @param string   $msg_cnt_str
-* @param string   $paginator Paginator string
-*/
+ * Displays the standard message list header.
+ *
+ * To finish the table, you need to do a "</table></table>";
+ *
+ * @param resource $imapConnection
+ * @param array    $aMailbox associative array with mailbox related information
+ * @param string   $msg_cnt_str
+ * @param string   $paginator Paginator string
+ */
 function mail_message_listing_beginning ($imapConnection,
                                          $aMailbox,
                                          $msg_cnt_str = '',
                                          $paginator = '&nbsp;'
                                         ) {
     global $color, $show_flag_buttons, $PHP_SELF;
-    global $lastTargetMailbox;
+    global $lastTargetMailbox, $boxes;
 
     $php_self = $PHP_SELF;
 
@@ -1185,16 +1185,39 @@ function mail_message_listing_beginning ($imapConnection,
     echo '<form name="' . $form_name . '" method="post" action="'.$php_self.'">' ."\n"
         . $moveFields;
 
-
+    $button_str = '';
+    // display flag buttons only if supported
+    if ($show_flag_buttons  &&
+        in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true) ) {
+        $button_str .= getButton('submit', 'markUnflagged', _("Unflag"));
+        $button_str .= getButton('submit', 'markFlagged',   _("Flag"));
+        $button_str .= "&nbsp;\n";
+    }
+    if (in_array('\\seen',$aMailbox['PERMANENTFLAGS'], true)) {
+        $button_str .= getButton('submit', 'markUnread', _("Unread"));
+        $button_str .= getButton('submit', 'markRead',   _("Read"));
+        $button_str .= "&nbsp;\n";
+    }
+    $button_str .= getButton('submit', 'attache',_("Forward")) .
+                   "&nbsp;\n";
+    if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) {
+        $button_str .= getButton('submit', 'delete',_("Delete"));
+        $button_str .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
+        $button_str .= "&nbsp;\n";
+    }
+    if (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY') {
+        $button_str .= getButton('submit', 'expungeButton',_("Expunge"))  .'&nbsp;' . _("mailbox") . "\n";
+        $button_str .= '&nbsp;';
+    }
 ?>
     <table width="100%" cellpadding="1"  cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>">
         <tr>
         <td>
             <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1"  cellspacing="0">
             <tr>
-                <td align="left"><small><?php echo $paginator . $thread_link_str; ?></small></td>
-                <td align="center"></td>
-                <td align="right"><small><?php echo $msg_cnt_str; ?></small></td>
+                <?php echo html_tag('td', '<small>' . $paginator . $thread_link_str . '</small>', 'left') . "\n"; ?>
+                <?php echo html_tag('td', '', 'center') . "\n"; ?>
+                <?php echo html_tag('td', '<small>' . $msg_cnt_str . '</small>', 'right') . "\n"; ?>
             </tr>
             </table>
         </td>
@@ -1203,45 +1226,23 @@ function mail_message_listing_beginning ($imapConnection,
         <td>
             <table border="0" width="100%" cellpadding="1"  cellspacing="0">
             <tr>
-                <td align="left">
-                <small><?php
-
-                    // display flag buttons only if supported
-                    if ($show_flag_buttons  &&
-                    in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true) ) {
-                        echo getButton('SUBMIT', 'markUnflagged',_("Unflag"));
-                        echo getButton('SUBMIT', 'markFlagged',_("Flag"));
-                        echo '&nbsp;';
-                    }
-                    if (in_array('\\seen',$aMailbox['PERMANENTFLAGS'], true)) {
-                        echo getButton('SUBMIT', 'markUnread',_("Unread"));
-                        echo getButton('SUBMIT', 'markRead',_("Read"));
-                        echo '&nbsp;';
-                    }
-
-                    echo getButton('SUBMIT', 'attache',_("Forward"));
-                    echo '&nbsp;';
-                    if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) {
-                        echo getButton('SUBMIT', 'delete',_("Delete"));
-                        echo '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
-                        echo '&nbsp;';
-                    }
-                    if (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY') {
-                    echo getButton('SUBMIT', 'expungeButton',_("Expunge"))  .'&nbsp;' . _("mailbox") . "\n";
-                    echo '&nbsp;';
-                    }
-                    do_hook('mailbox_display_buttons');
-                ?></small>
+                <?php echo html_tag('td', '', 'left') . "\n"; ?>
+                <small>
+                    <?php echo $button_str; ?>
+                    <?php do_hook('mailbox_display_buttons'); ?>
+                </small>
                 </td>
                 <?php
                 if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) {
-                    echo '<td align="right">
-                <small>';
-                    echo  '         <small>&nbsp;<tt><select name="targetMailbox">';
-                    echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
-                    echo '         </select></tt>&nbsp;';
-                    echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n
-                </small>";
+                ?>
+                <?php echo html_tag('td', '', 'right'); ?>
+                    <small>&nbsp;<tt>
+                        <select name="targetMailbox">
+                            <?php echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes); ?>
+                        </select></tt>&nbsp;
+                        <?php echo getButton('submit', 'moveButton',_("Move")); ?>
+                    </small>
+                <?php
                 }
                 ?>
                 </td>
@@ -1250,19 +1251,18 @@ function mail_message_listing_beginning ($imapConnection,
         </td>
         </tr>
     </table>
-
 <?php
     do_hook('mailbox_form_before');
 }
 
 /**
-* Function to add the last row in a message list, it contains the paginator and info about
-* the number of messages.
-*
-* @param integer $num_msgs number of messages in a mailbox
-* @param string  $paginator_str Paginator string  [Prev | Next]  [ 1 2 3 ... 91 92 94 ]  [Show all]
-* @param string  $msg_cnt_str   Message count string Viewing Messages: 21 to 1861 (20 total)
-*/
+ * Function to add the last row in a message list, it contains the paginator and info about
+ * the number of messages.
+ *
+ * @param integer $num_msgs number of messages in a mailbox
+ * @param string  $paginator_str Paginator string  [Prev | Next]  [ 1 2 3 ... 91 92 94 ]  [Show all]
+ * @param string  $msg_cnt_str   Message count string Viewing Messages: 21 to 1861 (20 total)
+ */
 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str) {
 global $color;
 if ($num_msgs) {
@@ -1276,8 +1276,8 @@ if ($num_msgs) {
         <td>
             <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1"  cellspacing="0">
             <tr>
-                <td align="left"><small><?php echo $paginator_str; ?></small></td>
-                <td align="right"><small><?php echo $msg_cnt_str; ?></small></td>
+                    <?php echo html_tag('td', '<small>' . $paginator_str . '</small>', 'left');  ?>
+                    <?php echo html_tag('td', '<small>' . $msg_cnt_str   . '</small>', 'right'); ?>
             </tr>
             </table>
         </td>
@@ -1294,10 +1294,10 @@ if ($num_msgs) {
 }
 
 /**
-* Prints the table header for the messages list view
-*
-* @param array $aMailbox
-*/
+ * Prints the table header for the messages list view
+ *
+ * @param array $aMailbox
+ */
 function printHeader($aMailbox) {
     global $index_order, $internal_date_sort, $color;
 
@@ -1310,7 +1310,7 @@ function printHeader($aMailbox) {
     echo html_tag( 'tr' ,'' , 'center', $color[5] );
 
     /* calculate the width of the subject column based on the
-    * widths of the other columns */
+     * widths of the other columns */
     $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
     $subjectwidth = 100;
     foreach($index_order as $item) {
@@ -1376,12 +1376,12 @@ function printHeader($aMailbox) {
 
 
 /**
-* This function shows the sort button. Isn't this a good comment?
-*
-* @param array $aMailbox
-* @param integer $Down
-* @param integer $Up
-*/
+ * This function shows the sort button. Isn't this a good comment?
+ *
+ * @param array $aMailbox
+ * @param integer $Down
+ * @param integer $Up
+ */
 function ShowSortButton($aMailbox, $Down, $Up ) {
     global $PHP_SELF;
 
@@ -1412,10 +1412,10 @@ function ShowSortButton($aMailbox, $Down, $Up ) {
 }
 
 /**
-* FIXME: Undocumented function
-*
-* @param array $aMailbox
-*/
+ * FIXME: Undocumented function
+ *
+ * @param array $aMailbox
+ */
 function get_selectall_link($aMailbox) {
     global $checkall, $javascript_on;
     global $PHP_SELF;
@@ -1469,13 +1469,13 @@ function get_selectall_link($aMailbox) {
 }
 
 /**
-* This function computes the "Viewing Messages..." string.
-*
-* @param integer $start_msg first message number
-* @param integer $end_msg last message number
-* @param integer $num_msgs total number of message in folder
-* @return string
-*/
+ * This function computes the "Viewing Messages..." string.
+ *
+ * @param integer $start_msg first message number
+ * @param integer $end_msg last message number
+ * @param integer $num_msgs total number of message in folder
+ * @return string
+ */
 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
     /* Compute the $msg_cnt_str. */
     $result = '';
@@ -1483,7 +1483,7 @@ function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
         $result = sprintf(_("Viewing Messages: %s to %s (%s total)"),
                         '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs);
     } else if ($start_msg == $end_msg) {
-        $result = sprintf(_("Viewing Message: %s (1 total)"), '<b>'.$start_msg.'</b>');
+        $result = sprintf(_("Viewing Message: %s (%s total)"), '<b>'.$start_msg.'</b>', $num_msgs);
     } else {
         $result = '<br />';
     }
@@ -1492,14 +1492,14 @@ function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
 }
 
 /**
-* Generate a paginator link.
-*
-* @param mixed $box Mailbox name
-* @param mixed $start_msg Message Offset
-* @param mixed $use
-* @param string $text text used for paginator link
-* @return string
-*/
+ * Generate a paginator link.
+ *
+ * @param mixed $box Mailbox name
+ * @param mixed $start_msg Message Offset
+ * @param mixed $use
+ * @param string $text text used for paginator link
+ * @return string
+ */
 function get_paginator_link($box, $start_msg, $text) {
     sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER);
     $result = "<a href=\"$php_self?startMessage=$start_msg&amp;mailbox=$box\" "
@@ -1509,20 +1509,17 @@ function get_paginator_link($box, $start_msg, $text) {
 }
 
 /**
-* This function computes the paginator string.
-*
-* @param string $box
-* @param integer $start_msg
-* @param integer $end_msg
-* @param integer $num_msgs // total number of messages
-* @param integer $limit // number of messages to show on one page
-* @param integer $sort
-*/
-//function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
-//                        $show_num, $sort) {
+ * This function computes the paginator string.
+ *
+ * @param string  $box      mailbox name
+ * @param integer $iOffset  offset in total number of messages
+ * @param integer $iTotal   total number of messages
+ * @param integer $iLimit   maximum number of messages to show on a page
+ * @param bool    $bShowAll show all messages at once (non paginate mode)
+ * @return string $result   paginate string with links to pages
+ */
 function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) {
-
-    global $username, $data_dir, $color;
+    global $username, $data_dir;
     sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER);
 
     /* Initialize paginator string chunks. */
@@ -1683,9 +1680,9 @@ function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) {
 
     /* Put all the pieces of the paginator string together. */
     /**
-    * Hairy code... But let's leave it like it is since I am not certain
-    * a different approach would be any easier to read. ;)
-    */
+     * Hairy code... But let's leave it like it is since I am not certain
+     * a different approach would be any easier to read. ;)
+     */
     $result = '';
     if ( $prv_str || $nxt_str ) {
 
@@ -1713,8 +1710,8 @@ function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) {
 }
 
 /**
-* FIXME: Undocumented function
-*/
+ * FIXME: Undocumented function
+ */
 function truncateWithEntities($subject, $trim_at)
 {
     $ent_strlen = strlen($subject);
@@ -1724,11 +1721,11 @@ function truncateWithEntities($subject, $trim_at)
     global $languages, $squirrelmail_language;
 
     /*
-    * see if this is entities-encoded string
-    * If so, Iterate through the whole string, find out
-    * the real number of characters, and if more
-    * than $trim_at, substr with an updated trim value.
-    */
+     * see if this is entities-encoded string
+     * If so, Iterate through the whole string, find out
+     * the real number of characters, and if more
+     * than $trim_at, substr with an updated trim value.
+     */
     $trim_val = $trim_at;
     $ent_offset = 0;
     $ent_loc = 0;
@@ -1748,16 +1745,16 @@ function truncateWithEntities($subject, $trim_at)
         return $subject;
 
     if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
-        function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
-        return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
+        function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth')) {
+        return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth', $subject, $trim_val);
     }
 
     return substr_replace($subject, '...', $trim_val);
 }
 
 /**
-* FIXME: Undocumented function
-*/
+ * FIXME: Undocumented function
+ */
 function processSubject($subject, $threadlevel = 0) {
     /* Shouldn't ever happen -- caught too many times in the IMAP functions */
     if ($subject == '') {
@@ -1776,15 +1773,15 @@ function processSubject($subject, $threadlevel = 0) {
 
 
 /**
-* Creates button
-*
-* @deprecated see form functions available in 1.5.1 and 1.4.3.
-* @param string $type
-* @param string $name
-* @param string $value
-* @param string $js
-* @param bool $enabled
-*/
+ * Creates button
+ *
+ * @deprecated see form functions available in 1.5.1 and 1.4.3.
+ * @param string $type
+ * @param string $name
+ * @param string $value
+ * @param string $js
+ * @param bool $enabled
+ */
 function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
     $disabled = ( $enabled ? '' : 'disabled ' );
     $js = ( $js ? $js.' ' : '' );
@@ -1796,11 +1793,11 @@ function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
 }
 
 /**
-* Puts string into cell, aligns it and adds <small> tag
-*
-* @param string $string string
-* @param string $align alignment
-*/
+ * Puts string into cell, aligns it and adds <small> tag
+ *
+ * @param string $string string
+ * @param string $align alignment
+ */
 function getSmallStringCell($string, $align) {
     return html_tag('td',
                     '<small>' . $string . ':&nbsp; </small>',
@@ -1810,9 +1807,9 @@ function getSmallStringCell($string, $align) {
 }
 
 /**
-* This should go in imap_mailbox.php
-* @param string $mailbox
-*/
+ * This should go in imap_mailbox.php
+ * @param string $mailbox
+ */
 function handleAsSent($mailbox) {
     global $handleAsSent_result;
 
@@ -1870,11 +1867,8 @@ function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = ar
                 !in_array($aUid[0],$aMailbox['UIDSET'][$aMailbox['SETINDEX']])) {
                 break;
             }
-            // What kind of hook is this, can it be removed? Disabled for now because it can invalidate the cache
-            //if (!boolean_hook_function('move_messages_button_action', NULL, 1)) {
-                $aUpdatedMsgs = sqimap_msgs_list_delete($imapConnection, $mailbox, $aUid,$bypass_trash);
-                $bExpunge = true;
-            //}
+            $aUpdatedMsgs = sqimap_msgs_list_delete($imapConnection, $mailbox, $aUid,$bypass_trash);
+            $bExpunge = true;
             break;
           case 'unsetDeleted':
           case 'setSeen':
@@ -1902,6 +1896,10 @@ function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = ar
                 $aMailbox['FORWARD_SESSION'] = $composesession;
             }
             break;
+          default:
+            // Hook for plugin buttons
+            do_hook_function('mailbox_display_button_action', $aUid);
+            break;
         }
         /**
          * Updates messages is an array containing the result of the untagged
@@ -1913,7 +1911,13 @@ function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = ar
             $aDeleted = array();
             foreach ($aUpdatedMsgs as $iUid => $aMsg) {
                 if (isset($aMsg['FLAGS'])) {
-                    $aMailbox['MSG_HEADERS'][$iUid]['FLAGS'] = $aMsg['FLAGS'];
+                    /**
+                     * Only update the cached headers if the header is
+                     * cached.
+                     */
+                    if (isset($aMailbox['MSG_HEADERS'][$iUid])) {
+                        $aMailbox['MSG_HEADERS'][$iUid]['FLAGS'] = $aMsg['FLAGS'];
+                    }
                     /**
                      * Count the messages with the \Delete flag set so we can determine
                      * if the number of expunged messages equals the number of flagged
@@ -1950,10 +1954,12 @@ function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = ar
                             unset($aMailbox['MSG_HEADERS'][$iUid]);
                         }
                         $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = array_keys($aUidSetDummy);
-                        // update EXISTS info
-                        $aMailbox['EXISTS'] -= $iExpungedMessages;
                     }
                 }
+                // update EXISTS info
+                if ($iExpungedMessages) {
+                    $aMailbox['EXISTS'] -= (int) $iExpungedMessages;
+                }
                 // Change the startMessage number if the mailbox was changed
                 if (($aMailbox['PAGEOFFSET']+$iExpungedMessages-1) >= $aMailbox['EXISTS']) {
                     $aMailbox['PAGEOFFSET'] = ($aMailbox['PAGEOFFSET'] > $aMailbox['LIMIT']) ?
@@ -2041,4 +2047,5 @@ function attachSelectedMessages($imapConnection,$aMsgHeaders) {
     return $composesession;
 }
 
-?>
+// vim: et ts=4
+?>
\ No newline at end of file