/** * Given a list of folder names, unsubscribes from each of them. */ function folders_unsubscribe($imapConnection, $folder_names) { global $color, $oTemplate; if (count($folder_names) == 0 || $folder_names[0] == '') { plain_error_message(_("You have not selected a folder to unsubscribe. Please do so.") . '<br /><a href="../src/folders.php">' . _("Click here to go back") . '</a>.', $color); sqimap_logout($imapConnection); $oTemplate->display('footer.tpl'); exit; } foreach ($folder_names as $folder_name) { sqimap_unsubscribe($imapConnection, $folder_name); } return; }
/** * Renames a mailbox. */ function sqimap_mailbox_rename($imap_stream, $old_name, $new_name) { if ($old_name != $new_name) { global $delimiter, $imap_server_type, $data_dir, $username; if (substr($old_name, -1) == $delimiter) { $old_name = substr($old_name, 0, strlen($old_name) - 1); $new_name = substr($new_name, 0, strlen($new_name) - 1); $postfix = $delimiter; } else { $postfix = ''; } $boxesall = sqimap_mailbox_list_all($imap_stream); $cmd = 'RENAME "' . $old_name . '" "' . $new_name . '"'; $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message); sqimap_unsubscribe($imap_stream, $old_name . $postfix); $oldpref_thread = getPref($data_dir, $username, 'thread_' . $old_name . $postfix); $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_' . $old_name . $postfix); removePref($data_dir, $username, 'thread_' . $old_name . $postfix); removePref($data_dir, $username, 'collapse_folder_' . $old_name . $postfix); sqimap_subscribe($imap_stream, $new_name . $postfix); setPref($data_dir, $username, 'thread_' . $new_name . $postfix, $oldpref_thread); setPref($data_dir, $username, 'collapse_folder_' . $new_name . $postfix, $oldpref_collapse); do_hook_function('rename_or_delete_folder', $args = array($old_name, 'rename', $new_name)); $l = strlen($old_name) + 1; $p = 'unformatted'; foreach ($boxesall as $box) { if (substr($box[$p], 0, $l) == $old_name . $delimiter) { $new_sub = $new_name . $delimiter . substr($box[$p], $l); /* With Cyrus IMAPd >= 2.0 rename is recursive, so don't check for errors here */ if ($imap_server_type == 'cyrus') { $cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"'; $data = sqimap_run_command($imap_stream, $cmd, false, $response, $message); } $was_subscribed = sqimap_mailbox_is_subscribed($imap_stream, $box[$p]); if ($was_subscribed) { sqimap_unsubscribe($imap_stream, $box[$p]); } $oldpref_thread = getPref($data_dir, $username, 'thread_' . $box[$p]); $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_' . $box[$p]); removePref($data_dir, $username, 'thread_' . $box[$p]); removePref($data_dir, $username, 'collapse_folder_' . $box[$p]); if ($was_subscribed) { sqimap_subscribe($imap_stream, $new_sub); } setPref($data_dir, $username, 'thread_' . $new_sub, $oldpref_thread); setPref($data_dir, $username, 'collapse_folder_' . $new_sub, $oldpref_collapse); do_hook_function('rename_or_delete_folder', $args = array($box[$p], 'rename', $new_sub)); } } } }
$location = get_location(); if (!isset($mailbox) || !isset($mailbox[0]) || $mailbox[0] == '') { header("Location: {$location}/folders.php"); exit(0); } $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if ($method == 'sub') { if ($no_list_for_subscribe && $imap_server_type == 'cyrus') { /* Cyrus, atleast, does not typically allow subscription to * nonexistent folders (this is an optional part of IMAP), * lets catch it here and report back cleanly. */ if (!sqimap_mailbox_exists($imapConnection, $mailbox[0])) { header("Location: {$location}/folders.php?success=subscribe-doesnotexist"); sqimap_logout($imapConnection); exit(0); } } for ($i = 0; $i < count($mailbox); $i++) { $mailbox[$i] = trim($mailbox[$i]); sqimap_subscribe($imapConnection, $mailbox[$i]); } $success = 'subscribe'; } else { for ($i = 0; $i < count($mailbox); $i++) { $mailbox[$i] = trim($mailbox[$i]); sqimap_unsubscribe($imapConnection, $mailbox[$i]); } $success = 'unsubscribe'; } sqimap_logout($imapConnection); header("Location: {$location}/folders.php?success={$success}");
function sqimap_mailbox_rename($imap_stream, $old_name, $new_name) { if ($old_name != $new_name) { global $delimiter, $imap_server_type, $data_dir, $username; if (substr($old_name, -1) == $delimiter) { $old_name = substr($old_name, 0, strlen($old_name) - 1); $new_name = substr($new_name, 0, strlen($new_name) - 1); $postfix = $delimiter; } else { $postfix = ''; } $boxesall = sqimap_mailbox_list($imap_stream); $cmd = 'RENAME "' . $old_name . '" "' . $new_name . '"'; $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message); sqimap_unsubscribe($imap_stream, $old_name . $postfix); $oldpref = getPref($data_dir, $username, 'thread_' . $old_name . $postfix); removePref($data_dir, $username, 'thread_' . $old_name . $postfix); sqimap_subscribe($imap_stream, $new_name . $postfix); setPref($data_dir, $username, 'thread_' . $new_name . $postfix, $oldpref); do_hook_function('rename_or_delete_folder', $args = array($old_name, 'rename', $new_name)); $l = strlen($old_name) + 1; $p = 'unformatted'; foreach ($boxesall as $box) { if (substr($box[$p], 0, $l) == $old_name . $delimiter) { $new_sub = $new_name . $delimiter . substr($box[$p], $l); if ($imap_server_type == 'cyrus') { $cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"'; $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message); } sqimap_unsubscribe($imap_stream, $box[$p]); $oldpref = getPref($data_dir, $username, 'thread_' . $box[$p]); removePref($data_dir, $username, 'thread_' . $box[$p]); sqimap_subscribe($imap_stream, $new_sub); setPref($data_dir, $username, 'thread_' . $new_sub, $oldpref); do_hook_function('rename_or_delete_folder', $args = array($box[$p], 'rename', $new_sub)); } } } }