| 1 | <?php |
| 2 | /** |
| 3 | ** folders_rename_do.php |
| 4 | ** |
| 5 | ** Copyright (c) 1999-2000 The SquirrelMail development team |
| 6 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
| 7 | ** |
| 8 | ** Does the actual renaming of files on the IMAP server. |
| 9 | ** Called from the folders.php |
| 10 | ** |
| 11 | ** $Id$ |
| 12 | **/ |
| 13 | |
| 14 | session_start(); |
| 15 | |
| 16 | if (!isset($strings_php)) |
| 17 | include("../functions/strings.php"); |
| 18 | if (!isset($config_php)) |
| 19 | include("../config/config.php"); |
| 20 | if (!isset($page_header_php)) |
| 21 | include("../functions/page_header.php"); |
| 22 | if (!isset($imap_php)) |
| 23 | include("../functions/imap.php"); |
| 24 | |
| 25 | include("../src/load_prefs.php"); |
| 26 | |
| 27 | |
| 28 | if($old_name == $new_name) { |
| 29 | $location = get_location(); |
| 30 | header ("Location: $location/folders.php"); |
| 31 | exit; |
| 32 | } |
| 33 | |
| 34 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 35 | $dm = sqimap_get_delimiter($imapConnection); |
| 36 | |
| 37 | if (strpos($orig, $dm)) |
| 38 | $old_dir = substr($orig, 0, strrpos($orig, $dm)); |
| 39 | else |
| 40 | $old_dir = ""; |
| 41 | |
| 42 | if ($old_dir != "") |
| 43 | $newone = "$old_dir$dm$new_name"; |
| 44 | else |
| 45 | $newone = "$new_name"; |
| 46 | |
| 47 | fputs ($imapConnection, ". RENAME \"$orig\" \"$newone\"\r\n"); |
| 48 | $data = sqimap_read_data($imapConnection, ".", true, $a, $b); |
| 49 | |
| 50 | // Renaming a folder doesn't renames the folder but leaves you unsubscribed |
| 51 | // at least on Cyrus IMAP servers. |
| 52 | if (isset($isfolder)) { |
| 53 | $newone = $newone.$dm; |
| 54 | $orig = $orig.$dm; |
| 55 | } |
| 56 | sqimap_unsubscribe($imapConnection, $orig); |
| 57 | sqimap_subscribe($imapConnection, $newone); |
| 58 | |
| 59 | fputs ($imapConnection, "a001 LIST \"\" \"$newone*\"\r\n"); |
| 60 | $data = sqimap_read_data($imapConnection, "a001", true, $a, $b); |
| 61 | for ($i=0; $i < count($data); $i++) |
| 62 | { |
| 63 | $name = find_mailbox_name($data[$i]); |
| 64 | |
| 65 | if ($name != $newone) // don't try to resubscribe when renaming ab to abc |
| 66 | { |
| 67 | sqimap_unsubscribe($imapConnection, $name); |
| 68 | $name = substr($name, strlen($orig)); |
| 69 | $name = $newone . $name; |
| 70 | sqimap_subscribe($imapConnection, $name); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** Log out this session **/ |
| 75 | sqimap_logout($imapConnection); |
| 76 | $location = get_location(); |
| 77 | header ("Location: $location/folders.php?success=rename"); |
| 78 | ?> |