X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fimap_mailbox.php;h=6f798dbbfef3dec88e7e49c5c610b1b94aafc39b;hb=527a8ae64a5c5e510c2efa47039f6c966cd338d3;hp=191c6b944166b1b9650f56f77005e09e49d4c80a;hpb=48af4b64d30963c920d8855ecd095bf6bc94d4e0;p=squirrelmail.git diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index 191c6b94..6f798dbb 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -3,13 +3,14 @@ /** * imap_mailbox.php * - * Copyright (c) 1999-2003 The SquirrelMail Project Team + * Copyright (c) 1999-2004 The SquirrelMail Project Team * Licensed under the GNU GPL. For full terms see the file COPYING. * * This impliments all functions that manipulate mailboxes * - * $Id$ + * @version $Id$ * @package squirrelmail + * @subpackage imap */ /** UTF7 support */ @@ -224,13 +225,12 @@ function isDraftMailbox($box) { * Expunges a mailbox, ie. delete all contents. */ function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, $id='') { - global $uid_support; if ($id) { if (is_array($id)) { $id = sqimap_message_list_squisher($id); } $id = ' '.$id; - $uid = $uid_support; + $uid = TRUE; } else { $uid = false; } @@ -248,6 +248,62 @@ function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, return $cnt; } +/** + * Expunge specified message, updated $msgs and $msort + * + * Until Marc and I come up with a better way to maintain + * these stupid arrays, we'll use this wrapper function to + * remove the message with the matching UID .. the order + * won't be changed - the array element for the message + * will just be removed. + */ +function sqimap_mailbox_expunge_dmn($message_id) +{ + global $msgs, $msort, $sort, $imapConnection, + $mailbox, $mbx_response, $auto_expunge, + $sort, $allow_server_sort, $thread_sort_messages, $allow_thread_sort, + $username, $data_dir; + $cnt = 0; + + // Got to grab this out of prefs, since it isn't saved from mailbox_view.php + if ($allow_thread_sort) { + $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox",0); + } + + for ($i = 0; $i < count($msort); $i++) { + if ($msgs[$i]['ID'] == $message_id) { + break; + } + } + + if ( isset($msgs) ) { + unset($msgs[$i]); + $msgs = array_values($msgs); + sqsession_register($msgs, 'msgs'); + } + + if ( isset($msort) ) { + unset($msort[$i]); + $msort = array_values($msort); + sqsession_register($msort, 'msort'); + } + + if ($auto_expunge) { + $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); + } + + // And after all that mucking around, update the sort list! + // Remind me why the hell we need those two arrays again?! + if ( $allow_thread_sort && $thread_sort_messages ) { + $server_sort_array = get_thread_sort($imapConnection); + } elseif ( $allow_server_sort ) { + $server_sort_array = sqimap_get_sort_order($imapConnection, $sort, $mbx_response); + } else { + $server_sort_array = sqimap_get_php_sort_order($imapConnection, $mbx_response); + } + return $cnt; +} + /** * Checks whether or not the specified mailbox exists */ @@ -328,7 +384,7 @@ function sqimap_subscribe ($imap_stream, $mailbox) { function sqimap_unsubscribe ($imap_stream, $mailbox) { $read_ary = sqimap_run_command($imap_stream, 'UNSUBSCRIBE ' . sqimap_encode_mailbox_name($mailbox), - true, $response, $message); + false, $response, $message); } /** @@ -336,12 +392,17 @@ function sqimap_unsubscribe ($imap_stream, $mailbox) { */ function sqimap_mailbox_delete ($imap_stream, $mailbox) { global $data_dir, $username; + sqimap_unsubscribe ($imap_stream, $mailbox); $read_ary = sqimap_run_command($imap_stream, 'DELETE ' . sqimap_encode_mailbox_name($mailbox), true, $response, $message); - sqimap_unsubscribe ($imap_stream, $mailbox); - do_hook_function('rename_or_delete_folder', $args = array($mailbox, 'delete', '')); - removePref($data_dir, $username, "thread_$mailbox"); + if ($response !== 'OK') { + // subscribe again + sqimap_subscribe ($imap_stream, $mailbox); + } else { + do_hook_function('rename_or_delete_folder', $args = array($mailbox, 'delete', '')); + removePref($data_dir, $username, "thread_$mailbox"); + } } /** @@ -755,15 +816,34 @@ function sqimap_mailbox_tree($imap_stream) { $has_inbox = false; for ($i = 0, $cnt = count($lsub_ary); $i < $cnt; $i++) { - if (preg_match("/^\*\s+LSUB\s+(.*)\"?INBOX\"?[^(\/\.)].*$/i",$lsub_ary[$i])) { + if (preg_match("/^\*\s+LSUB.*\s\"?INBOX\"?[^(\/\.)].*$/i",$lsub_ary[$i])) { $lsub_ary[$i] = strtoupper($lsub_ary[$i]); - $has_inbox = true; + // in case of an unsubscribed inbox an imap server can + // return the inbox in the lsub results with a \NoSelect + // flag. + if (!preg_match("/\*\s+LSUB\s+\(.*\\\\NoSelect.*\).*/i",$lsub_ary[$i])) { + $has_inbox = true; + } else { + // remove the result and request it again with a list + // response at a later stage. + unset($lsub_ary[$i]); + // re-index the array otherwise the addition of the LIST + // response will fail in PHP 4.1.2 and probably other older versions + $lsub_ary = array_values($lsub_ary); + } break; } } if ($has_inbox == false) { - $lsub_ary[] = '* LSUB () NIL INBOX'; + // do a list request for inbox because we should always show + // inbox even if the user isn't subscribed to it. + $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" INBOX', + true, $response, $message); + $inbox_ary = compact_mailboxes_response($inbox_ary); + if (count($inbox_ary)) { + $lsub_ary[] = $inbox_ary[0]; + } } /* @@ -893,7 +973,7 @@ function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) { $mbx->is_special |= ($mbx->is_sent = isSentMailbox($mailbox)); $mbx->is_special |= ($mbx->is_draft = isDraftMailbox($mailbox)); if (!$mbx->is_special) - $mbx->is_special = do_hook_function('special_mailbox', $mailbox); + $mbx->is_special = boolean_hook_function('special_mailbox', $mailbox, 1); if (isset($mbx_ary[$i]['unseen'])) { $mbx->unseen = $mbx_ary[$i]['unseen']; @@ -922,7 +1002,7 @@ function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) { } function sqimap_utf7_decode_mbx_tree(&$mbx_tree) { - if (strtoupper($mbx_tree->mailboxname_sub) == 'INBOX') + if (strtoupper($mbx_tree->mailboxname_full) == 'INBOX') $mbx_tree->mailboxname_sub = _("INBOX"); else $mbx_tree->mailboxname_sub = imap_utf7_decode_local($mbx_tree->mailboxname_sub);