4 * folders_rename_do.php
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Does the actual renaming of files on the IMAP server.
10 * Called from the folders.php
15 /*****************************************************************/
16 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
17 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
18 /*** + Base level indent should begin at left margin, as ***/
19 /*** the require_once below looks. ***/
20 /*** + All identation should consist of four space blocks ***/
21 /*** + Tab characters are evil. ***/
22 /*** + all comments should use "slash-star ... star-slash" ***/
23 /*** style -- no pound characters, no slash-slash style ***/
24 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
25 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
26 /*** + Please use ' instead of ", when possible. Note " ***/
27 /*** should always be used in _( ) function calls. ***/
28 /*** Thank you for your help making the SM code more readable. ***/
29 /*****************************************************************/
31 require_once('../src/validate.php');
32 require_once('../functions/imap.php');
34 if($old_name == $new_name) {
35 $location = get_location();
36 header ("Location: $location/folders.php");
40 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
43 if (strpos($orig, $delimiter))
44 $old_dir = substr($orig, 0, strrpos($orig, $delimiter));
49 $newone = "$old_dir$delimiter$new_name";
51 $newone = "$new_name";
53 $cmd = sqimap_session_id() . " RENAME \"" . quoteIMAP($orig) . "\" \"" .
54 quoteIMAP($newone) . "\"\r\n";
55 fputs ($imapConnection, $cmd);
56 $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b);
58 // Renaming a folder doesn't renames the folder but leaves you unsubscribed
59 // at least on Cyrus IMAP servers.
60 if (isset($isfolder)) {
61 $newone = $newone.$delimiter;
62 $orig = $orig.$delimiter;
64 sqimap_unsubscribe($imapConnection, $orig);
65 sqimap_subscribe($imapConnection, $newone);
67 fputs ($imapConnection, sqimap_session_id() . " LIST \"\" \"" . quoteIMAP($newone) .
69 $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b);
70 for ($i=0; $i < count($data); $i++
)
72 $name = find_mailbox_name($data[$i]);
74 if ($name != $newone) // don't try to resubscribe when renaming ab to abc
76 sqimap_unsubscribe($imapConnection, $name);
77 $name = substr($name, strlen($orig));
78 $name = $newone . $name;
79 sqimap_subscribe($imapConnection, $name);
83 /** Log out this session **/
84 sqimap_logout($imapConnection);
85 $location = get_location();
86 header ("Location: $location/folders.php?success=rename");