| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | +-----------------------------------------------------------------------+ |
|---|
| 4 | | program/steps/mail/mark.inc | |
|---|
| 5 | | | |
|---|
| 6 | | This file is part of the RoundCube Webmail client | |
|---|
| 7 | | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
|---|
| 8 | | Licensed under the GNU GPL | |
|---|
| 9 | | | |
|---|
| 10 | | PURPOSE: | |
|---|
| 11 | | Mark the submitted messages with the specified flag | |
|---|
| 12 | | | |
|---|
| 13 | +-----------------------------------------------------------------------+ |
|---|
| 14 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 15 | +-----------------------------------------------------------------------+ |
|---|
| 16 | |
|---|
| 17 | $Id$ |
|---|
| 18 | |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | $a_flags_map = array( |
|---|
| 22 | 'undelete' => 'UNDELETED', |
|---|
| 23 | 'delete' => 'DELETED', |
|---|
| 24 | 'read' => 'SEEN', |
|---|
| 25 | 'unread' => 'UNSEEN', |
|---|
| 26 | 'flagged' => 'FLAGGED', |
|---|
| 27 | 'unflagged' => 'UNFLAGGED'); |
|---|
| 28 | |
|---|
| 29 | if (($uids = get_input_value('_uid', RCUBE_INPUT_POST)) && ($flag = get_input_value('_flag', RCUBE_INPUT_POST))) |
|---|
| 30 | { |
|---|
| 31 | $flag = $a_flags_map[$flag] ? $a_flags_map[$flag] : strtoupper($flag); |
|---|
| 32 | |
|---|
| 33 | if ($flag == 'DELETED' && $CONFIG['skip_deleted'] && $_POST['_from'] != 'show') { |
|---|
| 34 | // count messages before changing anything |
|---|
| 35 | $old_count = $IMAP->messagecount(); |
|---|
| 36 | $old_pages = ceil($old_count / $IMAP->page_size); |
|---|
| 37 | $count = sizeof(explode(',', $uids)); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | $marked = $IMAP->set_flag($uids, $flag); |
|---|
| 41 | |
|---|
| 42 | if ($marked == -1) { |
|---|
| 43 | // send error message |
|---|
| 44 | if ($_POST['_from'] != 'show') |
|---|
| 45 | $OUTPUT->command('list_mailbox'); |
|---|
| 46 | $OUTPUT->show_message('errormarking', 'error'); |
|---|
| 47 | $OUTPUT->send(); |
|---|
| 48 | exit; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | if($flag == 'DELETED' && $CONFIG['read_when_deleted'] && !empty($_POST['_ruid'])) { |
|---|
| 52 | $uids = get_input_value('_ruid', RCUBE_INPUT_POST); |
|---|
| 53 | $read = $IMAP->set_flag($uids, 'SEEN'); |
|---|
| 54 | |
|---|
| 55 | if ($read != -1 && !$CONFIG['skip_deleted']) |
|---|
| 56 | $OUTPUT->command('flag_deleted_as_read', $uids); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | if ($flag == 'SEEN' || $flag == 'UNSEEN' || ($flag == 'DELETED' && !$CONFIG['skip_deleted'])) { |
|---|
| 60 | $mbox_name = $IMAP->get_mailbox_name(); |
|---|
| 61 | $OUTPUT->command('set_unread_count', $mbox_name, $IMAP->messagecount($mbox_name, 'UNSEEN'), ($mbox_name == 'INBOX')); |
|---|
| 62 | } |
|---|
| 63 | else if ($flag == 'DELETED' && $CONFIG['skip_deleted']) { |
|---|
| 64 | if ($_POST['_from'] == 'show') { |
|---|
| 65 | if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC)) |
|---|
| 66 | $OUTPUT->command('show_message', $next); |
|---|
| 67 | else |
|---|
| 68 | $OUTPUT->command('command', 'list'); |
|---|
| 69 | } else { |
|---|
| 70 | // refresh saved search set after moving some messages |
|---|
| 71 | if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) { |
|---|
| 72 | $_SESSION['search'][$search_request] = $IMAP->refresh_search(); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | $msg_count = $IMAP->messagecount(); |
|---|
| 76 | $pages = ceil($msg_count / $IMAP->page_size); |
|---|
| 77 | $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page; |
|---|
| 78 | $remaining = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1); |
|---|
| 79 | |
|---|
| 80 | // jump back one page (user removed the whole last page) |
|---|
| 81 | if ($IMAP->list_page > 1 && $nextpage_count <= 0 && $remaining == 0) { |
|---|
| 82 | $IMAP->set_page($IMAP->list_page-1); |
|---|
| 83 | $_SESSION['page'] = $IMAP->list_page; |
|---|
| 84 | $jump_back = true; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | // update message count display |
|---|
| 88 | $OUTPUT->set_env('messagecount', $msg_count); |
|---|
| 89 | $OUTPUT->set_env('current_page', $IMAP->list_page); |
|---|
| 90 | $OUTPUT->set_env('pagecount', $pages); |
|---|
| 91 | |
|---|
| 92 | // update mailboxlist |
|---|
| 93 | $mbox = $IMAP->get_mailbox_name(); |
|---|
| 94 | $OUTPUT->command('set_unread_count', $mbox, $IMAP->messagecount($mbox, 'UNSEEN'), ($mbox == 'INBOX')); |
|---|
| 95 | |
|---|
| 96 | // $OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota())); |
|---|
| 97 | $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count)); |
|---|
| 98 | |
|---|
| 99 | // add new rows from next page (if any) |
|---|
| 100 | if (($jump_back || $nextpage_count > 0)) { |
|---|
| 101 | $sort_col = isset($_SESSION['sort_col']) ? $_SESSION['sort_col'] : $CONFIG['message_sort_col']; |
|---|
| 102 | $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order']; |
|---|
| 103 | |
|---|
| 104 | $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order); |
|---|
| 105 | if (!$jump_back) { |
|---|
| 106 | $a_headers = array_slice($a_headers, -$count, $count); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | rcmail_js_message_list($a_headers, false, false); |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | $OUTPUT->send(); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | exit; |
|---|
| 118 | ?> |
|---|