From 6a8e7cae9c5f0779b5aa4afb8acfc295b0d8e974 Mon Sep 17 00:00:00 2001 From: ebullient Date: Fri, 7 Feb 2003 20:34:09 +0000 Subject: [PATCH] Fix for 636577. Make subfolders of Sent/Drafts show To: instead of From: (like Sent and Drafts do already). Needs some UW verification but should work pretty well. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4508 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_mailbox.php | 55 ++++++++++++++++++++++++++--------- functions/mailbox_display.php | 9 +++--- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index 8553beca..ee1e657a 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -105,30 +105,41 @@ function readMailboxParent($haystack, $needle) { return( $ret ); } +/** + * Check if $subbox is below the specified $parentbox + */ +function isBoxBelow( $subbox, $parentbox ) { + global $delimiter, $folder_prefix, $imap_server_type; + + /* + * Eliminate the obvious mismatch, where the + * subfolder path is shorter than that of the potential parent + */ + if ( strlen($subbox) < strlen($parentbox) ) { + return false; + } -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 ) ); + $boxs = $parentbox; + $i = strpos( $subbox, $delimiter, strlen( $folder_prefix ) ); if ( $i === false ) { - $i = strlen( $box2 ); + $i = strlen( $parentbox ); } } else { - if (substr($box2,0,strlen($box1)) == $box1) { + if (substr($parentbox,0,strlen($subbox)) == $subbox) { return true; } - $boxs = $box2 . $delimiter; + $boxs = $parentbox . $delimiter; /* Skip next second delimiter */ - $i = strpos( $box1, $delimiter ); - $i = strpos( $box1, $delimiter, $i + 1 ); + $i = strpos( $subbox, $delimiter ); + $i = strpos( $subbox, $delimiter, $i + 1 ); if ( $i === false ) { - $i = strlen( $box2 ); + $i = strlen( $parentbox ); } else { $i++; } } - return ( substr( $box1, 0, $i ) == substr( $boxs, 0, $i ) ); + return ( substr( $subbox, 0, $i ) == substr( $boxs, 0, $i ) ); } /* Defines special mailboxes */ @@ -137,9 +148,7 @@ function isSpecialMailbox( $box ) { $move_to_trash, $move_to_sent, $save_as_draft; $ret = ( (strtolower($box) == 'inbox') || - ( $move_to_trash && $trash_folder && isBoxBelow( $box, $trash_folder )) || - ( $move_to_sent && $sent_folder && isBoxBelow( $box, $sent_folder )) || - ($save_as_draft && $box == $draft_folder ) ); + isTrashMailbox($box) || isSentMailbox($box) || isDraftMailbox($box) ); if ( !$ret ) { $ret = do_hook_function( 'special_mailbox', $box ); @@ -147,6 +156,24 @@ function isSpecialMailbox( $box ) { return $ret; } +function isTrashMailbox ($box) { + global $trash_folder, $move_to_trash; + return $move_to_trash && $trash_folder && + ( $box == $trash_folder || isBoxBelow($box, $trash_folder) ); +} + +function isSentMailbox($box) { + global $sent_folder, $move_to_sent; + return $move_to_sent && $sent_folder && + ( $box == $sent_folder || isBoxBelow($box, $sent_folder) ); +} + +function isDraftMailbox($box) { + global $draft_folder, $save_as_draft; + return $save_as_draft && + ( $box == $draft_folder || isBoxBelow($box, $draft_folder) ); +} + /* Expunges a mailbox */ function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, $id='') { global $uid_support; diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index f5cdda61..4174bbc1 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -1247,16 +1247,15 @@ function getEndMessage($start_msg, $show_num, $num_msgs) { } function handleAsSent($mailbox) { - global $sent_folder, $draft_folder, $handleAsSent_result; - + global $handleAsSent_result; + /* First check if this is the sent or draft folder. */ - $handleAsSent_result = (($mailbox == $sent_folder) - || ($mailbox == $draft_folder)); + $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox); /* Then check the result of the handleAsSent hook. */ do_hook('check_handleAsSent_result', $mailbox); /* And return the result. */ - return ($handleAsSent_result); + return $handleAsSent_result; } ?> -- 2.25.1