Converted "foo" to 'foo' for abook_*.php
[squirrelmail.git] / src / folders_rename_do.php
CommitLineData
59177427 1<?php
ef870322 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
245a6892 10 **
11 ** $Id$
ef870322 12 **/
13
14 session_start();
15
ef870322 16 if (!isset($strings_php))
17 include("../functions/strings.php");
1863670d 18 if (!isset($config_php))
19 include("../config/config.php");
ef870322 20 if (!isset($page_header_php))
21 include("../functions/page_header.php");
22 if (!isset($imap_php))
23 include("../functions/imap.php");
ef870322 24
25 include("../src/load_prefs.php");
26
5bdd7223 27
28 if($old_name == $new_name) {
29 $location = get_location();
30 header ("Location: $location/folders.php");
31 exit;
32 }
33
ef870322 34 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
35 $dm = sqimap_get_delimiter($imapConnection);
36
d92b6f31 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
7aaa81fc 47 $orig = sqStripSlashes($orig);
48 $newone = sqStripSlashes($newone);
d7092926 49
390372b4 50 fputs ($imapConnection, ". RENAME \"$orig\" \"$newone\"\r\n");
813eba2f 51 $data = sqimap_read_data($imapConnection, ".", true, $a, $b);
d92b6f31 52
f16d469a 53 // Renaming a folder doesn't renames the folder but leaves you unsubscribed
54 // at least on Cyrus IMAP servers.
1863670d 55 if (isset($isfolder)) {
693ccbc9 56 $newone = $newone.$dm;
57 $orig = $orig.$dm;
58 }
693ccbc9 59 sqimap_unsubscribe($imapConnection, $orig);
60 sqimap_subscribe($imapConnection, $newone);
d92b6f31 61
a97105e6 62 fputs ($imapConnection, "a001 LIST \"\" \"$newone*\"\r\n");
390372b4 63 $data = sqimap_read_data($imapConnection, "a001", true, $a, $b);
a97105e6 64 for ($i=0; $i < count($data); $i++)
65 {
390372b4 66 $name = find_mailbox_name($data[$i]);
390372b4 67
5bdd7223 68 if ($name != $newone) // don't try to resubscribe when renaming ab to abc
a97105e6 69 {
70 sqimap_unsubscribe($imapConnection, $name);
71 $name = substr($name, strlen($orig));
72 $name = $newone . $name;
73 sqimap_subscribe($imapConnection, $name);
74 }
75 }
390372b4 76
be69e508 77 /** Log out this session **/
693ccbc9 78 sqimap_logout($imapConnection);
1195c340 79 $location = get_location();
80 header ("Location: $location/folders.php?success=rename");
be69e508 81?>