From 1c52ba77ca7d72fd34feeb6b338d3e60b6083f07 Mon Sep 17 00:00:00 2001 From: philippe_mingo Date: Fri, 11 Jan 2002 23:28:12 +0000 Subject: [PATCH 1/1] In order to make sent_subfolders work I had to change a lot of code. I may have messed up something in the process so PLEASE TEST THIS CARFULLY. In my system (that uses uw) it almost work. The only thing left to be done is to organize left main in such a way that sent subfolders are placed to the top. I've replaced some spare code with a few new functions. sqimap_mailbox_rename and isSpecialMailbox are the most interesting in other proceses. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2119 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_mailbox.php | 58 +++++++++-- functions/page_header.php | 1 - plugins/sent_subfolders/setup.php | 65 +++++++----- src/folders.php | 162 ++++++++++++++--------------- src/folders_create.php | 83 +++++++-------- src/folders_delete.php | 163 ++++++++++++++---------------- src/folders_rename_do.php | 88 +++++----------- src/folders_rename_getname.php | 86 +++++++--------- src/left_main.php | 82 +++++++-------- 9 files changed, 373 insertions(+), 415 deletions(-) diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index a46ccaed..0a5e9b8a 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -137,7 +137,49 @@ function sqimap_mailbox_is_subscribed($imap_stream, $folder) return false; } +/* + Renames a mailbox +*/ +function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) { + if ( $old_name <> $new_name ) { + + global $delimiter; + + if ( substr( $old_name, -1 ) == $delimiter ) { + $old_name = substr( $old_name, 0, strlen( $old_name ) - 1 ); + $new_name = substr( $new_name, 0, strlen( $new_name ) - 1 ); + $postfix = $delimiter; + $boxes = sqimap_mailbox_list($imap_stream); + } else { + $postfix = ''; + $boxes = FALSE; + } + + $cmd = sqimap_session_id() . " RENAME \"" . quoteIMAP($old_name) . "\" \"" . + quoteIMAP($new_name) . "\"\r\n"; + fputs($imap_stream, $cmd); + $data = sqimap_read_data($imap_stream, sqimap_session_id(), + TRUE, $response, $message); + sqimap_unsubscribe($imap_stream, $old_name.$postfix); + sqimap_subscribe($imap_stream, $new_name.$postfix); + + if ( $boxes ) { + // Sub-unsub subfolders + $l = strlen( $old_name ) + 1; + $p = 'unformatted'; + foreach ( $boxes as $box ) { + if ( substr( $box[$p], 0, $l ) == $old_name . $delimiter ) { + sqimap_unsubscribe($imap_stream, $box[$p]); + sqimap_subscribe($imap_stream, + $new_name . $delimiter . substr( $box[$p], $l ) ); + } + } + } + + } + +} /****************************************************************************** ** Formats a mailbox into 4 parts for the $boxes array @@ -481,14 +523,14 @@ function sqimap_mailbox_list_all ($imap_stream) $read_ary[$i], $regs)) { $i ++; $read_ary[$i] = $regs[1] . '"' . - addslashes(trim($read_ary[$i])) . - '"' . $regs[2]; + addslashes(trim($read_ary[$i])) . + '"' . $regs[2]; } if (substr ($read_ary[$i], 0, $lsid) != $ssid ) { /* Store the raw IMAP reply */ $boxes[$g]["raw"] = $read_ary[$i]; - + /* Count number of delimiters ($delimiter) in folder name */ $mailbox = find_mailbox_name($read_ary[$i]); $dm_count = substr_count($mailbox, $delimiter); @@ -534,9 +576,9 @@ function sqimap_mailbox_list_all ($imap_stream) if (isset($read_mlbx[1]) && ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", $read_mlbx[0], $regs)) { - $read_mlbx[0] = $regs[1] . '"' . - addslashes(trim($read_mlbx[1])) . - '"' . $regs[2]; + $read_mlbx[0] = $regs[1] . '"' . + addslashes(trim($read_mlbx[1])) . + '"' . $regs[2]; } $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+1); @@ -544,7 +586,7 @@ function sqimap_mailbox_list_all ($imap_stream) $flags = str_replace('\\', '', $flags); $flags = trim(strtolower($flags)); if ($flags) { - $boxes[$g]['flags'] = explode(" ", $flags); + $boxes[$g]['flags'] = explode(' ', $flags); } else { $boxes[$g]['flags'] = array(); @@ -553,7 +595,7 @@ function sqimap_mailbox_list_all ($imap_stream) $g++; } if(is_array($boxes)) { - $boxes = ary_sort ($boxes, "unformatted", 1); + $boxes = ary_sort ($boxes, 'unformatted', 1); } return $boxes; diff --git a/functions/page_header.php b/functions/page_header.php index 60c8ec7a..ef84f2d2 100644 --- a/functions/page_header.php +++ b/functions/page_header.php @@ -81,7 +81,6 @@ function checkForm() { i++; } if( pos >= 0 ) { - // document.write( "Si tio" ); document.forms[i-1].elements[pos].focus(); } diff --git a/plugins/sent_subfolders/setup.php b/plugins/sent_subfolders/setup.php index 92f66532..28870477 100644 --- a/plugins/sent_subfolders/setup.php +++ b/plugins/sent_subfolders/setup.php @@ -149,40 +149,51 @@ function sent_subfolders_update_sentfolder() { global $username, $data_dir, $key, $imapServerAddress, $imapPort; global $use_sent_subfolders, $move_to_sent; - if ($use_sent_subfolders && $move_to_sent) { + if ($use_sent_subfolders || $move_to_sent) { $year = date('Y'); $month = date('m'); $quarter = sent_subfolder_getQuarter($month); + /* + Regarding the structure we've got three main possibilities. + One sent holder. level 0. + Multiple year holders with messages in it. level 1. + Multiple year folders with holders in it. level 2. + */ switch ($sent_subfolders_setting) { - case SMPREF_SENT_SUBFOLDERS_YEARLY: - $sent_subfolder = $sent_subfolders_base - . $delimiter . $year; - $year_folder = $sent_subfolder; - break; - case SMPREF_SENT_SUBFOLDERS_QUARTERLY: - $sent_subfolder = $sent_subfolders_base - . $delimiter . $year - . $delimiter . $quarter; - $year_folder = $sent_subfolders_base - . $delimiter . $year; - break; - case SMPREF_SENT_SUBFOLDERS_MONTHLY: - $sent_subfolder = $sent_subfolders_base - . $delimiter . $year - . $delimiter . $month; - $year_folder = $sent_subfolders_base - . $delimiter . $year; - break; - case SMPREF_SENT_SUBFOLDERS_DISABLED: - default: - $sent_subfolder = $sent_folder; - $year_folder = $sent_folder; + case SMPREF_SENT_SUBFOLDERS_YEARLY: + $level = 1; + $sent_subfolder = $sent_subfolders_base + . $year; + $year_folder = $sent_subfolder; + break; + case SMPREF_SENT_SUBFOLDERS_QUARTERLY: + $level = 2; + $sent_subfolder = $sent_subfolders_base + . $year + . $delimiter . $quarter; + $year_folder = $sent_subfolders_base + . $delimiter . $year; + break; + case SMPREF_SENT_SUBFOLDERS_MONTHLY: + $level = 2; + $sent_subfolder = $sent_subfolders_base + . $year + . $delimiter . $month; + $year_folder = $sent_subfolders_base + . $delimiter . $year; + break; + case SMPREF_SENT_SUBFOLDERS_DISABLED: + default: + $level = 0; + $sent_subfolder = $sent_folder; + $year_folder = $sent_folder; } /* If this folder is NOT the current sent folder, update stuff. */ if ($sent_subfolder != $sent_folder) { /* First, update the sent folder. */ + setPref($data_dir, $username, 'sent_folder', $sent_subfolder); setPref($data_dir, $username, 'move_to_sent', SMPREF_ON); $sent_folder = $sent_subfolder; @@ -196,7 +207,7 @@ function sent_subfolders_update_sentfolder() { /* Auto-create the year folder, if it does not yet exist. */ if (!sqimap_mailbox_exists($ic, $year_folder)) { - sqimap_mailbox_create($ic, $year_folder, ''); + sqimap_mailbox_create($ic, $year_folder, ($level==1)?'':'noselect'); } else if (!sqimap_mailbox_is_subscribed($ic, $year_folder)) { sqimap_subscribe($ic, $year_folder); } @@ -204,8 +215,8 @@ function sent_subfolders_update_sentfolder() { /* Auto-create the subfolder, if it does not yet exist. */ if (!sqimap_mailbox_exists($ic, $sent_folder)) { sqimap_mailbox_create($ic, $sent_folder, ''); - } else if (!sqimap_mailbox_is_subscribed($ic, $sent_folder)) { - sqimap_subscribe($ic, $sent_folder); + } else if (!sqimap_mailbox_is_subscribed($ic, $sent_subfolder)) { + sqimap_subscribe($ic, $sent_subfolder); } /* Close the imap connection. */ diff --git a/src/folders.php b/src/folders.php index eb7d634d..9adb36b0 100644 --- a/src/folders.php +++ b/src/folders.php @@ -13,22 +13,6 @@ * $Id$ */ -/*****************************************************************/ -/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ -/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ -/*** + Base level indent should begin at left margin, as ***/ -/*** the require_once below looks. ***/ -/*** + All identation should consist of four space blocks ***/ -/*** + Tab characters are evil. ***/ -/*** + all comments should use "slash-star ... star-slash" ***/ -/*** style -- no pound characters, no slash-slash style ***/ -/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ -/*** ALWAYS USE { AND } CHARACTERS!!! ***/ -/*** + Please use ' instead of ", when possible. Note " ***/ -/*** should always be used in _( ) function calls. ***/ -/*** Thank you for your help making the SM code more readable. ***/ -/*****************************************************************/ - require_once('../src/validate.php'); require_once('../functions/imap.php'); require_once('../functions/array.php'); @@ -49,11 +33,11 @@ displayPageHeader($color, 'None'); \n"; - echo " \n"; +if ((isset($success) && $success) || + (isset($sent_create) && $sent_create == 'true') || + (isset($trash_create) && $trash_create == 'true')) { + echo "\n" . + " \n"; - echo "
\n"; if ($success == "subscribe") { echo "" . _("Subscribed successfully!") . "
"; } else if ($success == "unsubscribe") { @@ -66,9 +50,9 @@ if ((isset($success) && $success) || echo "" . _("Renamed successfully!") . "
"; } - echo " " . _("refresh folder list") . ""; - echo "

\n"; + echo " " . _("refresh folder list") . "". + " \n"; + "
\n"; } else { echo "
"; } @@ -76,17 +60,16 @@ $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, $boxes = sqimap_mailbox_list($imapConnection); /** CREATING FOLDERS **/ -echo "\n"; - -echo ""; -echo "
"; -echo _("Create Folder"); -echo "
"; -echo "
\n"; -echo "
\n"; -echo _("as a subfolder of"); -echo "
"; -echo "\n". + "". + "\n"; echo "\n"; /** RENAMING FOLDERS **/ -echo ""; -echo "". + "\n"; + echo "\n". + "\n". + "\n"; } else { echo _("No folders found") . "

"; } @@ -159,25 +145,27 @@ echo ""; echo "
". + _("Create Folder"). + "
". + "\n". + "
\n". + _("as a subfolder of"). + "
". + "  "; echo _("Let this folder contain subfolders"); echo "
"; -} +} echo "\n"; echo "
 
"; -echo _("Rename a Folder"); -echo "
"; +echo "
". + _("Rename a Folder"). + "
"; if ($count_special_folders < count($boxes)) { - echo "
\n"; - echo "\n"; for ($i = 0; $i < count($boxes); $i++) { $use_folder = true; - if ((strtolower($boxes[$i]["unformatted"]) != "inbox") && - ($boxes[$i]["unformatted"] != $trash_folder) && - ($boxes[$i]["unformatted"] != $sent_folder) && - ($boxes[$i]["unformatted"] != $draft_folder)) { - $box = $boxes[$i]["unformatted-dm"]; - $box2 = str_replace(' ', ' ', $boxes[$i]["unformatted-disp"]); - if (strtolower($imap_server_type) != "courier" || strtolower($box) != "inbox.trash") - echo "\n"; + } } } - echo "\n"; - echo "\n"; - echo "
"; $count_special_folders = 0; - $num_max = 1; - if (strtolower($imap_server_type) == "courier" || $move_to_trash) - $num_max++; - if ($move_to_sent) - $num_max++; - if ($save_as_draft) - $num_max++; - +$num_max = 1; +if (strtolower($imap_server_type) == "courier" || $move_to_trash) { + $num_max++; +} +if ($move_to_sent) { + $num_max++; +} +if ($save_as_draft) { + $num_max++; +} for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) { - if (strtolower($boxes[$p]["unformatted"]) == "inbox") + if (strtolower($boxes[$p]['unformatted']) == 'inbox') $count_special_folders++; - else if (strtolower($imap_server_type) == "courier" && - strtolower($boxes[$p]["unformatted"]) == "inbox.trash") + else if (strtolower($imap_server_type) == 'courier' && + strtolower($boxes[$p]['unformatted']) == 'inbox.trash') $count_special_folders++; - else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder) + else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder) $count_special_folders++; - else if ($boxes[$p]["unformatted"] == $sent_folder && $sent_folder) + else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder) $count_special_folders++; - else if ($boxes[$p]["unformatted"] == $draft_folder && $draft_folder) + else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder) $count_special_folders++; } @@ -186,15 +174,15 @@ if ($count_special_folders < count($boxes)) { echo "\n"; @@ -290,4 +278,4 @@ do_hook("folders_bottom"); sqimap_logout($imapConnection); ?> - + \ No newline at end of file diff --git a/src/folders_create.php b/src/folders_create.php index 43beb9ed..c0b4de48 100644 --- a/src/folders_create.php +++ b/src/folders_create.php @@ -12,57 +12,42 @@ * $Id$ */ -/*****************************************************************/ -/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ -/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ -/*** + Base level indent should begin at left margin, as ***/ -/*** the require_once below looks. ***/ -/*** + All identation should consist of four space blocks ***/ -/*** + Tab characters are evil. ***/ -/*** + all comments should use "slash-star ... star-slash" ***/ -/*** style -- no pound characters, no slash-slash style ***/ -/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ -/*** ALWAYS USE { AND } CHARACTERS!!! ***/ -/*** + Please use ' instead of ", when possible. Note " ***/ -/*** should always be used in _( ) function calls. ***/ -/*** Thank you for your help making the SM code more readable. ***/ -/*****************************************************************/ - require_once('../src/validate.php'); require_once('../functions/imap.php'); require_once('../functions/display_messages.php'); - $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); - global $delimiter; - - if (strpos($folder_name, "\"") || strpos($folder_name, "\\") || - strpos($folder_name, "'") || strpos($folder_name, "$delimiter")) { - echo ""; - plain_error_message(_("Illegal folder name. Please select a different name.")."
"._("Click here to go back").".", $color); - sqimap_logout($imapConnection); - exit; - } - - if (isset($contain_subs) && $contain_subs == true) - $folder_name = "$folder_name$delimiter"; - - if ($folder_prefix && (substr($folder_prefix, -1) != $delimiter)) { - $folder_prefix = $folder_prefix . $delimiter; - } - if ($folder_prefix && (substr($subfolder, 0, strlen($folder_prefix)) != $folder_prefix)){ - $subfolder_orig = $subfolder; - $subfolder = $folder_prefix . $subfolder; - } else { - $subfolder_orig = $subfolder; - } - - if (trim($subfolder_orig) == '') { - sqimap_mailbox_create ($imapConnection, $folder_prefix.$folder_name, ""); - } else { - sqimap_mailbox_create ($imapConnection, $subfolder.$delimiter.$folder_name, ""); - } - - $location = get_location(); - header ("Location: $location/folders.php?success=create"); - sqimap_logout($imapConnection); +$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); +global $delimiter; + +if (strpos($folder_name, "\"") || strpos($folder_name, "\\") || + strpos($folder_name, "'") || strpos($folder_name, "$delimiter")) { + echo ""; + plain_error_message(_("Illegal folder name. Please select a different name.")."
"._("Click here to go back").".", $color); + sqimap_logout($imapConnection); + exit; +} + +if (isset($contain_subs) && $contain_subs ) { + $folder_name = "$folder_name$delimiter"; +} + +if ($folder_prefix && (substr($folder_prefix, -1) != $delimiter)) { + $folder_prefix = $folder_prefix . $delimiter; +} +if ($folder_prefix && (substr($subfolder, 0, strlen($folder_prefix)) != $folder_prefix)){ + $subfolder_orig = $subfolder; + $subfolder = $folder_prefix . $subfolder; +} else { + $subfolder_orig = $subfolder; +} + +if (trim($subfolder_orig) == '') { + sqimap_mailbox_create ($imapConnection, $folder_prefix.$folder_name, ''); +} else { + sqimap_mailbox_create ($imapConnection, $subfolder.$delimiter.$folder_name, ''); +} + +$location = get_location(); +header ("Location: $location/folders.php?success=create"); +sqimap_logout($imapConnection); ?> diff --git a/src/folders_delete.php b/src/folders_delete.php index de432553..4ae96f80 100644 --- a/src/folders_delete.php +++ b/src/folders_delete.php @@ -12,108 +12,93 @@ * $Id$ */ -/*****************************************************************/ -/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ -/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ -/*** + Base level indent should begin at left margin, as ***/ -/*** the require_once below looks. ***/ -/*** + All identation should consist of four space blocks ***/ -/*** + Tab characters are evil. ***/ -/*** + all comments should use "slash-star ... star-slash" ***/ -/*** style -- no pound characters, no slash-slash style ***/ -/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ -/*** ALWAYS USE { AND } CHARACTERS!!! ***/ -/*** + Please use ' instead of ", when possible. Note " ***/ -/*** should always be used in _( ) function calls. ***/ -/*** Thank you for your help making the SM code more readable. ***/ -/*****************************************************************/ require_once('../src/validate.php'); require_once('../functions/imap.php'); require_once('../functions/array.php'); require_once('../functions/tree.php'); - /* - * Incoming values: - * $mailbox - selected mailbox from the form - */ - - $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); - $boxes = sqimap_mailbox_list ($imap_stream); - global $delimiter; - - if (substr($mailbox, -1) == $delimiter) - $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1); - else - $mailbox_no_dm = $mailbox; - - /** lets see if we CAN move folders to the trash.. otherwise, +/* +* Incoming values: +* $mailbox - selected mailbox from the form +*/ + +$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); +$boxes = sqimap_mailbox_list ($imap_stream); +global $delimiter; + +if (substr($mailbox, -1) == $delimiter) + $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1); +else + $mailbox_no_dm = $mailbox; + +/** lets see if we CAN move folders to the trash.. otherwise, ** just delete them **/ - // Courier IMAP doesn't like subfolders of Trash - if (strtolower($imap_server_type) == "courier") { - $can_move_to_trash = false; - } +// Courier IMAP doesn't like subfolders of Trash +if (strtolower($imap_server_type) == "courier") { + $can_move_to_trash = false; +} - // If it's already a subfolder of trash, we'll have to delete it - else if(eregi("^".$trash_folder.".+", $mailbox)) { +// If it's already a subfolder of trash, we'll have to delete it +else if(eregi("^".$trash_folder.".+", $mailbox)) { - $can_move_to_trash = false; + $can_move_to_trash = false; - } +} - // Otherwise, check if trash folder exits and support sub-folders - else { - for ($i = 0; $i < count($boxes); $i++) { - if ($boxes[$i]["unformatted"] == $trash_folder) { +// Otherwise, check if trash folder exits and support sub-folders +else { + for ($i = 0; $i < count($boxes); $i++) { + if ($boxes[$i]["unformatted"] == $trash_folder) { $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']); - } - } - } - - /** First create the top node in the tree **/ - for ($i = 0;$i < count($boxes);$i++) { - if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) { - $foldersTree[0]["value"] = $mailbox; - $foldersTree[0]["doIHaveChildren"] = false; - continue; - } - } - // Now create the nodes for subfolders of the parent folder - // You can tell that it is a subfolder by tacking the mailbox delimiter - // on the end of the $mailbox string, and compare to that. - $j = 0; - for ($i = 0;$i < count($boxes);$i++) { - if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) { - addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree); - } - } + } + } +} + +/** First create the top node in the tree **/ +for ($i = 0;$i < count($boxes);$i++) { + if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) { + $foldersTree[0]["value"] = $mailbox; + $foldersTree[0]["doIHaveChildren"] = false; + continue; + } +} +// Now create the nodes for subfolders of the parent folder +// You can tell that it is a subfolder by tacking the mailbox delimiter +// on the end of the $mailbox string, and compare to that. +$j = 0; +for ($i = 0;$i < count($boxes);$i++) { + if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) { + addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree); + } +} // simpleWalkTreePre(0, $foldersTree); - /** Lets start removing the folders and messages **/ - if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/ - walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox); - walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree); - } else { /** if they do NOT wish to move messages to the trash (or cannot)**/ - walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree); - } - - /** Log out this session **/ - sqimap_logout($imap_stream); - - $location = get_location(); - header ("Location: $location/folders.php?success=delete"); - /* - echo "


"; - echo _("Folder Deleted!"); - echo "

"; - echo _("The folder has been successfully deleted."); - echo "
"; - echo _("Click here"); - echo " "; - echo _("to continue."); - echo "
"; - - echo ""; - */ +/** Lets start removing the folders and messages **/ +if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/ + walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox); + walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree); +} else { /** if they do NOT wish to move messages to the trash (or cannot)**/ + walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree); +} + +/** Log out this session **/ +sqimap_logout($imap_stream); + +$location = get_location(); +header ("Location: $location/folders.php?success=delete"); +/* +echo "


"; +echo _("Folder Deleted!"); +echo "

"; +echo _("The folder has been successfully deleted."); +echo "
"; +echo _("Click here"); +echo " "; +echo _("to continue."); +echo "
"; + +echo ""; +*/ ?> diff --git a/src/folders_rename_do.php b/src/folders_rename_do.php index 9d69ba99..8e03d83b 100644 --- a/src/folders_rename_do.php +++ b/src/folders_rename_do.php @@ -6,82 +6,44 @@ * Copyright (c) 1999-2002 The SquirrelMail Project Team * Licensed under the GNU GPL. For full terms see the file COPYING. * - * Does the actual renaming of files on the IMAP server. + * Does the actual renaming of files on the IMAP server. * Called from the folders.php * * $Id$ */ -/*****************************************************************/ -/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ -/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ -/*** + Base level indent should begin at left margin, as ***/ -/*** the require_once below looks. ***/ -/*** + All identation should consist of four space blocks ***/ -/*** + Tab characters are evil. ***/ -/*** + all comments should use "slash-star ... star-slash" ***/ -/*** style -- no pound characters, no slash-slash style ***/ -/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ -/*** ALWAYS USE { AND } CHARACTERS!!! ***/ -/*** + Please use ' instead of ", when possible. Note " ***/ -/*** should always be used in _( ) function calls. ***/ -/*** Thank you for your help making the SM code more readable. ***/ -/*****************************************************************/ +global $delimiter, $base_uri; require_once('../src/validate.php'); require_once('../functions/imap.php'); - if($old_name == $new_name) { - $location = get_location(); - header ("Location: $location/folders.php"); - exit; - } +if ($old_name <> $new_name) { - $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); - global $delimiter; + $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); - if (strpos($orig, $delimiter)) - $old_dir = substr($orig, 0, strrpos($orig, $delimiter)); - else - $old_dir = ""; + if (strpos($orig, $delimiter)) { + $old_dir = substr($orig, 0, strrpos($orig, $delimiter)); + } else { + $old_dir = ''; + } - if ($old_dir != "") - $newone = "$old_dir$delimiter$new_name"; - else - $newone = "$new_name"; + if ($old_dir != '') { + $newone = $old_dir . $delimiter . $new_name; + } else { + $newone = $new_name; + } - $cmd = sqimap_session_id() . " RENAME \"" . quoteIMAP($orig) . "\" \"" . - quoteIMAP($newone) . "\"\r\n"; - fputs ($imapConnection, $cmd); - $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b); + // Renaming a folder doesn't renames the folder but leaves you unsubscribed + // at least on Cyrus IMAP servers. + if (isset($isfolder)) { + $newone = $newone.$delimiter; + $orig = $orig.$delimiter; + } + sqimap_mailbox_rename( $imapConnection, $orig, $newone ); - // Renaming a folder doesn't renames the folder but leaves you unsubscribed - // at least on Cyrus IMAP servers. - if (isset($isfolder)) { - $newone = $newone.$delimiter; - $orig = $orig.$delimiter; - } - sqimap_unsubscribe($imapConnection, $orig); - sqimap_subscribe($imapConnection, $newone); + // Log out this session + sqimap_logout($imapConnection); - fputs ($imapConnection, sqimap_session_id() . " LIST \"\" \"" . quoteIMAP($newone) . - "*\"\r\n"); - $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b); - for ($i=0; $i < count($data); $i++) - { - $name = find_mailbox_name($data[$i]); - - if ($name != $newone) // don't try to resubscribe when renaming ab to abc - { - sqimap_unsubscribe($imapConnection, $name); - $name = substr($name, strlen($orig)); - $name = $newone . $name; - sqimap_subscribe($imapConnection, $name); - } - } - - /** Log out this session **/ - sqimap_logout($imapConnection); - $location = get_location(); - header ("Location: $location/folders.php?success=rename"); +} +header ('Location: ' . $base_uri . 'src/folders.php'); ?> diff --git a/src/folders_rename_getname.php b/src/folders_rename_getname.php index c5a85c99..7896fa5b 100644 --- a/src/folders_rename_getname.php +++ b/src/folders_rename_getname.php @@ -12,58 +12,48 @@ * $Id$ */ -/*****************************************************************/ -/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ -/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ -/*** + Base level indent should begin at left margin, as ***/ -/*** the require_once below looks. ***/ -/*** + All identation should consist of four space blocks ***/ -/*** + Tab characters are evil. ***/ -/*** + all comments should use "slash-star ... star-slash" ***/ -/*** style -- no pound characters, no slash-slash style ***/ -/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ -/*** ALWAYS USE { AND } CHARACTERS!!! ***/ -/*** + Please use ' instead of ", when possible. Note " ***/ -/*** should always be used in _( ) function calls. ***/ -/*** Thank you for your help making the SM code more readable. ***/ -/*****************************************************************/ +global $delimiter; require_once('../src/validate.php'); require_once('../functions/imap.php'); - $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); +$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); - global $delimiter; - if (substr($old, strlen($old) - strlen($delimiter)) == $delimiter) { - $isfolder = true; - $old = substr($old, 0, strlen($old) - 1); - } - - if (strpos($old, $delimiter)) { - $old_name = substr($old, strrpos($old, $delimiter)+1, strlen($old)); - $old_parent = substr($old, 0, strrpos($old, $delimiter)); - } else { - $old_name = $old; - $old_parent = ""; - } +echo $old; - displayPageHeader($color, 'None'); - echo "
"; - echo ""; - echo ""; - echo "
"; - echo _("Rename a folder"); - echo "
"; - echo "
\n"; - echo _("New name:"); - echo "
$old_parent .
\n"; - if (isset($isfolder)) - echo ""; - printf("\n", $old); - printf("\n", $old_name); - echo "\n"; - echo "

"; +if (substr($old, strlen($old) - strlen($delimiter)) == $delimiter) { + $isfolder = TRUE; + $old = substr($old, 0, strlen($old) - 1); +} else { + $isfolder = FALSE; +} - /** Log out this session **/ - sqimap_logout($imapConnection); -?> +if (strpos($old, $delimiter)) { + $old_name = substr($old, strrpos($old, $delimiter)+1, strlen($old)); + $old_parent = substr($old, 0, strrpos($old, $delimiter)); +} else { + $old_name = $old; + $old_parent = ''; +} + +displayPageHeader($color, 'None'); +echo "
". + "". + "". + "
". + _("Rename a folder"). + "
". + "
\n". + _("New name:"). + "
$old_parent $delimiter
\n"; +if ( $isfolder ) { + echo ""; +} +printf("\n", $old); +printf("\n", $old_name); +echo "\n". + "

"; + +/** Log out this session **/ +sqimap_logout($imapConnection); +?> \ No newline at end of file diff --git a/src/left_main.php b/src/left_main.php index 427d6fc4..eb4b5379 100644 --- a/src/left_main.php +++ b/src/left_main.php @@ -10,23 +10,7 @@ * available, and has cookie information. * * $Id$ - / - -/*****************************************************************/ -/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ -/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ -/*** + Base level indent should begin at left margin, as ***/ -/*** the require_once below looks. ***/ -/*** + All identation should consist of four space blocks ***/ -/*** + Tab characters are evil. ***/ -/*** + all comments should use "slash-star ... star-slash" ***/ -/*** style -- no pound characters, no slash-slash style ***/ -/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ -/*** ALWAYS USE { AND } CHARACTERS!!! ***/ -/*** + Please use ' instead of ", when possible. Note " ***/ -/*** should always be used in _( ) function calls. ***/ -/*** Thank you for your help making the SM code more readable. ***/ -/*****************************************************************/ + */ require_once('../src/validate.php'); require_once('../functions/array.php'); @@ -40,7 +24,25 @@ define('SM_BOX_COLLAPSED', 1); /* --------------------- FUNCTIONS ------------------------- */ +function isSpecialMailbox( $box ) { + + global $trash_folder, $sent_folder, $draft_folder, + $move_to_trash, $move_to_sent, $save_as_draft; + + $ret = ( (strtolower($box) == 'inbox') || + (($box == $trash_folder) && + ($move_to_trash)) || + ((substr( $sent_folder, 0, strlen( $box ) ) == $box) && + ($move_to_sent)) || + (($box == $draft_folder) && + ($save_as_draft)) ); + + return( $ret ); + +} + function formatMailboxName($imapConnection, $box_array) { + global $folder_prefix, $trash_folder, $sent_folder; global $color, $move_to_sent, $move_to_trash; global $unseen_notify, $unseen_type, $collapse_folders; @@ -71,15 +73,7 @@ function formatMailboxName($imapConnection, $box_array) { } } - $special_color = false; - if ($use_special_folder_color) { - if ((strtolower($real_box) == 'inbox') - || (($real_box == $trash_folder) && ($move_to_trash)) - || (($real_box == $sent_folder) && ($move_to_sent)) - || (($real_box == $draft_folder) && ($save_as_draft))) { - $special_color = true; - } - } + $special_color = ($use_special_folder_color && isSpecialMailbox( $real_box ) ); /* Start off with a blank line. */ $line = ''; @@ -89,8 +83,9 @@ function formatMailboxName($imapConnection, $box_array) { /* Crate the link for this folder. */ $line .= ""; - if ($special_color == true) + if ($special_color) { $line .= ""; + } $line .= str_replace(' ',' ',$mailbox); if ($special_color == true) $line .= ""; @@ -104,7 +99,7 @@ function formatMailboxName($imapConnection, $box_array) { $line .= " $unseen_string"; } - if (($move_to_trash == true) && ($real_box == $trash_folder)) { + if (($move_to_trash) && ($real_box == $trash_folder)) { if (! isset($numMessages)) { $numMessages = sqimap_get_num_messages($imapConnection, $real_box); } @@ -134,7 +129,7 @@ function compute_folder_children(&$parbox, $boxcount) { $parbox_name = $boxes[$parbox]['unformatted']; /* 'Initialize' this parent box to childless. */ - $boxes[$parbox]['parent'] = false; + $boxes[$parbox]['parent'] = FALSE; /* Compute the collapse status for this box. */ if( isset($collapse_folders) && $collapse_folders ) { @@ -146,25 +141,22 @@ function compute_folder_children(&$parbox, $boxcount) { $boxes[$parbox]['collapse'] = $collapse; /* Otherwise, get the name of the next box. */ - if (isset($boxes[$nextbox]['unformatted'])) + if (isset($boxes[$nextbox]['unformatted'])) { $nextbox_name = $boxes[$nextbox]['unformatted']; - else + } 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; + $boxes[$parbox]['parent'] = TRUE; /* Compute the visiblity of this box. */ - if ($boxes[$parbox]['visible'] && - ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED)) { - $boxes[$nextbox]['visible'] = true; - } else { - $boxes[$nextbox]['visible'] = false; - } + $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] && + ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED)); /* Compute the visibility of any child boxes. */ compute_folder_children($nextbox, $boxcount); @@ -317,7 +309,7 @@ while ($curbox < $boxcount) { compute_folder_children($curbox, $boxcount); } -for ($i = 0;$i < count($boxes); $i++) { +for ($i = 0; $i < count($boxes); $i++) { if ( $boxes[$i]['visible'] ) { $mailbox = $boxes[$i]['formatted']; $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1; @@ -333,11 +325,15 @@ for ($i = 0;$i < count($boxes); $i++) { $line = "$prefix"; /* Add the folder name and link. */ - if (! isset($color[15])) { + if (! isset($color[15])) { $color[15] = $color[6]; - } + } if (in_array('noselect', $boxes[$i]['flags'])) { - $line .= ""; + if( isSpecialMailbox( $boxes[$i]['unformatted']) ) { + $line .= ""; + } else { + $line .= ""; + } if (ereg("^( *)([^ ]*)", $mailbox, $regs)) { $mailbox = str_replace(' ','',$mailbox); $line .= str_replace(' ', ' ', $mailbox); @@ -360,4 +356,4 @@ do_hook('left_main_after'); echo "\n"; -?> +?> \ No newline at end of file -- 2.25.1