Some cleanup.
[squirrelmail.git] / src / folders_rename_do.php
CommitLineData
59177427 1<?php
895905c0 2
ef870322 3 /**
4 ** folders_rename_do.php
5 **
895905c0 6 ** Copyright (c) 1999-2001 The SquirrelMail development team
ef870322 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
245a6892 11 **
12 ** $Id$
ef870322 13 **/
14
ff8a98e7 15 require_once('../src/validate.php');
16 require_once('../functions/imap.php');
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);
525b7ae6 25 global $delimiter;
ef870322 26
525b7ae6 27 if (strpos($orig, $delimiter))
28 $old_dir = substr($orig, 0, strrpos($orig, $delimiter));
d92b6f31 29 else
30 $old_dir = "";
31
32 if ($old_dir != "")
525b7ae6 33 $newone = "$old_dir$delimiter$new_name";
d92b6f31 34 else
35 $newone = "$new_name";
36
56a19f1e 37 $cmd = sqimap_session_id() . " RENAME \"" . quoteIMAP($orig) . "\" \"" .
844d9c1a 38 quoteIMAP($newone) . "\"\r\n";
844d9c1a 39 fputs ($imapConnection, $cmd);
56a19f1e 40 $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b);
d92b6f31 41
f16d469a 42 // Renaming a folder doesn't renames the folder but leaves you unsubscribed
43 // at least on Cyrus IMAP servers.
1863670d 44 if (isset($isfolder)) {
525b7ae6 45 $newone = $newone.$delimiter;
46 $orig = $orig.$delimiter;
693ccbc9 47 }
693ccbc9 48 sqimap_unsubscribe($imapConnection, $orig);
49 sqimap_subscribe($imapConnection, $newone);
d92b6f31 50
56a19f1e 51 fputs ($imapConnection, sqimap_session_id() . " LIST \"\" \"" . quoteIMAP($newone) .
844d9c1a 52 "*\"\r\n");
56a19f1e 53 $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b);
a97105e6 54 for ($i=0; $i < count($data); $i++)
55 {
390372b4 56 $name = find_mailbox_name($data[$i]);
390372b4 57
5bdd7223 58 if ($name != $newone) // don't try to resubscribe when renaming ab to abc
a97105e6 59 {
60 sqimap_unsubscribe($imapConnection, $name);
61 $name = substr($name, strlen($orig));
62 $name = $newone . $name;
63 sqimap_subscribe($imapConnection, $name);
64 }
65 }
390372b4 66
be69e508 67 /** Log out this session **/
693ccbc9 68 sqimap_logout($imapConnection);
1195c340 69 $location = get_location();
70 header ("Location: $location/folders.php?success=rename");
525b7ae6 71?>