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