alecpl
2008-05-21 2b962c1074c45695da0376f830ec63923743c39e
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/move_del.inc                                       |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
f11541 8  | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 |
30233b 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 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
c3ab87 22 // count messages before changing anything
51e14a 23 $old_count = $IMAP->messagecount();
9a3567 24 $old_pages = ceil($old_count / $IMAP->page_size);
51e14a 25
4e17e6 26 // move messages
e090a1 27 if ($RCMAIL->action=='moveto' && !empty($_POST['_uid']) && !empty($_POST['_target_mbox'])) {
T 28     $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST))));
29     $target = get_input_value('_target_mbox', RCUBE_INPUT_POST);
30     $moved = $IMAP->move_message($uids, $target, get_input_value('_mbox', RCUBE_INPUT_POST));
4e17e6 31   
e090a1 32     if (!$moved) {
T 33         // send error message
34         $OUTPUT->command('list_mailbox');
35         $OUTPUT->show_message('errormoving', 'error');
36         $OUTPUT->send();
37         exit;
38     }
f11541 39 }
4e17e6 40 // delete messages 
e090a1 41 else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) {
T 42     $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST))));
43     $del = $IMAP->delete_message($uids, get_input_value('_mbox', RCUBE_INPUT_POST));
4e17e6 44   
e090a1 45     if (!$del) {
T 46         // send error message
47         $OUTPUT->command('list_mailbox');
48         $OUTPUT->show_message('errordeleting', 'error');
49         $OUTPUT->send();
50         exit;
51     }
f11541 52 }
4e17e6 53 // unknown action or missing query param
e090a1 54 else {
T 55     exit;
56 }
110748 57 // refresh saved search set after moving some messages
e090a1 58 if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
T 59     $_SESSION['search'][$search_request] = $IMAP->refresh_search();
60 }
04c618 61
e090a1 62 $msg_count      = $IMAP->messagecount();
T 63 $pages          = ceil($msg_count / $IMAP->page_size);
9a3567 64 $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page;
e090a1 65 $remaining      = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1);
c3ab87 66
T 67 // jump back one page (user removed the whole last page)
e090a1 68 if ($IMAP->list_page > 1 && $nextpage_count <= 0 && $remaining == 0) {
T 69     $IMAP->set_page($IMAP->list_page-1);
70     $_SESSION['page'] = $IMAP->list_page;
71     $jump_back = true;
c3ab87 72 }
T 73
4e17e6 74 // update message count display
f11541 75 $OUTPUT->set_env('pagecount', $pages);
d41d67 76 $OUTPUT->set_env('messagecount', $msg_count);
c3ab87 77 $OUTPUT->set_env('current_page', $IMAP->list_page);
f11541 78 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
4e17e6 79
7902df 80
4e17e6 81 // update mailboxlist
T 82 $mbox = $IMAP->get_mailbox_name();
cf1f0f 83 $OUTPUT->command('set_unread_count', $mbox, $IMAP->messagecount($mbox, 'UNSEEN'), ($mbox == 'INBOX'));
7902df 84
e090a1 85 if ($RCMAIL->action=='moveto' && $target) {
T 86     $OUTPUT->command('set_unread_count', $target, $IMAP->messagecount($target, 'UNSEEN'));
87 }
4e17e6 88
6d2714 89 $OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));
4e17e6 90
T 91 // add new rows from next page (if any)
e090a1 92 if ($_POST['_from']!='show' && ($jump_back || $nextpage_count > 0)) {
T 93     $sort_col   = isset($_SESSION['sort_col'])   ? $_SESSION['sort_col']   : $CONFIG['message_sort_col'];
94     $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order'];
04c618 95   
e090a1 96     $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order);
T 97     if (!$jump_back) {
98         $a_headers = array_slice($a_headers, -$count, $count);
99     }
100     rcmail_js_message_list($a_headers);
f11541 101 }
04c618 102
4e17e6 103 // send response
f11541 104 $OUTPUT->send();