support for picking up attachments in case of a expired session
[squirrelmail.git] / src / search.php
index 8a04fd70b585616566eaa29e1e54e3fbb86a1576..3acc5b1262274dc0fea371b4eb4e21e19dcd48c4 100644 (file)
 require_once('../src/validate.php');
 require_once('../functions/imap.php');
 require_once('../functions/imap_search.php');
-require_once('../functions/imap_utf7_decode_local.php');
+require_once('../functions/imap_mailbox.php');
 require_once('../functions/array.php');
 require_once('../functions/strings.php');
-require_once('../functions/html.php');
 
 global $allow_thread_sort;
 
@@ -160,6 +159,34 @@ function save_recent($save_index, $username, $data_dir) {
     }
 }
 
+function printSearchMessages($msgs,$mailbox, $cnt, $imapConnection, $where, $what, $usecache = false, $newsort = false) {
+    global $sort, $color;
+    
+    $msort = calc_msort($msgs, $sort);
+    if ($cnt > 0) {
+       if ( $mailbox == 'INBOX' ) {
+           $showbox = _("INBOX");
+       } else {
+            $showbox = imap_utf7_decode_local($mailbox);
+       }
+       echo html_tag( 'div', '<b><big>' . _("Folder:") . ' '. $showbox.'</big></b>','center') . "\n";
+
+
+       $msg_cnt_str = get_msgcnt_str(1, $cnt, $cnt);
+
+       mail_message_listing_beginning($imapConnection, $mailbox, $sort, 
+                                       $msg_cnt_str, '', 1);
+
+
+       printHeader($mailbox, 6, $color, false);
+
+       displayMessageArray($imapConnection, $cnt, 1, 
+                         $msort, $mailbox, $sort, $color, $cnt, $where, $what);
+
+       mail_message_listing_end($cnt, '', $msg_cnt_str, $color); 
+    }
+}                            
+
 /* ------------------------ main ------------------------ */
 
 /*  reset these arrays on each page load just in case  */
@@ -169,6 +196,7 @@ $search_all = 'none';
 $perbox_count = array ();
 $recent_count = getPref($data_dir, $username, 'search_memory', 0);
 
+
 /*  get mailbox names  */
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 $boxes = sqimap_mailbox_list($imapConnection);
@@ -266,7 +294,6 @@ if ($saved_count > 0) {
     echo "</table></td></tr></table>\n";
 }
 
-/* Recent Search Table */
 if ($recent_count > 0) {
     echo "<br>\n"
        . html_tag( 'table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"' )
@@ -313,6 +340,29 @@ if ($recent_count > 0) {
     echo '</table></td></tr></table><br>';
 }
 
+
+if (isset($newsort)) {
+    $sort = $newsort;
+    session_register('sort');
+}
+
+/*********************************************************************
+ * Check to see if we can use cache or not. Currently the only time  *
+ * when you will not use it is when a link on the left hand frame is *
+ * used. Also check to make sure we actually have the array in the   *
+ * registered session data.  :)                                      *
+ *********************************************************************/
+if (! isset($use_mailbox_cache)) {
+    $use_mailbox_cache = 0;
+}
+
+/* There is a problem with registered vars in 4.1 */
+/*
+if( substr( phpversion(), 0, 3 ) == '4.1'  ) {
+    $use_mailbox_cache = FALSE;
+}
+*/
+
 /* Search Form */
 echo html_tag( 'div', '<b>' . _("Current Search") . '</b>', 'left' ) . "\n"
    . '<form action="search.php" name="s">'
@@ -386,29 +436,30 @@ if ($allow_thread_sort == TRUE) {
 if ($search_all == 'all') {
     $mailbox == '';
     $boxcount = count($boxes);
-    echo '<br><center><b>' .
+    echo '<BR><CENTER><B>' .
          _("Search Results") .
-         "</b><center><br>\n";
+         "</B><CENTER><BR>\n";
     for ($x=0;$x<$boxcount;$x++) {
         if (!in_array('noselect', $boxes[$x]['flags'])) {
             $mailbox = $boxes[$x]['unformatted'];
         }
         if (($submit == _("Search") || $submit == 'Search_no_update') && !empty($what)) {
             sqimap_mailbox_select($imapConnection, $mailbox);
-            $count_all = sqimap_search($imapConnection, $where, $what, $mailbox, $color, 0, $search_all, $count_all);
-        array_push($perbox_count, $count_all);
+            $msgs = sqimap_search($imapConnection, $where, $what, $mailbox, $color, 0, $search_all, $count_all);
+           $count_all = count($msgs);
+            printSearchMessages($msgs, $mailbox, $count_all, $imapConnection, 
+                               $where, $what, false, false);
+            array_push($perbox_count, $count_all);
         }
     }
     for ($i=0;$i<count($perbox_count);$i++) {
-        if ($perbox_count[$i] != "") {
-            $count_all = "found";
+        if ($perbox_count[$i]) {
+            $count_all = true;
             break;
         }
     }
-    if ($count_all != "found") {
-        echo '<br><b>' .
-             _("No Messages found") .
-             '</b><br>';
+    if (!$count_all) {
+       echo '<br><center>' . _("No Messages Found") . '</center>';
     }
 }
 
@@ -418,7 +469,13 @@ else {
         echo '<br>'
         . html_tag( 'div', '<b>' . _("Search Results") . '</b>', 'center' ) . "\n";
         sqimap_mailbox_select($imapConnection, $mailbox);
-        sqimap_search($imapConnection, $where, $what, $mailbox, $color, 0, $search_all, $count_all);
+        $msgs = sqimap_search($imapConnection, $where, $what, $mailbox, $color, 0, $search_all, $count_all);
+       if (count($msgs)) {
+           printSearchMessages($msgs, $mailbox, count($msgs), $imapConnection,
+                              $where, $what, false, false);
+       } else {
+           echo '<br><center>' . _("No Messages Found") . '</center>';
+       }
     }
 }
 
@@ -430,6 +487,7 @@ if ($submit == _("Search") && empty($what)) {
 
 $allow_thread_sort = $old_value;
 
+
 do_hook('search_bottom');
 sqimap_logout ($imapConnection);
 echo '</body></html>';