/**
* imap_mailbox.php
*
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This impliments all functions that manipulate mailboxes
return( $ret );
}
-
-function isBoxBelow( $box2, $box1 ) {
+/**
+ * Check if $subbox is below the specified $parentbox
+ */
+function isBoxBelow( $subbox, $parentbox ) {
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++;
- }
+ /*
+ * Eliminate the obvious mismatch, where the
+ * subfolder path is shorter than that of the potential parent
+ */
+ if ( strlen($subbox) < strlen($parentbox) ) {
+ return false;
}
- return ( substr( $box1, 0, $i ) == substr( $boxs, 0, $i ) );
+ if ( $imap_server_type == 'uw' ) {
+ $boxs = $parentbox;
+ $i = strpos( $subbox, $delimiter, strlen( $folder_prefix ) );
+ if ( $i === false ) {
+ $i = strlen( $parentbox );
+ }
+ } else {
+ if (substr($parentbox,0,strlen($subbox)) == $subbox) {
+ return true;
+ }
+ $boxs = $parentbox . $delimiter;
+ /* Skip next second delimiter */
+ $i = strpos( $subbox, $delimiter );
+ $i = strpos( $subbox, $delimiter, $i + 1 );
+ if ( $i === false ) {
+ $i = strlen( $parentbox );
+ } else {
+ $i++;
+ }
+ }
+ return ( substr( $subbox, 0, $i ) == substr( $boxs, 0, $i ) );
}
/* Defines special mailboxes */
$move_to_trash, $move_to_sent, $save_as_draft;
$ret = ( (strtolower($box) == 'inbox') ||
- ( $move_to_trash && isBoxBelow( $box, $trash_folder ) ) ||
- ( $move_to_sent && 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 );
}
-
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;
return $mailboxes;
}
+
?>