Added sent_subfolders plugin, tweaked config stuff, other stuff.
[squirrelmail.git] / src / folders_rename_do.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders_rename_do.php
5 *
6 * Copyright (c) 1999-2001 The Squirrelmail Development Team
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
11 *
12 * $Id$
13 */
14
15/*****************************************************************/
16/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
17/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
18/*** + Base level indent should begin at left margin, as ***/
19/*** the require_once below looks. ***/
20/*** + All identation should consist of four space blocks ***/
21/*** + Tab characters are evil. ***/
22/*** + all comments should use "slash-star ... star-slash" ***/
23/*** style -- no pound characters, no slash-slash style ***/
24/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
25/*** ALWAYS USE { AND } CHARACTERS!!! ***/
26/*** + Please use ' instead of ", when possible. Note " ***/
27/*** should always be used in _( ) function calls. ***/
28/*** Thank you for your help making the SM code more readable. ***/
29/*****************************************************************/
30
31require_once('../src/validate.php');
32require_once('../functions/imap.php');
5bdd7223 33
34 if($old_name == $new_name) {
35 $location = get_location();
36 header ("Location: $location/folders.php");
37 exit;
38 }
39
ef870322 40 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
525b7ae6 41 global $delimiter;
ef870322 42
525b7ae6 43 if (strpos($orig, $delimiter))
44 $old_dir = substr($orig, 0, strrpos($orig, $delimiter));
d92b6f31 45 else
46 $old_dir = "";
47
48 if ($old_dir != "")
525b7ae6 49 $newone = "$old_dir$delimiter$new_name";
d92b6f31 50 else
51 $newone = "$new_name";
52
56a19f1e 53 $cmd = sqimap_session_id() . " RENAME \"" . quoteIMAP($orig) . "\" \"" .
844d9c1a 54 quoteIMAP($newone) . "\"\r\n";
844d9c1a 55 fputs ($imapConnection, $cmd);
56a19f1e 56 $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b);
d92b6f31 57
f16d469a 58 // Renaming a folder doesn't renames the folder but leaves you unsubscribed
59 // at least on Cyrus IMAP servers.
1863670d 60 if (isset($isfolder)) {
525b7ae6 61 $newone = $newone.$delimiter;
62 $orig = $orig.$delimiter;
693ccbc9 63 }
693ccbc9 64 sqimap_unsubscribe($imapConnection, $orig);
65 sqimap_subscribe($imapConnection, $newone);
d92b6f31 66
56a19f1e 67 fputs ($imapConnection, sqimap_session_id() . " LIST \"\" \"" . quoteIMAP($newone) .
844d9c1a 68 "*\"\r\n");
56a19f1e 69 $data = sqimap_read_data($imapConnection, sqimap_session_id(), true, $a, $b);
a97105e6 70 for ($i=0; $i < count($data); $i++)
71 {
390372b4 72 $name = find_mailbox_name($data[$i]);
390372b4 73
5bdd7223 74 if ($name != $newone) // don't try to resubscribe when renaming ab to abc
a97105e6 75 {
76 sqimap_unsubscribe($imapConnection, $name);
77 $name = substr($name, strlen($orig));
78 $name = $newone . $name;
79 sqimap_subscribe($imapConnection, $name);
80 }
81 }
390372b4 82
be69e508 83 /** Log out this session **/
693ccbc9 84 sqimap_logout($imapConnection);
1195c340 85 $location = get_location();
86 header ("Location: $location/folders.php?success=rename");
525b7ae6 87?>