| 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 | include("../src/validate.php"); |
| 15 | include("../functions/imap.php"); |
| 16 | |
| 17 | |
| 18 | if($old_name == $new_name) { |
| 19 | $location = get_location(); |
| 20 | header ("Location: $location/folders.php"); |
| 21 | exit; |
| 22 | } |
| 23 | |
| 24 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 25 | $dm = sqimap_get_delimiter($imapConnection); |
| 26 | |
| 27 | if (strpos($orig, $dm)) |
| 28 | $old_dir = substr($orig, 0, strrpos($orig, $dm)); |
| 29 | else |
| 30 | $old_dir = ""; |
| 31 | |
| 32 | if ($old_dir != "") |
| 33 | $newone = "$old_dir$dm$new_name"; |
| 34 | else |
| 35 | $newone = "$new_name"; |
| 36 | |
| 37 | $cmd = "a024 RENAME \"" . quoteIMAP($orig) . "\" \"" . |
| 38 | quoteIMAP($newone) . "\"\r\n"; |
| 39 | fputs ($imapConnection, $cmd); |
| 40 | $data = sqimap_read_data($imapConnection, "a024", true, $a, $b); |
| 41 | |
| 42 | // Renaming a folder doesn't renames the folder but leaves you unsubscribed |
| 43 | // at least on Cyrus IMAP servers. |
| 44 | if (isset($isfolder)) { |
| 45 | $newone = $newone.$dm; |
| 46 | $orig = $orig.$dm; |
| 47 | } |
| 48 | sqimap_unsubscribe($imapConnection, $orig); |
| 49 | sqimap_subscribe($imapConnection, $newone); |
| 50 | |
| 51 | fputs ($imapConnection, "a001 LIST \"\" \"" . quoteIMAP($newone) . |
| 52 | "*\"\r\n"); |
| 53 | $data = sqimap_read_data($imapConnection, "a001", true, $a, $b); |
| 54 | for ($i=0; $i < count($data); $i++) |
| 55 | { |
| 56 | $name = find_mailbox_name($data[$i]); |
| 57 | |
| 58 | if ($name != $newone) // don't try to resubscribe when renaming ab to abc |
| 59 | { |
| 60 | sqimap_unsubscribe($imapConnection, $name); |
| 61 | $name = substr($name, strlen($orig)); |
| 62 | $name = $newone . $name; |
| 63 | sqimap_subscribe($imapConnection, $name); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** Log out this session **/ |
| 68 | sqimap_logout($imapConnection); |
| 69 | $location = get_location(); |
| 70 | header ("Location: $location/folders.php?success=rename"); |
| 71 | ?> |