فهرست منبع

added a server-side sorting option. set gloablly in conf.pl
IMAP server does the sorting with the SORT extension. Defaults
to disabled.

jmunro 23 سال پیش
والد
کامیت
cead1432ff
4فایلهای تغییر یافته به همراه147 افزوده شده و 36 حذف شده
  1. 29 2
      config/conf.pl
  2. 12 4
      config/config_default.php
  3. 40 2
      functions/imap_messages.php
  4. 66 28
      functions/mailbox_display.php

+ 29 - 2
config/conf.pl

@@ -287,6 +287,9 @@ if ( !$edit_name ) {
 if ( !$allow_thread_sort ) {
 if ( !$allow_thread_sort ) {
     $allow_thread_sort = 'false';
     $allow_thread_sort = 'false';
 }
 }
+if ( !$allow_server_sort ) {
+    $allow_server_sort = 'false';
+}
 if ( !$prefs_user_field ) {
 if ( !$prefs_user_field ) {
     $prefs_user_field = 'user';
     $prefs_user_field = 'user';
 }
 }
@@ -415,8 +418,9 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
         print "9.  Allow use of receipts     : $WHT$default_use_mdn$NRM\n";
         print "9.  Allow use of receipts     : $WHT$default_use_mdn$NRM\n";
         print "10. Allow editing of identity : $WHT$edit_identity$NRM\n";
         print "10. Allow editing of identity : $WHT$edit_identity$NRM\n";
         print "11. Allow server thread sort  : $WHT$allow_thread_sort$NRM\n";
         print "11. Allow server thread sort  : $WHT$allow_thread_sort$NRM\n";
+        print "12. Allow server-side sorting  : $WHT$allow_server_sort$NRM\n";
         if ( lc($edit_identity) eq "false" ) {
         if ( lc($edit_identity) eq "false" ) {
-            print "12. Allow editing of name     : $WHT$edit_name$NRM\n";
+            print "13. Allow editing of name     : $WHT$edit_name$NRM\n";
         }
         }
         print "\n";
         print "\n";
         print "R   Return to Main Menu\n";
         print "R   Return to Main Menu\n";
@@ -596,7 +600,8 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
             elsif ( $command == 9 )  { $default_use_mdn          = command39(); }
             elsif ( $command == 9 )  { $default_use_mdn          = command39(); }
             elsif ( $command == 10 ) { $edit_identity            = command310(); }
             elsif ( $command == 10 ) { $edit_identity            = command310(); }
             elsif ( $command == 11 ) { $allow_thread_sort        = command312(); }
             elsif ( $command == 11 ) { $allow_thread_sort        = command312(); }
-            elsif ( $command == 12 ) { $edit_name                = command311(); }
+            elsif ( $command == 12 ) { $allow_server_sort        = command313(); }
+            elsif ( $command == 13 ) { $edit_name                = command311(); }
         } elsif ( $menu == 5 ) {
         } elsif ( $menu == 5 ) {
             if ( $command == 1 ) { command41(); }
             if ( $command == 1 ) { command41(); }
             elsif ( $command == 2 ) { $theme_css = command42(); }
             elsif ( $command == 2 ) { $theme_css = command42(); }
@@ -1676,6 +1681,7 @@ sub command311 {
 sub command312 {
 sub command312 {
     print "This option allows you to choose if users can use thread sorting\n";
     print "This option allows you to choose if users can use thread sorting\n";
     print "Your IMAP server must support the THREAD command for this to work\n";
     print "Your IMAP server must support the THREAD command for this to work\n";
+	print "PHP versions later than 4.0.3 recommended\n";
     print "\n";
     print "\n";
 
 
     if ( lc($allow_thread_sort) eq "true" ) {
     if ( lc($allow_thread_sort) eq "true" ) {
@@ -1693,6 +1699,26 @@ sub command312 {
     return $allow_thread_sort;
     return $allow_thread_sort;
 }
 }
 
 
+sub command313 {
+    print "This option allows you to choose if SM uses server-side sorting\n";
+    print "Your IMAP server must support the SORT  command for this to work\n";
+    print "\n";
+
+    if ( lc($allow_server_sort) eq "true" ) {
+        $default_value = "y";
+    } else {
+        $default_value = "n";
+    }
+    print "Allow server-side sorting? (y/n) [$WHT$default_value$NRM]: $WHT";
+    $allow_server_sort = <STDIN>;
+    if ( ( $allow_server_sort =~ /^y\n/i ) || ( ( $allow_server_sort =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
+        $allow_server_sort = "true";
+    } else {
+        $allow_server_sort = "false";
+    }
+    return $allow_server_sort;
+}
+
 sub command41 {
 sub command41 {
     print "\nNow we will define the themes that you wish to use.  If you have added\n";
     print "\nNow we will define the themes that you wish to use.  If you have added\n";
     print "a theme of your own, just follow the instructions (?) about how to add\n";
     print "a theme of your own, just follow the instructions (?) about how to add\n";
@@ -2216,6 +2242,7 @@ sub save_data {
         print CF "\$edit_identity            = $edit_identity;\n";
         print CF "\$edit_identity            = $edit_identity;\n";
         print CF "\$edit_name                = $edit_name;\n";
         print CF "\$edit_name                = $edit_name;\n";
         print CF "\$allow_thread_sort        = $allow_thread_sort;\n";
         print CF "\$allow_thread_sort        = $allow_thread_sort;\n";
+        print CF "\$allow_server_sort        = $allow_server_sort;\n";
         print CF "\n";
         print CF "\n";
 
 
         for ( $ct = 0 ; $ct <= $#plugins ; $ct++ ) {
         for ( $ct = 0 ; $ct <= $#plugins ; $ct++ ) {

+ 12 - 4
config/config_default.php

@@ -469,14 +469,22 @@ $edit_name = true;
 
 
 
 
 /**
 /**
-* If you want to enable server side thread sorting options
-* Your IMAP server must support the THREAD extension for 
-* this to work.
-*/
+ * If you want to enable server side thread sorting options
+ * Your IMAP server must support the THREAD extension for 
+ * this to work.
+ */
 
 
 global $allow_thread_sort;
 global $allow_thread_sort;
 $allow_thread_sort = false;
 $allow_thread_sort = false;
 
 
+/** 
+ * to use server-side sorting instead of SM client side.
+ * Your IMAP server must support the SORT extension for this
+ * to work.
+ */
+global $allow_server_sort;
+$allow_server_sort = false;
+
 /**
 /**
  * Make sure there are no characters after the PHP closing
  * Make sure there are no characters after the PHP closing
  * tag below (including newline characters and whitespace).
  * tag below (including newline characters and whitespace).

+ 40 - 2
functions/imap_messages.php

@@ -90,6 +90,45 @@ function get_reference_header ($imap_stream, $message) {
 	return $responses;
 	return $responses;
 }
 }
 
 
+
+/* get sort order from server and
+ * return it as the $id array for
+ * mailbox_display
+ */
+ 
+function sqimap_get_sort_order ($imap_stream, $sort) {
+    global  $default_charset, $thread_sort_messages, $internal_date_sort;
+    $sid = sqimap_session_id();
+    $sort_on = array();
+    $reverse = 0;
+    $server_sort_array = array();
+    $sort_test = array();
+    $sort_query = '';
+    $sort_on = array (0=> 'DATE',
+                      1=> 'DATE',
+                      2=> 'FROM',
+                      3=> 'FROM',
+                      4=> 'SUBJECT',
+                      5=> 'SUBJECT',
+                      6=> 'DATE');
+    if ($internal_date_sort == true) {
+        $sort_on[0] = 'ARRIVAL';
+        $sort_on[1] = 'ARRIVAL';
+    }
+    if (!empty($sort_on[$sort])) {
+        $sort_query = "$sid SORT ($sort_on[$sort]) ".strtoupper($default_charset)." ALL\r\n";
+        fputs($imap_stream, $sort_query);
+        $sort_test = sqimap_read_data($imap_stream, $sid, true, $response, $message);
+    }
+    if (preg_match("/^\* SORT (.+)$/", $sort_test[0], $regs)) {
+        $server_sort_array = preg_split("/ /", trim($regs[1]));
+    }
+    if ($sort == 0 || $sort == 2 || $sort == 4) {
+       $server_sort_array = array_reverse($server_sort_array);
+    }
+    return $server_sort_array;
+}
+	
 /* returns an indent array for printMessageinfo()
 /* returns an indent array for printMessageinfo()
    this represents the amount of indent needed
    this represents the amount of indent needed
    for this message number
    for this message number
@@ -181,7 +220,7 @@ function get_thread_sort ($imap_stream) {
     else {
     else {
         $sort_type = 'ORDEREDSUBJECT';
         $sort_type = 'ORDEREDSUBJECT';
     }
     }
-    $thread_query = "$sid THREAD $sort_type $default_charset ALL\r\n";
+    $thread_query = "$sid THREAD $sort_type ".strtoupper($default_charset)." ALL\r\n";
     fputs($imap_stream, $thread_query);
     fputs($imap_stream, $thread_query);
     $thread_test = sqimap_read_data($imap_stream, $sid, true, $response, $message);
     $thread_test = sqimap_read_data($imap_stream, $sid, true, $response, $message);
     if (preg_match("/^\* THREAD (.+)$/", $thread_test[0], $regs)) {
     if (preg_match("/^\* THREAD (.+)$/", $thread_test[0], $regs)) {
@@ -228,7 +267,6 @@ function get_thread_sort ($imap_stream) {
 
 
 
 
 
 
-
 function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
 function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
     global $squirrelmail_language, $color, $data_dir, $username;
     global $squirrelmail_language, $color, $data_dir, $username;
 
 

+ 66 - 28
functions/mailbox_display.php

@@ -28,7 +28,9 @@ function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
     $indent_array,   /* indent subject by */
     $indent_array,   /* indent subject by */
     $pos,            /* Search postion (if any)  */
     $pos,            /* Search postion (if any)  */
     $thread_sort_messages, /* thread sorting on/off */
     $thread_sort_messages, /* thread sorting on/off */
-    $row_count;
+    $server_sort_order, /* sort value when using server-sorting */
+    $row_count,
+	$allow_server_sort; /* enable/disable server-side sorting */
   $color_string = $color[4];
   $color_string = $color[4];
   
   
   if ($GLOBALS['alt_index_colors']) {
   if ($GLOBALS['alt_index_colors']) {
@@ -223,21 +225,41 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
 				$use_cache) {
 				$use_cache) {
   global $msgs, $msort,
   global $msgs, $msort,
     $sent_folder, $draft_folder,
     $sent_folder, $draft_folder,
-    $message_highlight_list,
-    $auto_expunge, $thread_sort_messages,
-    $data_dir, $username;
-  /* If autoexpunge is turned on, then do it now. */
-  
+    $message_highlight_list, 
+    $auto_expunge, $thread_sort_messages, $allow_server_sort,
+    $data_dir, $username, $server_sort_order;
+
+  /* This code and the next if() block check for
+   * server-side sorting methods. The $id array is
+   * formatted and $sort is set to 6 to disable 
+   * SM internal sorting
+   */
   if ($thread_sort_messages == 1) {
   if ($thread_sort_messages == 1) {
     $id = get_thread_sort($imapConnection);
     $id = get_thread_sort($imapConnection);
     $sort = 6;
     $sort = 6;
     if ($start_msg + ($show_num - 1) < $num_msgs) {
     if ($start_msg + ($show_num - 1) < $num_msgs) {
       $end_msg = $start_msg + ($show_num-1);
       $end_msg = $start_msg + ($show_num-1);
-    } else {
+    } 
+	else {
+      $end_msg = $num_msgs;
+    }
+    $id = array_slice($id, ($start_msg-1), ($end_msg));
+  }
+
+  if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
+    $server_sort_order = $sort;
+    $id = sqimap_get_sort_order($imapConnection, $server_sort_order);
+    $sort = 6;
+    if ($start_msg + ($show_num - 1) < $num_msgs) {
+      $end_msg = $start_msg + ($show_num-1);
+    } 
+	else {
       $end_msg = $num_msgs;
       $end_msg = $num_msgs;
     }
     }
     $id = array_slice($id, ($start_msg-1), ($end_msg));
     $id = array_slice($id, ($start_msg-1), ($end_msg));
   }
   }
+
+  /* If autoexpunge is turned on, then do it now. */
   if ($auto_expunge == true) {
   if ($auto_expunge == true) {
     sqimap_mailbox_expunge($imapConnection, $mailbox, false);
     sqimap_mailbox_expunge($imapConnection, $mailbox, false);
   }
   }
@@ -249,7 +271,7 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
       if ($sort < 6 ) {
       if ($sort < 6 ) {
 	$id = range(1, $num_msgs);
 	$id = range(1, $num_msgs);
       } 
       } 
-      elseif ($thread_sort_messages != 1) {
+      elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) {
 	/* if it's not sorted */
 	/* if it's not sorted */
 	if ($start_msg + ($show_num - 1) < $num_msgs){
 	if ($start_msg + ($show_num - 1) < $num_msgs){
 	  $end_msg = $start_msg + ($show_num - 1);
 	  $end_msg = $start_msg + ($show_num - 1);
@@ -413,7 +435,7 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
       }
       }
     }		
     }		
     session_register('msort');
     session_register('msort');
-  } elseif ($thread_sort_messages == 1 ) {
+  } elseif ($thread_sort_messages == 1 || $allow_server_sort == TRUE) {
     $msort = $msgs;
     $msort = $msgs;
     session_unregister('msgs');
     session_unregister('msgs');
     session_register('msort');
     session_register('msort');
@@ -433,7 +455,7 @@ function displayMessageArray($imapConnection, $num_msgs, $start_msg,
   global $folder_prefix, $sent_folder, 
   global $folder_prefix, $sent_folder, 
     $imapServerAddress, $data_dir, $username, $use_mailbox_cache, 
     $imapServerAddress, $data_dir, $username, $use_mailbox_cache, 
     $index_order, $real_endMessage, $real_startMessage, $checkall, 
     $index_order, $real_endMessage, $real_startMessage, $checkall, 
-    $indent_array, $thread_sort_messages;
+    $indent_array, $thread_sort_messages, $allow_server_sort, $server_sort_order;
 
 
   /* If cache isn't already set, do it now. */
   /* If cache isn't already set, do it now. */
   if (!session_is_registered('msgs')) {
   if (!session_is_registered('msgs')) {
@@ -568,7 +590,7 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
 					 $start_msg = 1) {
 					 $start_msg = 1) {
   global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
   global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
     $checkall, $sent_folder, $draft_folder, $thread_sort_messages, 
     $checkall, $sent_folder, $draft_folder, $thread_sort_messages, 
-    $allow_thread_sort;
+    $allow_thread_sort, $allow_server_sort, $server_sort_order;
   $urlMailbox = urlencode($mailbox);
   $urlMailbox = urlencode($mailbox);
 
 
   /*
   /*
@@ -582,20 +604,6 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
     . "CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
     . "CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
     . "    <TD ALIGN=LEFT>$paginator\n";
     . "    <TD ALIGN=LEFT>$paginator\n";
 
 
-  if ($allow_thread_sort == TRUE) {
-    if ($thread_sort_messages == 1 ) {
-      $set_thread = 2;
-      $thread_name = 'Unthread View';
-    } elseif ($thread_sort_messages == 0) {
-      $set_thread = 1;
-      $thread_name = 'Thread View';
-    }
-    echo   '|&nbsp;<a href=' . "$base_uri" . 'src/right_main.php?sort=' 
-      . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
-      . '&mailbox=' . urlencode($mailbox) . '>' . _("$thread_name")
-      . '</a>&nbsp;';
-  }
-
   echo "    <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
   echo "    <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
     . "  </TR></TABLE>\n"
     . "  </TR></TABLE>\n"
     . '</TD></TR>'
     . '</TD></TR>'
@@ -641,8 +649,25 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
     . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
     . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
     . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '">&nbsp;'
     . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '">&nbsp;'
     . "</TD>\n"
     . "</TD>\n"
-    . "   </TR>\n"
-    . "</TABLE>\n";
+    . "   </TR>\n";
+
+/* draws thread sorting links */
+  if ($allow_thread_sort == TRUE) {
+    if ($thread_sort_messages == 1 ) {
+      $set_thread = 2;
+      $thread_name = 'Unthread View';
+    } 
+	elseif ($thread_sort_messages == 0) {
+      $set_thread = 1;
+      $thread_name = 'Thread View';
+    }
+    echo   '<tr><td>&nbsp;<a href=' . "$base_uri" . 'src/right_main.php?sort=' 
+      . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
+      . '&mailbox=' . urlencode($mailbox) . '><small>' . _("$thread_name")
+      . '</a></small>&nbsp;</td></tr>';
+  }
+
+  echo "</TABLE>\n";
   do_hook('mailbox_form_before');
   do_hook('mailbox_form_before');
   echo '</TD></TR>'
   echo '</TD></TR>'
     . "<TR><TD BGCOLOR=\"$color[0]\">"
     . "<TR><TD BGCOLOR=\"$color[0]\">"
@@ -654,7 +679,14 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
   }
   }
   echo " BGCOLOR=\"$color[0]\">"
   echo " BGCOLOR=\"$color[0]\">"
     . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
     . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
-
+  /* if using server sort we highjack the
+   * the $sort var and use $server_sort_order
+   * instead. but here we reset sort for a bit
+   * since its easy
+   */
+  if ($allow_server_sort == TRUE) {
+    $sort = $server_sort_order;
+  }
   /* Print the headers. */
   /* Print the headers. */
   for ($i=1; $i <= count($index_order); $i++) {
   for ($i=1; $i <= count($index_order); $i++) {
     switch ($index_order[$i]) {
     switch ($index_order[$i]) {
@@ -692,6 +724,12 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
       break;
       break;
     }
     }
   }
   }
+  /* if using server-sorting,
+   * send sort back to 6
+   */
+  if ($allow_server_sort == TRUE) {
+    $sort = 6;
+  }
   echo "</TR>\n";
   echo "</TR>\n";
 }
 }