X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fleft_main.php;h=b020d8eb10034226cfeec4ee87b8a5f7326780aa;hb=7d82bcebfcbc92a35bc7066d560e64d6ae786807;hp=c424a16a3f4ad93c5673487ba37395053da38d12;hpb=70bf5a7fbeab48b10a6c5bdf762f780aaaf0033c;p=squirrelmail.git diff --git a/src/left_main.php b/src/left_main.php index c424a16a..b020d8eb 100644 --- a/src/left_main.php +++ b/src/left_main.php @@ -12,12 +12,16 @@ * $Id$ */ -require_once('../src/validate.php'); -require_once('../functions/array.php'); -require_once('../functions/imap.php'); -require_once('../functions/plugin.php'); -require_once('../functions/page_header.php'); -require_once('../functions/html.php'); +/* Path for SquirrelMail required files. */ +define('SM_PATH','../'); + +/* SquirrelMail required files. */ +require_once(SM_PATH . 'include/validate.php'); +require_once(SM_PATH . 'functions/array.php'); +require_once(SM_PATH . 'functions/imap.php'); +require_once(SM_PATH . 'functions/plugin.php'); +require_once(SM_PATH . 'functions/page_header.php'); +require_once(SM_PATH . 'functions/html.php'); /* These constants are used for folder stuff. */ define('SM_BOX_UNCOLLAPSED', 0); @@ -41,23 +45,20 @@ function formatMailboxName($imapConnection, $box_array) { if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) { $mailbox = $regs[2]; } - $unseen = 0; - + $status = array(); if (($unseen_notify == 2 && $real_box == 'INBOX') || $unseen_notify == 3) { - $unseen = sqimap_unseen_messages($imapConnection, $real_box); - if ($unseen_type == 1 && $unseen > 0) { - $unseen_string = "($unseen)"; - $unseen_found = TRUE; - } else if ($unseen_type == 2) { - $numMessages = sqimap_get_num_messages($imapConnection, $real_box); - $unseen_string = "($unseen/$numMessages)"; - $unseen_found = TRUE; - } + $status = create_unseen_string($real_box, $box_array, $imapConnection, $unseen_type ); + if ($status !== false) { + list($unseen_string, $unseen) = $status; + } else { + list($unseen_string, $unseen) = array(_("Not available"),''); + } + } else { + list($unseen_string, $unseen) = array('',''); } - - $special_color = ($use_special_folder_color && isSpecialMailbox( $real_box ) ); + $special_color = ($use_special_folder_color && isSpecialMailbox($real_box)); /* Start off with a blank line. */ $line = ''; @@ -66,9 +67,10 @@ function formatMailboxName($imapConnection, $box_array) { if ($unseen > 0) { $line .= ''; } /* Create the link for this folder. */ - $line .= ''; - + if ($status !== false) { + $line .= ''; + } if ($special_color) { $line .= ""; } @@ -79,13 +81,15 @@ function formatMailboxName($imapConnection, $box_array) { } if ($special_color == TRUE) $line .= ''; - $line .= ''; + if ($status !== false) { + $line .= ''; + } /* If there are unseen message, close bolding. */ if ($unseen > 0) { $line .= ""; } /* Print unseen information. */ - if (isset($unseen_found) && $unseen_found) { + if ($unseen_string != '') { $line .= " $unseen_string"; } @@ -169,43 +173,96 @@ function create_collapse_link($boxnum) { $link = '+"; + } else { + $link .= "fold=$mailbox\">-"; + } + $link .= ''; + + /* Return the finished product. */ + return ($link); +} - /* this code checks unseen_notify settings and displays - * a total next to a colapsed folder for the amount of - * unread mail in its sunfolders - */ - $box_count = count($boxes); - $cur_box = $boxes[$boxnum]['unformatted']; - $parent_unseen = 0; - $length = strlen($cur_box); - if (($unseen_notify == 2 && $cur_box == 'INBOX') || $unseen_notify == 3) { - for ($i=0;$i<$box_count;$i++) { - $this_unseen = 0; - if ($cur_box != $boxes[$i]['unformatted']) { - if (substr($boxes[$i]['unformatted'], 0, $length) == $cur_box) { - if (!in_array('noselect', $boxes[$i]['flags'])) { - $this_unseen = sqimap_unseen_messages($imapConnection, - $boxes[$i]['unformatted']); - } - } +/** + * create_unseen_string: + * + * 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[0] unseen message string (for display) + * @return array[1] unseen message count + */ +function create_unseen_string($boxName, $boxArray, $imapConnection, $unseen_type) { + global $boxes, $unseen_type, $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'];; } - $parent_unseen += $this_unseen; + /* Add the counts for this subfolder to the total. */ + $totalUnseenCount += $subUnseenCount; + $totalMessageCount += $subMessageCount; } } - if ($parent_unseen > 0) { - $link .= "unfold=$mailbox\">+($parent_unseen)"; - } - else { - $link .= "unfold=$mailbox\">+"; - } + + /* Add the counts for all subfolders to that of the box. */ + $boxUnseenCount += $totalUnseenCount; + $boxMessageCount += $totalMessageCount; } - else { - $link .= "fold=$mailbox\">-"; + + /* 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]"; } - $link .= ''; - /* Return the finished product. */ - return ($link); + /* Set the unseen count to return to the outside world. */ + $result[1] = $boxUnseenCount; + + /* Return our happy result. */ + return ($result); } /** @@ -273,7 +330,8 @@ function listBoxes ($boxes, $j=0 ) { if (($move_to_trash) && ($mailbox == $trash_folder)) { if (! isset($numMessages)) { - $numMessages = sqimap_get_num_messages($imapConnection, $mailbox); + $status = sqimap_status_messages($imapConnection, $mailbox); + $numMessages = $status['MESSAGES']; } if ($numMessages > 0) { @@ -450,7 +508,17 @@ function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) { /* -------------------- MAIN ------------------------ */ -global $delimiter, $default_folder_prefix, $left_size; +$key = $_COOKIE['key']; +$onetimepad = $_SESSION['onetimepad']; +$username = $_SESSION['username']; +$delimiter = $_SESSION['delimiter']; + +if (isset($_GET['fold'])) { + $fold = $_GET['fold']; +} +if (isset($_GET['unfold'])) { + $unfold = $_GET['unfold']; +} // open a connection on the imap port (143) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output @@ -745,7 +813,7 @@ if ($auto_create_special && !isset($auto_create_done)) { /* Let the world know that autocreation is complete! Hurrah! */ $auto_create_done = TRUE; - session_register('auto_create_done'); + sqsession_register($auto_create_done, 'auto_create_done'); } echo "\n\n"; @@ -761,7 +829,7 @@ if ($advanced_tree) { echo '


'; } -echo "\n\n" . html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0" width="100%"' ) . +echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) . html_tag( 'tr' ) . html_tag( 'td', '', 'left' ) . '
'. _("Folders") . "
\n\n";