From 5bdd722368a3fac32defc2242e9dd3f1e567a527 Mon Sep 17 00:00:00 2001 From: pallo Date: Sat, 9 Dec 2000 15:22:00 +0000 Subject: [PATCH] Fixed how folder names are formatted in a hierarchy of folders. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@880 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_mailbox.php | 127 +++++++++++++++++++++++---------- functions/strings.php | 10 +++ src/folders.php | 97 ++++++++++++------------- src/folders_rename_do.php | 9 ++- src/folders_rename_getname.php | 9 ++- src/left_main.php | 30 ++++---- 6 files changed, 175 insertions(+), 107 deletions(-) diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index 0d966cd7..b7ae6032 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -111,20 +111,42 @@ /****************************************************************************** ** Formats a mailbox into 4 parts for the $boxes array + ** + ** The four parts are: + ** + ** raw - Raw LIST/LSUB response from the IMAP server + ** formatted - nicely formatted folder name + ** unformatted - unformatted, but with delimiter at end removed + ** unformatted-dm - folder name as it appears in raw response + ** ******************************************************************************/ function sqimap_mailbox_parse ($line, $line_lsub, $dm) { - global $folder_prefix; + global $folder_prefix; + + // Process each folder line for ($g=0; $g < count($line); $g++) { + + // Store the raw IMAP reply $boxes[$g]["raw"] = $line[$g]; - + + // Count number of delimiters ($dm) in folder name $mailbox = trim($line_lsub[$g]); $dm_count = countCharInString($mailbox, $dm); if (substr($mailbox, -1) == $dm) - $dm_count--; - - for ($j = 0; $j < $dm_count - (countCharInString($folder_prefix, $dm)); $j++) - $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . "  "; - $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm); + $dm_count--; // If name ends in delimiter - decrement count by one + + // Format folder name, but only if it's a INBOX.* or have + // a parent. + $boxesbyname[$mailbox] = $g; + $parentfolder = readMailboxParent($mailbox, $dm); + if((eregi("^inbox".quotemeta($dm), $mailbox)) || + ( isset($boxesbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) { + $indent = $dm_count - (countCharInString($folder_prefix, $dm)); + $boxes[$g]["formatted"] = str_repeat("  ", $indent); + $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm); + } else { + $boxes[$g]["formatted"] = $mailbox; + } $boxes[$g]["unformatted-dm"] = $mailbox; if (substr($mailbox, -1) == $dm) @@ -138,22 +160,24 @@ $boxes[$g]["flags"] = explode(" ", $flags); } } + return $boxes; } - /* patch from dave_michmerhuizen@yahoo.com - * allows case insensativity when sorting folders - */ - function _icmp ($a, $b) { - return strcasecmp($a, $b); - } + /* patch from dave_michmerhuizen@yahoo.com + * allows case insensativity when sorting folders + */ + function _icmp ($a, $b) { + return strcasecmp($a, $b); + } /****************************************************************************** ** Returns sorted mailbox lists in several different ways. - ** The array returned looks like this: + ** See comment on sqimap_mailbox_parse() for info about the returned array. ******************************************************************************/ function sqimap_mailbox_list ($imap_stream) { - global $load_prefs_php, $prefs_php, $config_php, $data_dir, $username, $list_special_folders_first; + global $load_prefs_php, $prefs_php, $config_php; + global $data_dir, $username, $list_special_folders_first; global $trash_folder, $sent_folder; global $move_to_trash, $move_to_sent; @@ -184,7 +208,7 @@ } $sorted_lsub_ary = $new_ary; if (isset($sorted_lsub_ary)) { - usort($sorted_lsub_ary, "_icmp"); + usort($sorted_lsub_ary, "_icmp"); //sort($sorted_lsub_ary); } @@ -216,40 +240,54 @@ $boxes = sqimap_mailbox_parse ($sorted_list_ary, $sorted_lsub_ary, $dm); + /** Now, lets sort for special folders **/ + + $boxesnew = Array(); + + // Find INBOX for ($i = 0; $i < count($boxes); $i++) { if (strtolower($boxes[$i]["unformatted"]) == "inbox") { - $boxesnew[0] = $boxes[$i]; + $boxesnew[] = $boxes[$i]; $boxes[$i]["used"] = true; - $i = count($boxes); + $i = count($boxes); } } if ($list_special_folders_first == true) { - for ($i = count($boxes)-1; $i >= 0 ; $i--) { - if (($boxes[$i]["unformatted"] == $trash_folder) && ($move_to_trash)) { - $pos = count($boxesnew); - $boxesnew[$pos] = $boxes[$i]; + + // Then list special folders and their subfolders + for ($i = 0 ; $i <= count($boxes) ; $i++) { + if((eregi("^".$trash_folder.'$', $boxes[$i]["unformatted"]) || + eregi("^".$trash_folder.quotemeta($dm), $boxes[$i]["unformatted"]) ) && + ($move_to_trash)) { + $boxesnew[] = $boxes[$i]; $boxes[$i]["used"] = true; - $trash_found = true; } - else if (($boxes[$i]["unformatted"] == $sent_folder) && ($move_to_sent)) { - $pos = count($boxesnew); - $boxesnew[$pos] = $boxes[$i]; + else if((eregi("^".$sent_folder.'$', $boxes[$i]["unformatted"]) || + eregi("^".$sent_folder.quotemeta($dm), $boxes[$i]["unformatted"]) ) && + ($move_to_sent)) { + $boxesnew[] = $boxes[$i]; $boxes[$i]["used"] = true; - $sent_found = true; } - - if (($sent_found && $trash_found) || ($sent_found && !$move_to_trash) || ($trash_found && !$move_to_sent) || (!$move_to_sent && !$move_to_trash)) - $i = -1; } + + // Put INBOX.* folders ahead of the rest + for ($i = 0; $i <= count($boxes); $i++) { + if (eregi("^inbox\.", $boxes[$i]["unformatted"]) && + ($boxes[$i]["used"] == false)) { + $boxesnew[] = $boxes[$i]; + $boxes[$i]["used"] = true; + } + } + } + // Rest of the folders for ($i = 0; $i < count($boxes); $i++) { if ((strtolower($boxes[$i]["unformatted"]) != "inbox") && ($boxes[$i]["used"] == false)) { - $pos = count($boxesnew); - $boxesnew[$pos] = $boxes[$i]; + $boxesnew[] = $boxes[$i]; $boxes[$i]["used"] = true; } } @@ -272,18 +310,30 @@ $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message); $g = 0; $phase = "inbox"; + for ($i = 0; $i < count($read_ary); $i++) { if (substr ($read_ary[$i], 0, 4) != "a001") { + + // Store the raw IMAP reply $boxes[$g]["raw"] = $read_ary[$i]; + // Count number of delimiters ($dm) in folder name $mailbox = find_mailbox_name($read_ary[$i]); $dm_count = countCharInString($mailbox, $dm); if (substr($mailbox, -1) == $dm) - $dm_count--; - - for ($j = 0; $j < $dm_count; $j++) - $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " "; - $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm); + $dm_count--; // If name ends in delimiter - decrement count by one + + // Format folder name, but only if it's a INBOX.* or have + // a parent. + $boxesbyname[$mailbox] = $g; + $parentfolder = readMailboxParent($mailbox, $dm); + if((eregi("^inbox".quotemeta($dm), $mailbox)) || + ( isset($boxesbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) { + $boxes[$g]["formatted"] = str_repeat("  ", $dm_count); + $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm); + } else { + $boxes[$g]["formatted"] = $mailbox; + } $boxes[$g]["unformatted-dm"] = $mailbox; if (substr($mailbox, -1) == $dm) @@ -305,9 +355,10 @@ } $g++; } - if ($boxes) { + if(is_array($boxes)) { $boxes = ary_sort ($boxes, "unformatted", 1); } + return $boxes; } diff --git a/functions/strings.php b/functions/strings.php index 8cacea41..2620fe52 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -20,6 +20,16 @@ return $regs[1]; } + //************************************************************************* + // Read from the back of $haystack until $needle is found, or the begining + // of the $haystack is reached. $needle is a single character + //************************************************************************* + function readMailboxParent($haystack, $needle) { + if ($needle == ".") $needle = "\."; + ereg("^(.+)$needle([^$needle]+)$needle?$", $haystack, $regs); + return $regs[1]; + } + // Searches for the next position in a string minus white space function next_pos_minus_white ($haystack, $pos) { while (substr($haystack, $pos, 1) == " " || diff --git a/src/folders.php b/src/folders.php index 0fdf5a9f..ad9c7232 100644 --- a/src/folders.php +++ b/src/folders.php @@ -70,7 +70,8 @@ //display form option for creating Sent and Trash folder if ($imap_server_type == "cyrus" && ($sent_folder != "none" || $trash_folder != "none")) { - if ((!sqimap_mailbox_exists ($imapConnection, $sent_folder)) || (!sqimap_mailbox_exists ($imapConnection, $trash_folder))) { + if ((!sqimap_mailbox_exists ($imapConnection, $sent_folder)) || + (!sqimap_mailbox_exists ($imapConnection, $trash_folder))) { echo "\n"; echo ""; echo "
"; echo _("Special Folder Options"); @@ -107,9 +108,9 @@ if (strtolower($boxes[$p]["unformatted"]) == "inbox") $count_special_folders++; else if (strtolower($imap_server_type) == "courier" && - strtolower($boxes[$p]["unformatted"]) == "inbox.trash") + strtolower($boxes[$p]["unformatted"]) == "inbox.trash") $count_special_folders++; - else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder) + else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder) $count_special_folders++; else if ($boxes[$p]["unformatted"] == $sent_folder && $sent_folder) $count_special_folders++; @@ -120,16 +121,16 @@ echo "\n"; echo "$box2\n"; - } + if ((strtolower($boxes[$i]["unformatted"]) != "inbox") && + ($boxes[$i]["unformatted"] != $trash_folder) && + ($boxes[$i]["unformatted"] != $sent_folder)) + { + $box = $boxes[$i]["unformatted-dm"]; + $box2 = replace_spaces($boxes[$i]["formatted"]); + if (strtolower($imap_server_type) != "courier" || strtolower($box) != "inbox.trash") + echo "
"; echo "
\n"; echo _("New name:"); - echo "   
\n"; + echo "
$old_parent .
\n"; if ($isfolder) echo ""; - echo ""; - echo "\n"; + printf("\n", $old); + printf("\n", $old_name); + echo "\n"; echo "

"; diff --git a/src/left_main.php b/src/left_main.php index 3623506e..8d823bae 100644 --- a/src/left_main.php +++ b/src/left_main.php @@ -45,14 +45,14 @@ displayHtmlHeader(); function formatMailboxName($imapConnection, $mailbox, $real_box, $delimeter, $unseen) { - global $folder_prefix, $trash_folder, $sent_folder; - global $color, $move_to_sent, $move_to_trash; + global $folder_prefix, $trash_folder, $sent_folder; + global $color, $move_to_sent, $move_to_trash; global $unseen_notify, $unseen_type; - + $mailboxURL = urlencode($real_box); - + if ($unseen_notify == 2 && $real_box == "INBOX") { - $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box); + $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box); if ($unseen_type == 1 && $unseen > 0) { $unseen_string = "($unseen)"; $unseen_found = true; @@ -62,7 +62,7 @@ $unseen_found = true; } } else if ($unseen_notify == 3) { - $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box); + $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box); if ($unseen_type == 1 && $unseen > 0) { $unseen_string = "($unseen)"; $unseen_found = true; @@ -72,17 +72,17 @@ $unseen_found = true; } } - + $line .= ""; if ($unseen > 0) $line .= ""; $special_color = false; - if ((strtolower($real_box) == "inbox") || - (($real_box == $trash_folder) && ($move_to_trash)) || - (($real_box == $sent_folder) && ($move_to_sent))) - $special_color = true; - + if ((strtolower($real_box) == "inbox") || + (($real_box == $trash_folder) && ($move_to_trash)) || + (($real_box == $sent_folder) && ($move_to_sent))) + $special_color = true; + if ($special_color == true) { $line .= ""; $line .= replace_spaces($mailbox); @@ -95,7 +95,7 @@ if ($unseen > 0) $line .= ""; - + if ($unseen_found) { $line .= " $unseen_string"; } @@ -133,7 +133,7 @@ for ($i = 0;$i < count($boxes); $i++) { $line = ""; $mailbox = $boxes[$i]["formatted"]; - + if ($boxes[$i]["flags"]) { $noselect = false; for ($h = 0; $h < count($boxes[$i]["flags"]); $h++) { @@ -142,7 +142,7 @@ } if ($noselect == true) { $line .= ""; - $line .= replace_spaces(readShortMailboxName($mailbox, $delimeter)); + $line .= replace_spaces($mailbox); $line .= ""; } else { $line .= formatMailboxName($imapConnection, $mailbox, $boxes[$i]["unformatted"], $delimeter, $boxes[$i]["unseen"]); -- 2.25.1