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