| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/mail/move_del.inc | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the Roundcube Webmail client | |
|---|
| 8 | | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 11 | | PURPOSE: | |
|---|
| 12 | | Move the submitted messages to a specific mailbox or delete them | |
|---|
| 13 | | | |
|---|
| 14 | +-----------------------------------------------------------------------+ |
|---|
| 15 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 16 | +-----------------------------------------------------------------------+ |
|---|
| 17 | |
|---|
| 18 | $Id$ |
|---|
| 19 | |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | // only process ajax requests |
|---|
| 23 | if (!$OUTPUT->ajax_call) |
|---|
| 24 | return; |
|---|
| 25 | |
|---|
| 26 | // count messages before changing anything |
|---|
| 27 | $old_count = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL'); |
|---|
| 28 | $old_pages = ceil($old_count / $IMAP->page_size); |
|---|
| 29 | |
|---|
| 30 | // move messages |
|---|
| 31 | if ($RCMAIL->action=='moveto' && !empty($_POST['_uid']) && !empty($_POST['_target_mbox'])) { |
|---|
| 32 | $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST)))); |
|---|
| 33 | $target = get_input_value('_target_mbox', RCUBE_INPUT_POST); |
|---|
| 34 | $mbox = get_input_value('_mbox', RCUBE_INPUT_POST); |
|---|
| 35 | |
|---|
| 36 | $moved = $IMAP->move_message($uids, $target, $mbox); |
|---|
| 37 | |
|---|
| 38 | if (!$moved) { |
|---|
| 39 | // send error message |
|---|
| 40 | if ($_POST['_from'] != 'show') |
|---|
| 41 | $OUTPUT->command('list_mailbox'); |
|---|
| 42 | $OUTPUT->show_message('errormoving', 'error'); |
|---|
| 43 | $OUTPUT->send(); |
|---|
| 44 | exit; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | $addrows = true; |
|---|
| 48 | } |
|---|
| 49 | // delete messages |
|---|
| 50 | else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) { |
|---|
| 51 | $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST)))); |
|---|
| 52 | $mbox = get_input_value('_mbox', RCUBE_INPUT_POST); |
|---|
| 53 | |
|---|
| 54 | $del = $IMAP->delete_message($uids, $mbox); |
|---|
| 55 | |
|---|
| 56 | if (!$del) { |
|---|
| 57 | // send error message |
|---|
| 58 | if ($_POST['_from'] != 'show') |
|---|
| 59 | $OUTPUT->command('list_mailbox'); |
|---|
| 60 | $OUTPUT->show_message('errordeleting', 'error'); |
|---|
| 61 | $OUTPUT->send(); |
|---|
| 62 | exit; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | $addrows = true; |
|---|
| 66 | } |
|---|
| 67 | // unknown action or missing query param |
|---|
| 68 | else { |
|---|
| 69 | exit; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | // refresh saved search set after moving some messages |
|---|
| 73 | if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) { |
|---|
| 74 | $_SESSION['search'] = $IMAP->refresh_search(); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | if ($_POST['_from'] == 'show') |
|---|
| 78 | { |
|---|
| 79 | if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC)) |
|---|
| 80 | $OUTPUT->command('show_message', $next); |
|---|
| 81 | else |
|---|
| 82 | $OUTPUT->command('command', 'list'); |
|---|
| 83 | } |
|---|
| 84 | else |
|---|
| 85 | { |
|---|
| 86 | $msg_count = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL'); |
|---|
| 87 | $pages = ceil($msg_count / $IMAP->page_size); |
|---|
| 88 | $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page; |
|---|
| 89 | $remaining = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1); |
|---|
| 90 | |
|---|
| 91 | // jump back one page (user removed the whole last page) |
|---|
| 92 | if ($IMAP->list_page > 1 && $remaining == 0) { |
|---|
| 93 | $IMAP->set_page($IMAP->list_page-1); |
|---|
| 94 | $_SESSION['page'] = $IMAP->list_page; |
|---|
| 95 | $jump_back = true; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | // update message count display |
|---|
| 99 | $OUTPUT->set_env('messagecount', $msg_count); |
|---|
| 100 | $OUTPUT->set_env('current_page', $IMAP->list_page); |
|---|
| 101 | $OUTPUT->set_env('pagecount', $pages); |
|---|
| 102 | |
|---|
| 103 | // update mailboxlist |
|---|
| 104 | $mbox = $IMAP->get_mailbox_name(); |
|---|
| 105 | $unseen_count = $msg_count ? $IMAP->messagecount($mbox, 'UNSEEN') : 0; |
|---|
| 106 | $old_unseen = $_SESSION['unseen_count'][$mbox]; |
|---|
| 107 | |
|---|
| 108 | if ($old_unseen != $unseen_count) { |
|---|
| 109 | $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX')); |
|---|
| 110 | $_SESSION['unseen_count'][$mbox] = $unseen_count; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | if ($RCMAIL->action=='moveto' && $target) { |
|---|
| 114 | rcmail_send_unread_count($target, true); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | $OUTPUT->command('set_quota', rcmail_quota_content()); |
|---|
| 118 | $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count)); |
|---|
| 119 | |
|---|
| 120 | if ($IMAP->threading) |
|---|
| 121 | $count = get_input_value('_count', RCUBE_INPUT_POST); |
|---|
| 122 | |
|---|
| 123 | // add new rows from next page (if any) |
|---|
| 124 | if ($addrows && $count && $uids != '*' && ($jump_back || $nextpage_count > 0)) { |
|---|
| 125 | $sort_col = isset($_SESSION['sort_col']) ? $_SESSION['sort_col'] : $CONFIG['message_sort_col']; |
|---|
| 126 | $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order']; |
|---|
| 127 | |
|---|
| 128 | $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order, |
|---|
| 129 | $jump_back ? NULL : $count); |
|---|
| 130 | |
|---|
| 131 | rcmail_js_message_list($a_headers, false); |
|---|
| 132 | } |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | // send response |
|---|
| 136 | $OUTPUT->send(); |
|---|
| 137 | |
|---|
| 138 | |
|---|