Added sent_subfolders plugin, tweaked config stuff, other stuff.
[squirrelmail.git] / src / folders_rename_do.php
1 <?php
2
3 /**
4 * folders_rename_do.php
5 *
6 * Copyright (c) 1999-2001 The Squirrelmail Development 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 */
14
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 /*****************************************************************/
30
31 require_once('../src/validate.php');
32 require_once('../functions/imap.php');
33
34 if($old_name == $new_name) {
35 $location = get_location();
36 header ("Location: $location/folders.php");
37 exit;
38 }
39
40 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41 global $delimiter;
42
43 if (strpos($orig, $delimiter))
44 $old_dir = substr($orig, 0, strrpos($orig, $delimiter));
45 else
46 $old_dir = "";
47
48 if ($old_dir != "")
49 $newone = "$old_dir$delimiter$new_name";
50 else
51 $newone = "$new_name";
52
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);
57
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;
63 }
64 sqimap_unsubscribe($imapConnection, $orig);
65 sqimap_subscribe($imapConnection, $newone);
66
67 fputs ($imapConnection, sqimap_session_id() . " LIST \"\" \"" . quoteIMAP($newone) .
68 "*\"\r\n");
69 $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b);
70 for ($i=0; $i < count($data); $i++)
71 {
72 $name = find_mailbox_name($data[$i]);
73
74 if ($name != $newone) // don't try to resubscribe when renaming ab to abc
75 {
76 sqimap_unsubscribe($imapConnection, $name);
77 $name = substr($name, strlen($orig));
78 $name = $newone . $name;
79 sqimap_subscribe($imapConnection, $name);
80 }
81 }
82
83 /** Log out this session **/
84 sqimap_logout($imapConnection);
85 $location = get_location();
86 header ("Location: $location/folders.php?success=rename");
87 ?>