Removed a lot of the warnings generated when PHP has all warnings enabled.
[squirrelmail.git] / src / folders_rename_do.php
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($config_php))
17 include("../config/config.php");
18 if (!isset($strings_php))
19 include("../functions/strings.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 $orig = sqStripSlashes($orig);
48 $newone = sqStripSlashes($newone);
49
50 fputs ($imapConnection, ". RENAME \"$orig\" \"$newone\"\r\n");
51 $data = sqimap_read_data($imapConnection, ".", true, $a, $b);
52
53 // Renaming a folder doesn't renames the folder but leaves you unsubscribed
54 // at least on Cyrus IMAP servers.
55 if ($isfolder) {
56 $newone = $newone.$dm;
57 $orig = $orig.$dm;
58 }
59 sqimap_unsubscribe($imapConnection, $orig);
60 sqimap_subscribe($imapConnection, $newone);
61
62 fputs ($imapConnection, "a001 LIST \"\" \"$newone*\"\r\n");
63 $data = sqimap_read_data($imapConnection, "a001", true, $a, $b);
64 for ($i=0; $i < count($data); $i++)
65 {
66 $name = find_mailbox_name($data[$i]);
67
68 if ($name != $newone) // don't try to resubscribe when renaming ab to abc
69 {
70 sqimap_unsubscribe($imapConnection, $name);
71 $name = substr($name, strlen($orig));
72 $name = $newone . $name;
73 sqimap_subscribe($imapConnection, $name);
74 }
75 }
76
77 /** Log out this session **/
78 sqimap_logout($imapConnection);
79 $location = get_location();
80 header ("Location: $location/folders.php?success=rename");
81 ?>