From: kink Date: Wed, 6 Apr 2005 20:58:03 +0000 (+0000) Subject: Drop "$oldway" mailbox list generation code from left_main. The new code X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3cbf882e8ebef2064f97b553055136e7e4c8d8d9;p=squirrelmail.git Drop "$oldway" mailbox list generation code from left_main. The new code has been surviving fine since 1.3.0 and as far as we know there are no current problems with it. What this patch does: - Remove a lot of obsolete code from left_main.php. - Remove configurable tweak 'oldway' from config (not renumbering conf.pl menu at this stage to avoid confusion of menu item numbers). - Coding style fixes to mailbox generation code. - Remove unneccessary (only one cell) HTML tables from left_main. - Add support for unselectable folder color (color[15]) which was missing from ListBoxes. Note: advancedtree is still a configurable tweak as it's not as mature and has dhtml-dependencies. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@9217 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/ChangeLog b/ChangeLog index 47c38c7d..aae8443a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -300,8 +300,9 @@ Version 1.5.1 -- CVS Awais Ahmad for the patch (#1082558). - src/delete_message.php script is disabled. It provided functions that could be implemented without playing with multiple redirects. + - Remove lots of obsoleted code from left_main.php. -Version 1.5.0 - 2 Februari 2004 +Version 1.5.0 - 2 February 2004 ------------------------------- - Added new preference that determines cursor focus when replying - Added support in conf.pl for MS cls command. diff --git a/config/conf.pl b/config/conf.pl index c3b959c3..ea0371cf 100755 --- a/config/conf.pl +++ b/config/conf.pl @@ -324,7 +324,6 @@ $show_alternative_names = 'false' if ( !$show_alternative_names ); $available_languages = 'all' if ( !$available_languages ); $aggressive_decoding = 'false' if ( !$aggressive_decoding ); $advanced_tree = 'false' if ( !$advanced_tree ); -$oldway = 'false' if ( !$oldway ); $use_php_recode = 'false' if ( !$use_php_recode ); $use_php_iconv = 'false' if ( !$use_php_iconv ); # since 1.5.1 @@ -605,7 +604,6 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) && ( $command ne ":q" ) ) { } elsif ( $menu == 11 ) { print $WHT. "Interface tweaks\n" . $NRM; print "1. Advanced tree : $WHT$advanced_tree$NRM\n"; - print "2. Oldway : $WHT$oldway$NRM\n"; print "3. Use Icons : $WHT$use_icons$NRM\n"; print "\n"; print $WHT. "PHP tweaks\n" . $NRM; @@ -769,7 +767,6 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) && ( $command ne ":q" ) ) { elsif ( $command == 6 ) { $lossy_encoding = commandA6(); } } elsif ( $menu == 11 ) { if ( $command == 1 ) { $advanced_tree = commandB1(); } - elsif ( $command == 2 ) { $oldway = commandB2(); } elsif ( $command == 3 ) { $use_icons = commandB3(); } elsif ( $command == 4 ) { $use_php_recode = commandB4(); } elsif ( $command == 5 ) { $use_php_iconv = commandB5(); } @@ -3048,26 +3045,6 @@ sub commandB1 { } return $advanced_tree; } -# Oldway -sub commandB2 { - print "Setting \$oldway to false causes left_main.php to use the new\n"; - print "experimental way of getting the mailbox-tree.\n"; - print "\n"; - - if ( lc($oldway) eq 'true' ) { - $default_value = "y"; - } else { - $default_value = "n"; - } - print "Use old way of folder list display? (y/n) [$WHT$default_value$NRM]: $WHT"; - $oldway = ; - if ( ( $oldway =~ /^y\n/i ) || ( ( $oldway =~ /^\n/ ) && ( $default_value eq "y" ) ) ) { - $oldway = 'true'; - } else { - $oldway = 'false'; - } - return $oldway; -} # use icons sub commandB3 { print "Enabling this option will cause icons to be used instead of text\n"; @@ -3451,9 +3428,6 @@ sub save_data { print CF "\$advanced_tree = $advanced_tree;\n"; print CF "\n"; # boolean - print CF "\$oldway = $oldway;\n"; - print CF "\n"; - # boolean print CF "\$use_icons = $use_icons;\n"; print CF "\n"; # boolean diff --git a/config/config_default.php b/config/config_default.php index 92d17ed2..2203bc58 100644 --- a/config/config_default.php +++ b/config/config_default.php @@ -919,15 +919,6 @@ $lossy_encoding = false; */ $advanced_tree = false; -/** - * Older listing way control - * - * Use older way of folder listing - * @global bool $oldway - * @since 1.5.0 - */ -$oldway = false; - /** * Message Icons control * diff --git a/plugins/administrator/defines.php b/plugins/administrator/defines.php index d09b8196..b8cc5d00 100644 --- a/plugins/administrator/defines.php +++ b/plugins/administrator/defines.php @@ -332,8 +332,6 @@ $defcfg = array( '$config_version' => array( 'name' => _("Config File Version"), 'type' => SMOPT_TYPE_TITLE ), '$advanced_tree' => array( 'name' => _("Use advanced tree folder listing"), 'type' => SMOPT_TYPE_BOOLEAN ), - '$oldway' => array( 'name' => _("Use old folder listing functions"), - 'type' => SMOPT_TYPE_BOOLEAN ), '$use_icons' => array( 'name' => _("Use icons"), 'type' => SMOPT_TYPE_BOOLEAN ), '$use_php_recode' => array( 'name' => _("Use PHP recode functions"), @@ -372,4 +370,4 @@ $defcfg = array( '$config_version' => array( 'name' => _("Config File Version"), ); -?> \ No newline at end of file +?> diff --git a/src/left_main.php b/src/left_main.php index 9c105bbe..1c292e94 100644 --- a/src/left_main.php +++ b/src/left_main.php @@ -33,266 +33,22 @@ define('SM_BOX_COLLAPSED', 1); /* --------------------- FUNCTIONS ------------------------- */ -function formatMailboxName($imapConnection, $box_array) { - - global $trash_folder, $color, $move_to_trash, - $unseen_notify, $unseen_type, $use_special_folder_color; - $real_box = $box_array['unformatted']; - $mailbox = str_replace(' ','',$box_array['formatted']); - $mailboxURL = urlencode($real_box); - - /* Strip down the mailbox name. */ - if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) { - $mailbox = $regs[2]; - } - $unseen = 0; - $status = array('',''); - if (($unseen_notify == 2 && $real_box == 'INBOX') || - $unseen_notify == 3) { - $tmp_status = create_unseen_string($real_box, $box_array, $imapConnection, $unseen_type ); - if ($status !== false) { - $status = $tmp_status; - } - } - list($unseen_string, $unseen) = $status; - $special_color = ($use_special_folder_color && isSpecialMailbox($real_box)); - - /* Start off with a blank line. */ - $line = ''; - - /* If there are unseen message, bold the line. */ - if ($unseen > 0) { $line .= ''; } - - /* Create the link for this folder. */ - if ($status !== false) { - $line .= ''; - } - if ($special_color) { - $line .= ""; - } - if ( $mailbox == 'INBOX' ) { - $line .= _("INBOX"); - } else { - $line .= str_replace(array(' ','<','>'),array(' ','<','>'),$mailbox); - } - if ($special_color == TRUE) - $line .= ''; - if ($status !== false) { - $line .= ''; - } - - /* If there are unseen message, close bolding. */ - if ($unseen > 0) { $line .= ""; } - - /* Print unseen information. */ - if ($unseen_string != '') { - $line .= " $unseen_string"; - } - - /* If it's the trash folder, show a purge link */ - if (($move_to_trash) && ($real_box == $trash_folder)) { - $urlMailbox = urlencode($real_box); - $line .= "\n\n" . - '  ['._("Purge").']' . - ''; - } - - - // let plugins fiddle with end of line - $line .= concat_hook_function('left_main_after_each_folder', - array(isset($numMessages) ? $numMessages : '', $real_box, $imapConnection)); - - - /* Return the final product. */ - return ($line); -} /** - * Recursive function that computes the collapsed status and parent - * (or not parent) status of this box, and the visiblity and collapsed - * status and parent (or not parent) status for all children boxes. - */ -function compute_folder_children(&$parbox, $boxcount) { - global $boxes, $data_dir, $username, $collapse_folders; - $nextbox = $parbox + 1; - - /* Retreive the name for the parent box. */ - $parbox_name = $boxes[$parbox]['unformatted']; - - /* 'Initialize' this parent box to childless. */ - $boxes[$parbox]['parent'] = FALSE; - - /* Compute the collapse status for this box. */ - if( isset($collapse_folders) && $collapse_folders ) { - $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name); - $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse); - } else { - $collapse = SM_BOX_UNCOLLAPSED; - } - $boxes[$parbox]['collapse'] = $collapse; - - /* Otherwise, get the name of the next box. */ - if (isset($boxes[$nextbox]['unformatted'])) { - $nextbox_name = $boxes[$nextbox]['unformatted']; - } else { - $nextbox_name = ''; - } - - /* Compute any children boxes for this box. */ - while (($nextbox < $boxcount) && - (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) { - - /* Note that this 'parent' box has at least one child. */ - $boxes[$parbox]['parent'] = TRUE; - - /* Compute the visiblity of this box. */ - $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] && - ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED)); - - /* Compute the visibility of any child boxes. */ - compute_folder_children($nextbox, $boxcount); - } - - /* Set the parent box to the current next box. */ - $parbox = $nextbox; -} - -/** - * Create the link for a parent folder that will allow that - * parent folder to either be collapsed or expaned, as is - * currently appropriate. - */ -function create_collapse_link($boxnum) { - global $boxes, $unseen_notify, $color, $use_icons, $icon_theme; - $mailbox = urlencode($boxes[$boxnum]['unformatted']); - - /* Create the link for this collapse link. */ - $link = ''; - } else { - $link .= "unfold=$mailbox\">+"; - } - } else { - if ($use_icons && $icon_theme != 'none') { - $link .= "fold=$mailbox\">'; - } else { - $link .= "fold=$mailbox\">-"; - } - } - $link .= ''; - - /* Return the finished product. */ - return ($link); -} - -/** - * create_unseen_string: + * Recursive function to output a tree of folders. + * It is called on a list of boxes and iterates over that tree. * - * Create unseen and total message count for both this folder and - * it's subfolders. - * - * @param string $boxName name of the current mailbox - * @param array $boxArray array for the current mailbox - * @param $imapConnection current imap connection in use - * @return array unseen message string (for display), unseen message count + * @since 1.3.0 */ -function create_unseen_string($boxName, $boxArray, $imapConnection, $unseen_type) { - global $boxes, $color, $unseen_cum; - - /* Initialize the return value. */ - $result = array(0,0); - - /* Initialize the counts for this folder. */ - $boxUnseenCount = 0; - $boxMessageCount = 0; - $totalUnseenCount = 0; - $totalMessageCount = 0; - - /* Collect the counts for this box alone. */ - $status = sqimap_status_messages($imapConnection, $boxName); - $boxUnseenCount = $status['UNSEEN']; - if ($boxUnseenCount === false) { - return false; - } - if ($unseen_type == 2) { - $boxMessageCount = $status['MESSAGES']; - } - - /* Initialize the total counts. */ - - if ($boxArray['collapse'] == SM_BOX_COLLAPSED && $unseen_cum) { - /* Collect the counts for this boxes subfolders. */ - $curBoxLength = strlen($boxName); - $boxCount = count($boxes); - - for ($i = 0; $i < $boxCount; ++$i) { - /* Initialize the counts for this subfolder. */ - $subUnseenCount = 0; - $subMessageCount = 0; - - /* Collect the counts for this subfolder. */ - if (($boxName != $boxes[$i]['unformatted']) - && (substr($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName) - && !in_array('noselect', $boxes[$i]['flags'])) { - $status = sqimap_status_messages($imapConnection, $boxes[$i]['unformatted']); - $subUnseenCount = $status['UNSEEN']; - if ($unseen_type == 2) { - $subMessageCount = $status['MESSAGES'];; - } - /* Add the counts for this subfolder to the total. */ - $totalUnseenCount += $subUnseenCount; - $totalMessageCount += $subMessageCount; - } - } - - /* Add the counts for all subfolders to that of the box. */ - $boxUnseenCount += $totalUnseenCount; - $boxMessageCount += $totalMessageCount; - } - - /* And create the magic unseen count string. */ - /* Really a lot more then just the unseen count. */ - if (($unseen_type == 1) && ($boxUnseenCount > 0)) { - $result[0] = "($boxUnseenCount)"; - } else if ($unseen_type == 2) { - $result[0] = "($boxUnseenCount/$boxMessageCount)"; - $result[0] = "$result[0]"; - } - - /* Set the unseen count to return to the outside world. */ - $result[1] = $boxUnseenCount; - - /* Return our happy result. */ - return ($result); -} - -/** - * This simple function checks if a box is another box's parent. - */ -function is_parent_box($curbox_name, $parbox_name) { - global $delimiter; - - /* Extract the name of the parent of the current box. */ - $curparts = explode($delimiter, $curbox_name); - $curname = array_pop($curparts); - $actual_parname = implode($delimiter, $curparts); - $actual_parname = substr($actual_parname,0,strlen($parbox_name)); - - /* Compare the actual with the given parent name. */ - return ($parbox_name == $actual_parname); -} - function ListBoxes ($boxes, $j=0 ) { global $data_dir, $username, $color, $unseen_notify, $unseen_type, $move_to_trash, $trash_folder, $collapse_folders, $imapConnection, $use_icons, $icon_theme, $use_special_folder_color; - if (!isset($boxes) || empty($boxes)) + // stop condition + if (empty($boxes)) { return; + } $pre = ''; $end = ''; @@ -389,7 +145,7 @@ function ListBoxes ($boxes, $j=0 ) { $end .= " $unseen_string"; } } - $end .= "\n\n" . + $end .= "\n\t" . '  ['._("Purge").']'. ''; } else { @@ -415,8 +171,11 @@ function ListBoxes ($boxes, $j=0 ) { if ($use_special_folder_color && $boxes->is_special) { $font = ""; $fontend = ""; + } elseif ( $boxes->is_noselect ) { + $font = ""; + $fontend = ''; } - + // let plugins fiddle with end of line $end .= concat_hook_function('left_main_after_each_folder', array(isset($numMessages) ? $numMessages : '', @@ -425,13 +184,18 @@ function ListBoxes ($boxes, $j=0 ) { $end .= ''; if (!$boxes->is_root) { - echo "" . $pre .$font. str_replace(array(' ','<','>'),array(' ','<','>'),$boxes->mailboxname_sub) .$fontend . $end. '
' . "\n"; + echo "" . $pre .$font. + str_replace( + array(' ','<','>'), + array(' ','<','>'), + $boxes->mailboxname_sub) . + $fontend . $end. '
' . "\n"; $j++; } if (!$collapse || $boxes->is_root) { for ($i = 0; $i mbxs); $i++) { - listBoxes($boxes->mbxs[$i],$j); + ListBoxes($boxes->mbxs[$i],$j); } } } @@ -440,8 +204,9 @@ function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) { global $data_dir, $username, $color, $unseen_notify, $unseen_type, $move_to_trash, $trash_folder, $collapse_folders, $use_special_folder_color; - if (!isset($boxes) || empty($boxes)) + if (empty($boxes)) { return; + } /* use_folder_images only works if the images exist in ../images */ $use_folder_images = true; @@ -546,7 +311,11 @@ function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) { } if (!isset($boxes->mbxs[0])) { echo ' ' . html_tag( 'div', - ''. $pre . $folder_img . ''. str_replace(array(' ','<','>'),array(' ','<','>'),$boxes->mailboxname_sub) . $end, + ''. $pre . $folder_img . '' . + str_replace( array(' ','<','>'), + array(' ','<','>'), + $boxes->mailboxname_sub) . + $end, 'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n"; } else { /* get collapse information */ @@ -554,13 +323,15 @@ function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) { $form_entry = $j.'F'; if (isset($mbx) && isset($mbx[$form_entry])) { $collapse = $mbx[$form_entry]; - setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , $collapse ? SM_BOX_COLLAPSED : SM_BOX_UNCOLLAPSED); + setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , + $collapse ? SM_BOX_COLLAPSED : SM_BOX_UNCOLLAPSED); } else { $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox); $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse); } $img_src = ($collapse ? '../images/plus.png' : '../images/minus.png'); - $collapse_link = ''." "; + $collapse_link = '' . + " "; } else { $collapse_link=''; } @@ -575,14 +346,16 @@ function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) { if (isset($boxes->mbxs[0]) && !$boxes->is_root) /* mailbox contains childs */ echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n"; - if ($j !='ID.0000') + if ($j !='ID.0000') { $j = $j .'.0000'; + } for ($i = 0; $i mbxs); $i++) { $j++; ListAdvancedBoxes($boxes->mbxs[$i],$mbx,$j); } - if (isset($boxes->mbxs[0]) && !$boxes->is_root) + if (isset($boxes->mbxs[0]) && !$boxes->is_root) { echo ''."\n\n"; + } } @@ -602,12 +375,13 @@ sqgetGlobalVar('unfold', $unfold, SQ_GET); /* end globals */ // open a connection on the imap port (143) -$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output +// why hide the output? +$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, true); /** - * Using stristr since older preferences may contain "None" and "none". + * Using stristr since very old preferences may contain "None" and "none". */ -if (isset($left_refresh) && ($left_refresh != '') && +if (!empty($left_refresh) && !stristr($left_refresh, 'none')){ $xtra = "\n\n" . "\n". @@ -617,10 +391,8 @@ if (isset($left_refresh) && ($left_refresh != '') && } /** - * $advanced_tree and $oldway are boolean vars which are default set to default + * $advanced_tree and is a boolean var which is default set to default * SM behaviour. - * Setting $oldway to false causes left_main.php to use the new experimental - * way of getting the mailbox-tree. * Setting $advanced tree to true causes SM to display a experimental * mailbox-tree with dhtml behaviour. * It only works on browsers which supports css and javascript. The used @@ -634,17 +406,12 @@ if (isset($left_refresh) && ($left_refresh != '') && * setting this to true is only usefull if the images exists in ../images. * * Feel free to experiment with the code and report bugs and enhancements - * to marc@its-projects.nl **/ /* set this to true if you want to see a nicer mailboxtree */ -if (! isset($advanced_tree) || $advanced_tree=="" ) { +if (empty($advanced_tree)) { $advanced_tree=false; } -/* default SM behaviour */ -if (! isset($oldway) || $oldway=="" ) { - $oldway=false; -} if ($advanced_tree) { $xtra .= '