From: jmunro Date: Thu, 28 Mar 2002 21:07:41 +0000 (+0000) Subject: Added a server-side thread sort option. disabled by default (site wide) X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=7c612fdd06ef01a509e7691e2cf373e7910f1d48 Added a server-side thread sort option. disabled by default (site wide) 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 --- diff --git a/config/conf.pl b/config/conf.pl index fbd3ae57..7e18dda6 100755 --- a/config/conf.pl +++ b/config/conf.pl @@ -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 = ; + 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++ ) { diff --git a/config/config_default.php b/config/config_default.php index 6a432239..2da4eacc 100644 --- a/config/config_default.php +++ b/config/config_default.php @@ -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). diff --git a/functions/imap_messages.php b/functions/imap_messages.php index 55932ca4..c40b516e 100755 --- a/functions/imap_messages.php +++ b/functions/imap_messages.php @@ -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 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 diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 3631ac54..7495032b 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -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 " $bold"; - if (! isset($search_stuff)) { $search_stuff = ''; } + if (! isset($search_stuff)) { $search_stuff = ''; } + if ($thread_sort_messages == 1) { + echo str_repeat("  ",$indent_array[$msg["ID"]]); + } echo "= 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&mailbox=$urlMailbox&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 = ' ', $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 . "\n" . "' . "\n". + ' \n"."\n"; + +echo " \n". " \n"; break; case 3: /* date */ echo ' \n"; + if ($thread_sort_messages != 1) { + ShowSortButton($sort, $mailbox, 0, 1); + } + echo "\n"; break; case 4: /* subject */ echo ' \n"; break; diff --git a/src/load_prefs.php b/src/load_prefs.php index 880b1a2e..c0a7a913 100644 --- a/src/load_prefs.php +++ b/src/load_prefs.php @@ -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); diff --git a/src/options_display.php b/src/options_display.php index ef52091b..d9414645 100644 --- a/src/options_display.php +++ b/src/options_display.php @@ -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, diff --git a/src/read_body.php b/src/read_body.php index 69b402b3..b245fc4e 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -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; diff --git a/src/right_main.php b/src/right_main.php index 0fd724bf..11268479 100644 --- a/src/right_main.php +++ b/src/right_main.php @@ -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 "
\n"; do_hook('right_main_after_header'); - if (isset($note)) { echo "
$note

\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);
" . " \n" - . " \n" - . " \n" + . " \n" . "
$paginator$msg_cnt_str$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 '| '._("$thread_name").' '; +} + + + +echo " $msg_cnt_str
\n" . '
\n" @@ -533,8 +573,9 @@ function mail_message_listing_beginning } echo '  '. ' '. - ' \n"."\n". - " "; if (!$auto_expunge) { echo ' ' . _("mailbox") . ' '; @@ -572,20 +613,25 @@ function mail_message_listing_beginning } else { echo ' '. _("From") .''; } - - ShowSortButton($sort, $mailbox, 2, 3); + if ($thread_sort_messages != 1) { + ShowSortButton($sort, $mailbox, 2, 3); + } echo "'. _("Date") .''; - ShowSortButton($sort, $mailbox, 0, 1); - echo "'. _("Subject") .' '; - ShowSortButton($sort, $mailbox, 4, 5); + if ($thread_sort_messages != 1) { + ShowSortButton($sort, $mailbox, 4, 5); + } echo "