alecpl
2008-10-03 cf6a833c95a341c1eada992ed09afc650493fdaa
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);
928188 30     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
A 31     $moved = $IMAP->move_message($uids, $target, $mbox);
4e17e6 32   
928188 33     if (!$moved) {
e090a1 34         // send error message
T 35         $OUTPUT->command('list_mailbox');
36         $OUTPUT->show_message('errormoving', 'error');
37         $OUTPUT->send();
38         exit;
39     }
928188 40
A 41     // flag old messages as read because rcube_imap will not send expunge command after moving
42     if ($CONFIG['read_when_deleted'])
43         $IMAP->set_flag($uids, 'SEEN');
44
45     if (!$CONFIG['flag_for_deletion'])
46         $addrows = true;
f11541 47 }
4e17e6 48 // delete messages 
e090a1 49 else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) {
T 50     $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST))));
928188 51     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
A 52     $del = $IMAP->delete_message($uids, $mbox);
4e17e6 53   
e090a1 54     if (!$del) {
T 55         // send error message
56         $OUTPUT->command('list_mailbox');
57         $OUTPUT->show_message('errordeleting', 'error');
58         $OUTPUT->send();
59         exit;
60     }
928188 61     
A 62     $addrows = true;
f11541 63 }
4e17e6 64 // unknown action or missing query param
e090a1 65 else {
T 66     exit;
67 }
110748 68 // refresh saved search set after moving some messages
e090a1 69 if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
T 70     $_SESSION['search'][$search_request] = $IMAP->refresh_search();
71 }
04c618 72
e090a1 73 $msg_count      = $IMAP->messagecount();
T 74 $pages          = ceil($msg_count / $IMAP->page_size);
9a3567 75 $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page;
e090a1 76 $remaining      = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1);
c3ab87 77
T 78 // jump back one page (user removed the whole last page)
e090a1 79 if ($IMAP->list_page > 1 && $nextpage_count <= 0 && $remaining == 0) {
T 80     $IMAP->set_page($IMAP->list_page-1);
81     $_SESSION['page'] = $IMAP->list_page;
82     $jump_back = true;
c3ab87 83 }
T 84
4e17e6 85 // update message count display
f11541 86 $OUTPUT->set_env('pagecount', $pages);
d41d67 87 $OUTPUT->set_env('messagecount', $msg_count);
c3ab87 88 $OUTPUT->set_env('current_page', $IMAP->list_page);
f11541 89 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
4e17e6 90
T 91 // update mailboxlist
92 $mbox = $IMAP->get_mailbox_name();
cf1f0f 93 $OUTPUT->command('set_unread_count', $mbox, $IMAP->messagecount($mbox, 'UNSEEN'), ($mbox == 'INBOX'));
7902df 94
e090a1 95 if ($RCMAIL->action=='moveto' && $target) {
T 96     $OUTPUT->command('set_unread_count', $target, $IMAP->messagecount($target, 'UNSEEN'));
97 }
4e17e6 98
6d2714 99 $OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));
4e17e6 100
T 101 // add new rows from next page (if any)
928188 102 if ($addrows && $_POST['_from']!='show' && ($jump_back || $nextpage_count > 0)) {
e090a1 103     $sort_col   = isset($_SESSION['sort_col'])   ? $_SESSION['sort_col']   : $CONFIG['message_sort_col'];
T 104     $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order'];
04c618 105   
e090a1 106     $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order);
T 107     if (!$jump_back) {
108         $a_headers = array_slice($a_headers, -$count, $count);
109     }
110     rcmail_js_message_list($a_headers);
f11541 111 }
04c618 112
4e17e6 113 // send response
f11541 114 $OUTPUT->send();