if ( !$edit_name ) {
$edit_name = "true";
}
+if ( !$allow_thread_sort ) {
+ $allow_thread_sort = 'false';
+}
if ( !$prefs_user_field ) {
$prefs_user_field = 'user';
}
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";
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(); }
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";
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++ ) {
$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).
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;
$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
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;
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(" ",$indent_array[$msg["ID"]]);
+ }
echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
do_hook("subject_link");
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);
}
$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) {
$type[] = $hdr->type0;
}
}
-
$j = 0;
if ($sort == 6) {
$end = $start_msg + $show_num - 1;
$end = $num_msgs;
$end_loop = $end;
}
-
while ($j < $end_loop) {
if (isset($date[$j])) {
$date[$j] = str_replace(' ', ' ', $date[$j]);
}
$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)
}
// 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)
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);
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'); }
$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);
} else {
$i = 1;
}
-
+
reset($msort);
$k = 0;
do {
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);
/*
. "<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 '| <a href='."$base_uri".'src/right_main.php?sort='."$sort".'&start_messages=1&set_thread='."$set_thread".'&mailbox='.urlencode($mailbox).'>'._("$thread_name").'</a> ';
+}
+
+
+
+echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
. " </TR></TABLE>\n"
. '</TD></TR>'
. "<TR><TD BGCOLOR=\"$color[0]\">\n"
}
echo ' </SELECT></TT> '.
'<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> '.
- '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward") . "\"> \n"."</SMALL>\n".
- " </TD>\n".
+ '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward") . "\"> \n"."</SMALL>\n";
+
+echo " </TD>\n".
" <TD ALIGN=\"RIGHT\" NOWRAP>";
if (!$auto_expunge) {
echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge") . '"> ' . _("mailbox") . ' ';
} 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;
/* 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);
/* 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();
'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,
* 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;
/** 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;
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;
}
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);
echo "<br>\n";
do_hook('right_main_after_header');
-
if (isset($note)) {
echo "<CENTER><B>$note</B></CENTER><BR>\n";
}
}
}
+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 *
session_register('numMessages');
$_SESSION['numMessages'] = $numMessages;
}
-
do_hook('right_main_bottom');
sqimap_logout ($imapConnection);