From 259faa3992c7aa2910c0d71d61959ff81659ea67 Mon Sep 17 00:00:00 2001 From: tassium Date: Thu, 9 Jan 2003 19:22:15 +0000 Subject: [PATCH] Fixed left_main.php to show purge link for trash if it contains folders but no messages. New function in functions/imap_mailbox.php: sqimap_mailbox_has_children(mailbox,stream) (Stream is optional) git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4405 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- ChangeLog | 4 +- functions/imap_mailbox.php | 75 +++++++++++++++++++++++++++----------- src/left_main.php | 3 +- 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 043afd6f..1925483a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,10 +15,12 @@ Version 1.4.0 RC 2 the more accurate name "login" (Plain to be implemented soon) - Fix for compose after search bug. (Closes #662346) - Improved error reporting when sending mail with SMTP. - - Changed SquirrelMail identification to use User-Agent in stead of X-Mailer. + - Changed SquirrelMail identification to use User-Agent instead of X-Mailer. - Prevent endless loop when timezone config is not found. Thanks Joshua Colson. - Fix IMAP error when returning to message from viewing image attachment. - Do more trimming to indented subjects in threadview so they don't wrap. + - New function in imap_mailbox.php: sqimap_mailbox_has_children. + - Trash folder now displays purge link in all cases. (Closes #655943) Version 1.4.0 RC 1 diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index f79aa699..ede0e493 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -107,27 +107,28 @@ function readMailboxParent($haystack, $needle) { function isBoxBelow( $box2, $box1 ) { - global $delimiter, $folder_prefix, $imap_server_type; - - if ( $imap_server_type == 'uw' ) { - $boxs = $box2; - $i = strpos( $box1, $delimiter, strlen( $folder_prefix ) ); - if ( $i === false ) { - $i = strlen( $box2 ); - } - } else { - $boxs = $box2 . $delimiter; - /* Skip next second delimiter */ - $i = strpos( $box1, $delimiter ); - $i = strpos( $box1, $delimiter, $i + 1 ); - if ( $i === false ) { - $i = strlen( $box2 ); - } else { - $i++; - } - } - - return ( substr( $box1, 0, $i ) == substr( $boxs, 0, $i ) ); +global $delimiter, $folder_prefix, $imap_server_type; + if ( $imap_server_type == 'uw' ) { + $boxs = $box2; + $i = strpos( $box1, $delimiter, strlen( $folder_prefix ) ); + if ( $i === false ) { + $i = strlen( $box2 ); + } + } else { + if (substr($box2,0,strlen($box1)) == $box1) { + return true; + } + $boxs = $box2 . $delimiter; + /* Skip next second delimiter */ + $i = strpos( $box1, $delimiter ); + $i = strpos( $box1, $delimiter, $i + 1 ); + if ( $i === false ) { + $i = strlen( $box2 ); + } else { + $i++; + } + } + return ( substr( $box1, 0, $i ) == substr( $boxs, 0, $i ) ); } /* Defines special mailboxes */ @@ -935,4 +936,36 @@ function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false) { return $mailboxes; } + +function sqimap_mailbox_has_children($mailbox='INBOX',$stream=false) { + if (!$stream) { + /* We weren't provided an IMAP stream - make one */ + global $username,$imapServerAddress, $imapPort; + $password=$_COOKIE['key']; + $stream=sqimap_login($username,$password,$imapServerAddress,$imapPort,false); + $log_this_out=true; + } + $query = 'LIST "" "' . $mailbox . '"'; + $results=sqimap_run_command($stream,$query,true,$response,$message,false); + if (isset($log_this_out)) { + /* It's our stream, and since we're done with it... */ + sqimap_logout($stream); + } + if (isset($results[0])) { + /* We got something back, let's parse the results */ + $pos = strpos($results[0], '\HasChildren'); + if ($pos === false) { + /* Folder has no children */ + return false; + } else { + /* Folder has children */ + return true; + } + } else { + /* Didn't get anything back, probably bad mailbox name */ + return false; + } + return true; +} + ?> diff --git a/src/left_main.php b/src/left_main.php index f9d3939b..a95607ad 100644 --- a/src/left_main.php +++ b/src/left_main.php @@ -92,12 +92,13 @@ function formatMailboxName($imapConnection, $box_array) { $line .= " $unseen_string"; } + /* If it's the trash folder, show a purge link when needed */ if (($move_to_trash) && ($real_box == $trash_folder)) { if (! isset($numMessages)) { $numMessages = sqimap_get_num_messages($imapConnection, $real_box); } - if ($numMessages > 0) { + if (($numMessages > 0) or (sqimap_mailbox_has_children($trash_folder))) { $urlMailbox = urlencode($real_box); $line .= "\n\n" . "  ("._("purge").")" . -- 2.25.1