Added a server-side thread sort option. disabled by default (site wide)
authorjmunro <jmunro@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 28 Mar 2002 21:07:41 +0000 (21:07 +0000)
committerjmunro <jmunro@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 28 Mar 2002 21:07:41 +0000 (21:07 +0000)
uses IMAP THREAD command to sort mailboxes. Also does indenting of replys

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2642 7612ce4b-ef26-0410-bec9-ea0150e637f0

config/conf.pl
config/config_default.php
functions/imap_messages.php
functions/mailbox_display.php
src/load_prefs.php
src/options_display.php
src/read_body.php
src/right_main.php

index fbd3ae576222c69bc094ce1e633d9fad747deb31..7e18dda637156694f0fe86846ff3ea112af66806 100755 (executable)
@@ -284,6 +284,9 @@ if ( !$edit_identity ) {
 if ( !$edit_name ) {
     $edit_name = "true";
 }
+if ( !$allow_thread_sort ) {
+    $allow_thread_sort = 'false';
+}
 if ( !$prefs_user_field ) {
     $prefs_user_field = 'user';
 }
@@ -411,9 +414,9 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
         print "8.  Hide SM attributions      : $WHT$hide_sm_attributions$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 "11. Allow server thread sort  : $WHT$allow_thread_sort$NRM\n";
         if ( lc($edit_identity) eq "false" ) {
-            print "11. Allow editing of name     : $WHT$edit_name$NRM\n";
+            print "12. Allow editing of name     : $WHT$edit_name$NRM\n";
         }
         print "\n";
         print "R   Return to Main Menu\n";
@@ -592,7 +595,8 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
             elsif ( $command == 8 )  { $hide_sm_attributions     = command38(); }
             elsif ( $command == 9 )  { $default_use_mdn          = command39(); }
             elsif ( $command == 10 ) { $edit_identity            = command310(); }
-            elsif ( $command == 11 ) { $edit_name                = command311(); }
+            elsif ( $command == 11 ) { $allow_thread_sort        = command312(); }
+            elsif ( $command == 12 ) { $edit_name                = command311(); }
         } elsif ( $menu == 5 ) {
             if ( $command == 1 ) { command41(); }
             elsif ( $command == 2 ) { $theme_css = command42(); }
@@ -1669,6 +1673,26 @@ sub command311 {
     return $edit_name;
 }
 
+sub command312 {
+    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 "\n";
+
+    if ( lc($allow_thread_sort) eq "true" ) {
+        $default_value = "y";
+    } else {
+        $default_value = "n";
+    }
+    print "Allow server side thread sorting? (y/n) [$WHT$default_value$NRM]: $WHT";
+    $allow_thread_sort = <STDIN>;
+    if ( ( $allow_thread_sort =~ /^y\n/i ) || ( ( $allow_thread_sort =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
+        $allow_thread_sort = "true";
+    } else {
+        $allow_thread_sort = "false";
+    }
+    return $allow_thread_sort;
+}
+
 sub command41 {
     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";
@@ -2191,6 +2215,7 @@ sub save_data {
         print CF "\$default_use_mdn          = $default_use_mdn;\n";
         print CF "\$edit_identity            = $edit_identity;\n";
         print CF "\$edit_name                = $edit_name;\n";
+        print CF "\$allow_thread_sort        = $allow_thread_sort;\n";
         print CF "\n";
 
         for ( $ct = 0 ; $ct <= $#plugins ; $ct++ ) {
index 6a4322394026d8cf13eb4a01090cc0ba0b273f10..2da4eaccd4332976b6737ccaaf09037a52e87c66 100644 (file)
@@ -467,6 +467,16 @@ global $edit_identity, $edit_name;
 $edit_identity = true;
 $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.
+*/
+
+global $allow_thread_sort;
+$allow_thread_sort = false;
+
 /**
  * Make sure there are no characters after the PHP closing
  * tag below (including newline characters and whitespace).
index 55932ca4cfbf470cd1b34a19cf664f3794a2d610..c40b516ec863ddba74d7cdfd1b14efc91f6b922c 100755 (executable)
@@ -90,6 +90,145 @@ function get_reference_header ($imap_stream, $message) {
        return $responses;
 }
 
+/* returns an indent array for printMessageinfo()
+   this represents the amount of indent needed
+   for this message number
+*/
+
+function get_parent_level ($imap_stream) {
+    global $sort_by_ref, $default_charset, $thread_new;
+        $parent = "";
+        $child = "";
+    for ($i=0;$i<count($thread_new);$i++) {
+        $thread_new[$i] = preg_replace("/\s\(/", "(", $thread_new[$i]);
+        $thread_new[$i] = preg_replace("/(\d+)/", "$1|", $thread_new[$i]);
+        $thread_new[$i] = preg_split("/\|/", $thread_new[$i], -1, PREG_SPLIT_NO_EMPTY);
+    } 
+    $indent_array = array();
+        if (!$thread_new) {
+                $thread_new = array();
+        }
+    for ($i=0;$i<count($thread_new);$i++) {
+        if (isset($thread_new[$i][0])) {
+        if (preg_match("/(\d+)/", $thread_new[$i][0], $regs)) {
+            $parent = $regs[1];
+        }
+        }
+        $indent_array[$parent] = 0;
+        $indent = 0;
+        $go = 'stop';
+        $spaces = array ();
+        $l = 0;
+        for ($k=1;$k<(count($thread_new[$i]))-1;$k++) {
+            $chars = count_chars($thread_new[$i][$k], 1);
+            if (isset($chars['40']) && isset($chars['41'])) {
+                $l--;
+            }
+            if (isset($chars['40'])) {  // (
+                $indent = $indent + $chars[40];
+                $go = 'start';
+                $l++;
+            }
+            if (isset($chars['41'])) {  //  )
+                if ($go == 'start') {
+                    if (!isset($spaces[$l])) {
+                                                $spaces[$l] = 0;
+                                        }
+                    $indent = $indent - $spaces[$l];
+                    $indent = $indent - $chars[41] ;
+                    $go = 'stop';
+                    $l--;
+                }
+                else {
+                    $indent = $indent - $chars[41];
+                }
+            }
+            if (isset($chars['32'])) {  //  space
+                $indent = $indent + $chars[32];
+                if ($go == 'start') {
+                    if (!isset($spaces[$l])) {
+                                                $spaces[$l] = 0;
+                                        }
+                    $spaces[$l] = $spaces[$l] + $chars[32];
+                }
+            }
+            if (preg_match("/(\d+)/", $thread_new[$i][$k], $regs)) {
+                $child = $regs[1];
+            }
+            $indent_array[$child] = abs($indent);
+        }    
+    }
+    return $indent_array;
+}
+
+
+/* returns an array with each element as a string
+   representing one message thread as returned by
+   the IMAP server
+*/
+
+function get_thread_sort ($imap_stream) {
+    global $thread_new, $sort_by_ref, $default_charset;
+
+    if (session_register('thread_new')) {
+        session_unregister('thread_new');
+    }
+    $sid = sqimap_session_id();
+    $thread_temp = array ();
+    if ($sort_by_ref == 1) {
+        $sort_type = 'REFERENCES';
+    }
+    else {
+        $sort_type = 'ORDEREDSUBJECT';
+    }
+    $thread_query = "$sid THREAD $sort_type $default_charset ALL\r\n";
+    fputs($imap_stream, $thread_query);
+    $thread_test = sqimap_read_data($imap_stream, $sid, true, $response, $message);
+    if (preg_match("/^\* THREAD (.+)$/", $thread_test[0], $regs)) {
+       $thread_list = trim($regs[1]);
+    }
+    else {
+       $thread_list = "";
+    }
+    $thread_temp = preg_split("//", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
+    $char_count = count($thread_temp);
+    $counter = 0;
+    $thread_new = array();
+    $k = 0;
+    $thread_new[0] = "";
+    for ($i=0;$i<$char_count;$i++) {
+            if ($thread_temp[$i] != ')' && $thread_temp[$i] != '(') {
+                    $thread_new[$k] = $thread_new[$k] . $thread_temp[$i];
+            }
+            elseif ($thread_temp[$i] == '(') {
+                    $thread_new[$k] .= $thread_temp[$i];
+                    $counter++;
+            }
+            elseif ($thread_temp[$i] == ')') {
+                    if ($counter > 1) {
+                            $thread_new[$k] .= $thread_temp[$i];
+                            $counter = $counter - 1;
+                    }
+                    else {
+                            $thread_new[$k] .= $thread_temp[$i];
+                            $k++;
+                            $thread_new[$k] = "";
+                            $counter = $counter - 1;
+                    }
+            }
+    }
+        session_register('$thread_new');
+    $thread_new = array_reverse($thread_new);
+    $thread_list = implode(" ", $thread_new);
+    $thread_list = str_replace("(", " ", $thread_list);
+    $thread_list = str_replace(")", " ", $thread_list);
+    $thread_list = preg_split("/\s/", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
+    return $thread_list;
+}
+
+
+
+
 function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
     global $squirrelmail_language, $color, $data_dir, $username;
 
@@ -100,7 +239,6 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
     $results = array();
     $read_list = array();
     $sizes_list = array();
-
     /*
      * We need to return the data in the same order as the caller supplied
      * in $msg_list, but IMAP servers are free to return responses in
index 3631ac5405fb7ea26ad86dc3e178c7721d7b2f98..7495032b10b60c4dedec3ba2121fcb2b5e56e5a3 100644 (file)
@@ -17,15 +17,17 @@ require_once('../functions/strings.php');
 define('PG_SEL_MAX', 10);  /* Default value for page_selector_max. */
 
 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
-    global $checkall,
+    global $checkall, 
            $color, $msgs, $msort,
            $sent_folder, $draft_folder,
            $default_use_priority,
            $message_highlight_list,
            $index_order,
-           $pos;            /* Search postion (if any)  */
+           $indent_array,   /* indent subject by */
+           $pos,            /* Search postion (if any)  */
+           $thread_sort_messages; /* thread sorting on/off */
+           $color_string = $color[4];
 
-    $color_string = $color[4];
     if ($GLOBALS['alt_index_colors']) {
         if (!isset($GLOBALS['row_count'])) {
             $GLOBALS['row_count'] = 0;
@@ -135,7 +137,10 @@ function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start
             break;
         case 4: /* subject */
             echo "   <td bgcolor=\"$hlt_color\">$bold";
-                if (! isset($search_stuff)) { $search_stuff = ''; }
+            if (! isset($search_stuff)) { $search_stuff = ''; }
+            if ($thread_sort_messages == 1) {
+                echo str_repeat("&nbsp;&nbsp;",$indent_array[$msg["ID"]]);
+            }
             echo "<a href=\"read_body.php?mailbox=$urlMailbox&amp;passed_id=".$msg["ID"]."&amp;startMessage=$start_msg&amp;show_more=0$search_stuff\"";
             do_hook("subject_link");
 
@@ -199,21 +204,34 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg
     global $msgs, $msort,
            $sent_folder, $draft_folder,
            $message_highlight_list,
-           $auto_expunge;
-
+           $auto_expunge, $thread_sort_messages,
+                  $data_dir, $username;
     /* If autoexpunge is turned on, then do it now. */
+
+
+    if ($thread_sort_messages == 1 ) {
+        $id = get_thread_sort($imapConnection);
+        $sort = 6;
+        if ($start_msg + ($show_num - 1) < $num_msgs) {
+            $end_msg = $start_msg + ($show_num-1);
+        }
+        else {
+            $end_msg = $num_msgs;
+        }
+        $id = array_slice($id, ($start_msg-1), ($end_msg));
+    }
     if ($auto_expunge == true) {
         sqimap_mailbox_expunge($imapConnection, $mailbox, false);
     }
     sqimap_mailbox_select($imapConnection, $mailbox);
-
     $issent = handleAsSent($mailbox);
     if (!$use_cache) {
         /* If it is sorted... */
         if ($num_msgs >= 1) {
-            if ($sort < 6) {
+            if ($sort < 6 ) {
                 $id = range(1, $num_msgs);
-            } else {
+            } 
+            elseif ($thread_sort_messages != 1) {
                 // if it's not sorted
                 if ($start_msg + ($show_num - 1) < $num_msgs) {
                     $end_msg = $start_msg + ($show_num-1);
@@ -235,7 +253,6 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg
                 }
                 $id = array_reverse(range($real_endMessage, $real_startMessage));
             }
-
             $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
             $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
             foreach ($msgs_list as $hdr) {
@@ -249,7 +266,6 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg
             $type[] = $hdr->type0;
             }
         }
-
         $j = 0;
         if ($sort == 6) {
             $end = $start_msg + $show_num - 1;
@@ -264,7 +280,6 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg
             $end = $num_msgs;
             $end_loop = $end;
         }
-
         while ($j < $end_loop) {
             if (isset($date[$j])) {
                 $date[$j] = str_replace('  ', ' ', $date[$j]);
@@ -310,7 +325,6 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg
             }
             $j++;
         }
-
         /* Only ignore messages flagged as deleted if we are using a
         * trash folder or auto_expunge */
         if (((isset($move_to_trash) && $move_to_trash)
@@ -340,7 +354,7 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg
     }
 
     // There's gotta be messages in the array for it to sort them.
-    if ($num_msgs > 0 && ! $use_cache) {
+    if ($num_msgs > 0 && ! $use_cache && $thread_sort_messages != 1) {
         /** 0 = Date (up)      4 = Subject (up)
         ** 1 = Date (dn)      5 = Subject (dn)
         ** 2 = Name (up)
@@ -360,10 +374,16 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg
         if ($sort < 6) {
             if ($sort % 2) {
                 asort($msort);
-            } else {
+            } 
+                       else {
                 arsort($msort);
             }
-        }
+        }              
+        session_register('msort');
+    }
+    elseif ($thread_sort_messages == 1 ) {
+        $msort = $msgs;
+        session_unregister('msgs');
         session_register('msort');
     }
     displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
@@ -377,6 +397,7 @@ function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $ms
     global $folder_prefix, $sent_folder;
     global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
     global $index_order, $real_endMessage, $real_startMessage, $checkall;
+    global $indent_array, $thread_sort_messages;
 
     /* If cache isn't already set, do it now. */
     if (!session_is_registered('msgs')) { session_register('msgs'); }
@@ -405,6 +426,10 @@ function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $ms
         $msg = '';
     }
 
+    /* get indent level for subject display */
+    if ($thread_sort_messages == 1 ) {
+        $indent_array = get_parent_level($imapConnection);
+    }
     mail_message_listing_beginning( $imapConnection,
         "move_messages.php?msg=$msg&amp;mailbox=$urlMailbox&amp;startMessage=$start_msg",
         $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
@@ -435,7 +460,7 @@ function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $ms
         } else {
             $i = 1;
         }
-
+                               
         reset($msort);
         $k = 0;
         do {
@@ -490,8 +515,8 @@ function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $ms
 function mail_message_listing_beginning
         ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
         $msg_cnt_str = '', $paginator = '&nbsp;', $start_msg = 1) {
-    global $color, $index_order, $auto_expunge, $move_to_trash;
-    global $checkall, $sent_folder, $draft_folder;
+    global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri;
+    global $checkall, $sent_folder, $draft_folder, $thread_sort_messages, $allow_thread_sort;
     $urlMailbox = urlencode($mailbox);
 
     /*
@@ -502,8 +527,23 @@ function mail_message_listing_beginning
        . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n"
        . "<TR BGCOLOR=\"$color[0]\"><TD>"
        . "    <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
-       . "    <TD ALIGN=LEFT>$paginator</TD>\n"
-       . "    <TD ALIGN=RIGHT>$msg_cnt_str</TD>\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"
        . "  </TR></TABLE>\n"
        . '</TD></TR>'
        . "<TR><TD BGCOLOR=\"$color[0]\">\n"
@@ -533,8 +573,9 @@ function mail_message_listing_beginning
     }
     echo '         </SELECT></TT>&nbsp;'.
          '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '">&nbsp;'.
-        '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward") . "\">&nbsp;\n"."</SMALL>\n".
-         "      </TD>\n".
+        '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward") . "\">&nbsp;\n"."</SMALL>\n";
+
+echo     "      </TD>\n".
          "      <TD ALIGN=\"RIGHT\" NOWRAP>";
     if (!$auto_expunge) {
         echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge") . '">&nbsp;' . _("mailbox") . '&nbsp;';
@@ -572,20 +613,25 @@ function mail_message_listing_beginning
             } else {
                 echo '   <TD WIDTH="25%"><B>'. _("From") .'</B>';
             }
-
-            ShowSortButton($sort, $mailbox, 2, 3);
+                                               if ($thread_sort_messages != 1) {
+                       ShowSortButton($sort, $mailbox, 2, 3);
+                                               }
             echo "</TD>\n";
             break;
 
         case 3: /* date */
             echo '   <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
-            ShowSortButton($sort, $mailbox, 0, 1);
-            echo "</TD>\n";
+                                               if ($thread_sort_messages != 1) {
+                       ShowSortButton($sort, $mailbox, 0, 1);
+            }
+                                               echo "</TD>\n";
             break;
 
         case 4: /* subject */
             echo '   <TD><B>'. _("Subject") .'</B> ';
-            ShowSortButton($sort, $mailbox, 4, 5);
+                                               if ($thread_sort_messages != 1) {
+                ShowSortButton($sort, $mailbox, 4, 5);
+            }
             echo "</TD>\n";
             break;
 
index 880b1a2e0ed09d6d53f893063285a90e9edcbcf7..c0a7a913a8cfed12e7666b0dbf629b5ed2d082b6 100644 (file)
@@ -217,6 +217,10 @@ $sig_first = getPref($data_dir, $username, 'sig_first', 0);
 /* use the internal date of the message for sorting instead of the supplied header date */
 $internal_date_sort = getPref($data_dir, $username, 'internal_date_sort', SMPREF_ON);
 
+/* if thread sorting is enabled/disabled */
+$thread_sort_messages = getPref($data_dir, $username, 'thread_sort_messages', 0);
+$sort_by_ref = getPref($data_dir, $username, 'sort_by_ref', 1);
+
 /* Load the javascript settings. */
 $javascript_setting =
     getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
index ef52091b4c00ed62b39decf4aa31c755ff019a65..d9414645ffbde5f36f9f5c34c776bde0fb26b568 100644 (file)
@@ -19,7 +19,7 @@ define('SMOPT_GRP_MESSAGE', 2);
 /* Define the optpage load function for the display options page. */
 function load_optpage_data_display() {
     global $theme, $language, $languages, $js_autodetect_results,
-           $default_use_mdn, $squirrelmail_language;
+           $default_use_mdn, $squirrelmail_language, $allow_thread_sort;
 
     /* Build a simple array into which we will build options. */
     $optgrps = array();
@@ -260,6 +260,14 @@ function load_optpage_data_display() {
         'type'    => SMOPT_TYPE_BOOLEAN,
         'refresh' => SMOPT_REFRESH_ALL
     );
+    if ($allow_thread_sort == 'TRUE') {
+        $optvals[SMOPT_GRP_MESSAGE][] = array(
+            'name'    => 'sort_by_ref',
+            'caption' => _("Use References header for thread sort"),
+            'type'    => SMOPT_TYPE_BOOLEAN,
+            'refresh' => SMOPT_REFRESH_ALL
+        );
+    }
     /* Assemble all this together and return it as our result. */
     $result = array(
         'grps' => $optgrps,
index 69b402b333182695bc0796b4502ace27a5d42d7e..b245fc4e5bcf042c7a171c28ca149d48bd607dfa 100644 (file)
@@ -27,9 +27,11 @@ require_once('../functions/smtp.php');
 * returns the index of the next valid message from the array
 */
 function findNextMessage() {
-    global $msort, $currentArrayIndex, $msgs, $sort;
+    global $msort, $currentArrayIndex, $msgs, $sort, $thread_sort_messages;
     $result = -1;
-
+               if ($thread_sort_messages == 1) {
+                               $sort = 0;
+               }
     if ($sort == 6) {
         if ($currentArrayIndex != 1) {
             $result = $currentArrayIndex - 1;
@@ -63,7 +65,10 @@ function RemoveAddress(&$addr_list, $addr) {
 /** returns the index of the previous message from the array. */
 function findPreviousMessage() {
     global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection,
-           $mailbox, $data_dir, $username;
+           $mailbox, $data_dir, $username, $thread_sort_messages;
+               if ($thread_sort_messages == 1) {
+                               $sort = 0;
+               }
 
     $result = -1;
 
index 0fd724bfd407a8a3c6501a1647b8d8efc3d636f8..11268479f4b9e8bd22bf239a9ebf856867c58f7b 100644 (file)
@@ -45,17 +45,38 @@ if( isset( $PG_SHOWNUM ) ) {
 
 if (isset($newsort) && $newsort != $sort) {
     setPref($data_dir, $username, 'sort', $newsort);
-    $sort = $newsort;
-    session_register('sort');
 }
 
+/* decide if we are thread sorting or not */
+global $allow_thread_sort;
+if ($allow_thread_sort == TRUE) {
+    if (isset($set_thread)) {
+        if ($set_thread == 1) {
+            setPref($data_dir, $username, 'thread_sort_messages', 1);
+            $thread_sort_messages = '1';    
+        }
+        elseif ($set_thread == 2)  {
+            setPref($data_dir, $username, 'thread_sort_messages', 0);
+            $thread_sort_messages = '0';    
+        }
+    }
+    else {
+        $thread_sort_messages = getPref($data_dir, $username, 'thread_sort_messages');
+    }
+}
+else {
+    $thread_sort_messages = 0;
+} 
+
+
 /* If the page has been loaded without a specific mailbox, */
 /* send them to the inbox                                  */
 if (!isset($mailbox)) {
     $mailbox = 'INBOX';
     $startMessage = 1;
 }
-   
+
+
 if (!isset($startMessage) || ($startMessage == '')) {
     $startMessage = 1;
 }
@@ -65,11 +86,11 @@ if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
                                   substr($mailbox, 0, 1) == '/')) {
    $mailbox = 'INBOX';
 }
-global $color;
+    global $color;
 
-if( isset($do_hook) && $do_hook ) {
-    do_hook ("generic_header");
-}
+    if( isset($do_hook) && $do_hook ) {
+        do_hook ("generic_header");
+    }
 
 sqimap_mailbox_select($imapConnection, $mailbox);
 
@@ -91,7 +112,6 @@ if (isset($composenew)) {
 echo "<br>\n";
 
 do_hook('right_main_after_header');
-
 if (isset($note)) {
     echo "<CENTER><B>$note</B></CENTER><BR>\n";
 }
@@ -111,6 +131,11 @@ if ($just_logged_in == true) {
     }
 }
 
+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 *
@@ -162,7 +187,6 @@ if ($use_mailbox_cache && session_is_registered('msgs')) {
     session_register('numMessages');
     $_SESSION['numMessages'] = $numMessages;
 }
-
 do_hook('right_main_bottom');
 sqimap_logout ($imapConnection);