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