Replace array_search that only uses a boolean to check whether the value
[squirrelmail.git] / src / read_body.php
index 75f478e8b25468586756934d8c46ac6d32a0a78c..7e12373efcb5c20c50b35f2441a3ecbf61c26708 100644 (file)
@@ -37,16 +37,20 @@ require_once(SM_PATH . 'functions/mailbox_display.php');
  * @param int $passed_id The current message UID
  * @return the index of the next valid message from the array
  */
-function findNextMessage($passed_id) {
-    global $server_sort_array;
+function findNextMessage($uidset,$passed_id='backwards') {
+    if ($passed_id=='backwards' || !is_array($uidset)) { // check for backwards compattibilty gpg plugin
+        $passed_id = $uidset;
+        sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
+        $uidset = $server_sort_array;
+    }
     $result = -1;
-    $count = count($server_sort_array) - 1;
-    foreach($server_sort_array as $key=>$value) {
+    $count = count($uidset) - 1;
+    foreach($uidset as $key=>$value) {
         if ($passed_id == $value) {
             if ($key == $count) {
                 break;
             }
-            $result = $server_sort_array[$key + 1];
+            $result = $uidset[$key + 1];
             break;
         }
     }
@@ -60,13 +64,17 @@ function findNextMessage($passed_id) {
  * @param int $passed_id The current message UID
  * @return the index of the next valid message from the array
  */
-function findPreviousMessage($numMessages, $passed_id) {
-    global $server_sort_array;
+
+function findPreviousMessage($uidset, $passed_id) {
+    if (!is_array($uidset)) { //obsolete check
+        sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
+        $uidset = $server_sort_array;
+    }
     $result = -1;
-    foreach($server_sort_array as $key=>$value) {
+    foreach($uidset as $key=>$value) {
         if ($passed_id == $value) {
             if ($key != 0) {
-                $result = $server_sort_array[$key - 1];
+                $result = $uidset[$key - 1];
             }
             break;
         }
@@ -111,10 +119,8 @@ function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
 
 function ServerMDNSupport($aFlags) {
     /* escaping $ doesn't work -> \x36 */
-    return (array_search('$mdnsent',$aFlags,true) !== false ||
-            array_search('\\*',$aFlags,true) !== false) ? true : false;
-    //$ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
-    //return $ret;
+    return ( in_array('$mdnsent',$aFlags,true) ||
+             in_array('\\*',$aFlags,true) ) ;
 }
 
 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
@@ -359,12 +365,14 @@ function formatRecipientString($recipients, $item ) {
     return $string;
 }
 
-function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
+function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
                          $color, $FirstTimeSee) {
     global $msn_user_support, $default_use_mdn, $default_use_priority,
            $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
           $squirrelmail_language;
 
+    $mailbox = $aMailbox['NAME']       ;
+
     $header = $message->rfc822_header;
     $env = array();
     $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject));
@@ -448,13 +456,16 @@ function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
  * @param object $message Current message object
  * @param object $mbx_response
  */
-function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
+function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
     global $base_uri, $draft_folder, $where, $what, $color, $sort,
            $startMessage, $PHP_SELF, $save_as_draft,
            $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
            $data_dir, $username, $delete_prev_next_display,
            $compose_new_win, $javascript_on;
 
+    //FIXME cleanup argument list, use $aMailbox where possible
+    $mailbox = $aMailbox['NAME'];
+
     $topbar_delimiter = ' | ';
     $double_delimiter = '    ';
     $urlMailbox = urlencode($mailbox);
@@ -513,8 +524,8 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp
 
     // Prev/Next links for regular messages
     } else if ( !(isset($where) && isset($what)) ) {
-        $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
-        $next = findNextMessage($passed_id);
+        $prev = findPreviousMessage($aMailbox['UIDSET'], $passed_id);
+        $next = findNextMessage($aMailbox['UIDSET'],$passed_id);
 
         $prev_link = _("Previous");
         if ($prev >= 0) {
@@ -535,7 +546,7 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp
         // Only bother with Delete & Prev and Delete & Next IF
         // top display is enabled.
         if ( $delete_prev_next_display == 1 &&
-               array_search('\\deleted', $mbx_response['PERMANENTFLAGS'],true) !== false) {
+               in_array('\\deleted', $mbx_response['PERMANENTFLAGS'],true) ) {
             $del_prev_link = _("Delete & Prev");
             if ($prev >= 0) {
                 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
@@ -621,7 +632,7 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp
 
     $menu_row .= '</form>&nbsp;';
 
-    if (array_search('\\deleted', $mbx_response['PERMANENTFLAGS'],true) !== false) {
+    if ( in_array('\\deleted', $mbx_response['PERMANENTFLAGS'],true) ) {
     // Form for deletion
         $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox;
         $menu_row .= '<form action="'.$delete_url.'" method="post" style="display: inline">';
@@ -648,7 +659,7 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp
     // Add top move link
     $menu_row .= '</small></td><td align="right">';
     if ( !(isset($passed_ent_id) && $passed_ent_id) &&
-        array_search('\\deleted', $mbx_response['PERMANENTFLAGS'],true) !== false) {
+        in_array('\\deleted', $mbx_response['PERMANENTFLAGS'],true) ) {
 
         $current_box = 'mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage;
 
@@ -788,13 +799,31 @@ global $sqimap_capabilities, $lastTargetMailbox;
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 $mbx_response   = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
 
+global $allow_thread_sort, $auto_expunge;
+
+if ($allow_thread_sort && getPref($data_dir, $username, "thread_$mailbox",0)) {
+    $aMailbox['SORT_METHOD'] = 'THREAD';
+} else if ($allow_server_sort) {
+    $aMailbox['SORT_METHOD'] = 'SERVER';
+} else {
+    $aMailbox['SORT_METHOD'] = 'SQUIRREL';
+}
+sqgetGlobalVar('aLastSelectedMailbox',$aMailbox,SQ_SESSION);
+$aMailbox['UIDSET'] = $server_sort_array;
+$aMailbox['SORT'] = $sort;
+$aMailbox['NAME'] = $mailbox;
+$aMailbox['EXISTS'] = $mbx_response['EXISTS'];
+$aMailbox['AUTO_EXPUNGE'] = $auto_expunge;
+$aMailbox['MSG_HEADERS'] = $msgs;
+
+
 /**
  * Process Delete from delete-move-next
  * but only if delete_id was set
  */
 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
     sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
-    sqimap_mailbox_expunge_dmn($delete_id,$mbx_response,$server_sort_array);
+    sqimap_mailbox_expunge_dmn($imapConnection,$aMailbox,$delete_id);
 }
 
 /**
@@ -876,8 +905,8 @@ for ($i = 0; $i < $cnt; $i++) {
 }
 
 displayPageHeader($color, $mailbox);
-formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
-formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
+formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
+formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
 echo '  <tr><td>';
 echo '    <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
@@ -937,7 +966,7 @@ if (($attachment_common_show_images) &&
     }
 }
 
-formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
+formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
 
 do_hook('read_body_bottom');
 do_hook('html_bottom');