724a63ed8eefa483e9a1819fc210890b65052184
[squirrelmail.git] / src / folders_subscribe.php
1 <?php
2
3 /**
4 * folders_subscribe.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Subscribe and unsubcribe from folders.
10 * Called from folders.php
11 *
12 * $Id$
13 */
14
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/imap.php');
21 require_once(SM_PATH . 'functions/display_messages.php');
22
23 /* globals */
24 sqgetGlobalVar('key', $key, SQ_COOKIE);
25 sqgetGlobalVar('username', $username, SQ_SESSION);
26 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
27 sqgetGlobalVar('method', $method, SQ_GET);
28 sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
29 /* end globals */
30
31 $location = get_location();
32
33 if (!isset($mailbox) || !isset($mailbox[0]) || $mailbox[0] == '') {
34 header("Location: $location/folders.php");
35
36 exit(0);
37 }
38
39 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
40
41 if ($method == 'sub') {
42 if($no_list_for_subscribe && $imap_server_type == 'cyrus') {
43 /* Cyrus, atleast, does not typically allow subscription to
44 * nonexistent folders (this is an optional part of IMAP),
45 * lets catch it here and report back cleanly. */
46 if(!sqimap_mailbox_exists($imapConnection, $mailbox[0])) {
47 header("Location: $location/folders.php?success=subscribe-doesnotexist");
48 sqimap_logout($imapConnection);
49 exit(0);
50 }
51 }
52 for ($i=0; $i < count($mailbox); $i++) {
53 $mailbox[$i] = trim($mailbox[$i]);
54 sqimap_subscribe ($imapConnection, $mailbox[$i]);
55 }
56 $success = 'subscribe';
57 } else {
58 for ($i=0; $i < count($mailbox); $i++) {
59 $mailbox[$i] = trim($mailbox[$i]);
60 sqimap_unsubscribe ($imapConnection, $mailbox[$i]);
61 }
62 $success = 'unsubscribe';
63 }
64
65 sqimap_logout($imapConnection);
66 header("Location: $location/folders.php?success=$success");
67
68 ?>