| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * folders_rename_do.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2004 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * Does the actual renaming of files on the IMAP server. |
| 10 | * Called from the folders.php |
| 11 | * |
| 12 | * $Id$ |
| 13 | * @package squirrelmail |
| 14 | */ |
| 15 | |
| 16 | /** Path for SquirrelMail required files. */ |
| 17 | define('SM_PATH','../'); |
| 18 | |
| 19 | /* SquirrelMail required files. */ |
| 20 | require_once(SM_PATH . 'include/validate.php'); |
| 21 | require_once(SM_PATH . 'functions/global.php'); |
| 22 | require_once(SM_PATH . 'functions/imap.php'); |
| 23 | require_once(SM_PATH . 'functions/display_messages.php'); |
| 24 | |
| 25 | /* globals */ |
| 26 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
| 27 | sqgetGlobalVar('username', $username, SQ_SESSION); |
| 28 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
| 29 | sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION); |
| 30 | sqgetGlobalVar('orig', $orig, SQ_POST); |
| 31 | sqgetGlobalVar('old_name', $old_name, SQ_POST); |
| 32 | sqgetGlobalVar('new_name', $new_name, SQ_POST); |
| 33 | /* end globals */ |
| 34 | |
| 35 | $new_name = trim($new_name); |
| 36 | |
| 37 | if (substr_count($new_name, '"') || substr_count($new_name, "\\") || |
| 38 | substr_count($new_name, $delimiter) || ($new_name == '')) { |
| 39 | displayPageHeader($color, 'None'); |
| 40 | |
| 41 | plain_error_message(_("Illegal folder name. Please select a different name."). |
| 42 | '<BR><A HREF="../src/folders.php">'._("Click here to go back").'</A>.', $color); |
| 43 | |
| 44 | exit; |
| 45 | } |
| 46 | |
| 47 | $orig = imap_utf7_encode_local($orig); |
| 48 | $old_name = imap_utf7_encode_local($old_name); |
| 49 | $new_name = imap_utf7_encode_local($new_name); |
| 50 | |
| 51 | if ($old_name <> $new_name) { |
| 52 | |
| 53 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 54 | |
| 55 | if (strpos($orig, $delimiter)) { |
| 56 | $old_dir = substr($orig, 0, strrpos($orig, $delimiter)); |
| 57 | } else { |
| 58 | $old_dir = ''; |
| 59 | } |
| 60 | |
| 61 | if ($old_dir != '') { |
| 62 | $newone = $old_dir . $delimiter . $new_name; |
| 63 | } else { |
| 64 | $newone = $new_name; |
| 65 | } |
| 66 | |
| 67 | // Renaming a folder doesn't rename the folder but leaves you unsubscribed |
| 68 | // at least on Cyrus IMAP servers. |
| 69 | if (isset($isfolder)) { |
| 70 | $newone = $newone.$delimiter; |
| 71 | $orig = $orig.$delimiter; |
| 72 | } |
| 73 | sqimap_mailbox_rename( $imapConnection, $orig, $newone ); |
| 74 | |
| 75 | // Log out this session |
| 76 | sqimap_logout($imapConnection); |
| 77 | |
| 78 | } |
| 79 | |
| 80 | header ('Location: ' . get_location() . '/folders.php?success=rename'); |
| 81 | |
| 82 | ?> |