Add explicit include of global.php
[squirrelmail.git] / src / folders_subscribe.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders_subscribe.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
b7f83b61 9 * Subscribe and unsubcribe from folders.
35586184 10 * Called from folders.php
11 *
12 * $Id$
13 */
ef870322 14
86725763 15/* Path for SquirrelMail required files. */
16define('SM_PATH','../');
17
18/* SquirrelMail required files. */
08185f2a 19require_once(SM_PATH . 'include/validate.php');
86725763 20require_once(SM_PATH . 'functions/imap.php');
21require_once(SM_PATH . 'functions/display_messages.php');
11353192 22
a32985a5 23/* globals */
1e12d1ff 24sqgetGlobalVar('key', $key, SQ_COOKIE);
25sqgetGlobalVar('username', $username, SQ_SESSION);
26sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
27sqgetGlobalVar('method', $method, SQ_GET);
28sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
a32985a5 29/* end globals */
30
32f4e318 31$location = get_location();
52ed2f88 32
b7f83b61 33if (!isset($mailbox) || !isset($mailbox[0]) || $mailbox[0] == '') {
52ed2f88 34 header("Location: $location/folders.php");
b7f83b61 35
52ed2f88 36 exit(0);
37}
38
b7f83b61 39$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
40
32f4e318 41if ($method == 'sub') {
52ed2f88 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 }
32f4e318 52 for ($i=0; $i < count($mailbox); $i++) {
53 $mailbox[$i] = trim($mailbox[$i]);
54 sqimap_subscribe ($imapConnection, $mailbox[$i]);
32f4e318 55 }
b7f83b61 56 $success = 'subscribe';
32f4e318 57} else {
58 for ($i=0; $i < count($mailbox); $i++) {
59 $mailbox[$i] = trim($mailbox[$i]);
60 sqimap_unsubscribe ($imapConnection, $mailbox[$i]);
32f4e318 61 }
b7f83b61 62 $success = 'unsubscribe';
32f4e318 63}
b7f83b61 64
32f4e318 65sqimap_logout($imapConnection);
b7f83b61 66header("Location: $location/folders.php?success=$success");
11353192 67
f1177e37 68?>