thomascube
2010-12-17 db1a87cd6c506f2afbd1a37c64cb56ae11120b49
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/move_del.inc                                       |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
A 8  | Copyright (C) 2005-2009, 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
881217 22 // only process ajax requests
T 23 if (!$OUTPUT->ajax_call)
24   return;
25
c3ab87 26 // count messages before changing anything
f52c93 27 $old_count = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL');
9a3567 28 $old_pages = ceil($old_count / $IMAP->page_size);
51e14a 29
4e17e6 30 // move messages
448409 31 if ($RCMAIL->action=='moveto' && !empty($_POST['_uid']) && strlen($_POST['_target_mbox'])) {
e090a1 32     $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST))));
b72e2f 33     $target = get_input_value('_target_mbox', RCUBE_INPUT_POST, true);
A 34     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true);
285551 35
928188 36     $moved = $IMAP->move_message($uids, $target, $mbox);
fb7ec5 37
928188 38     if (!$moved) {
e090a1 39         // send error message
fb7ec5 40         if ($_POST['_from'] != 'show')
A 41             $OUTPUT->command('list_mailbox');
db1a87 42         rcmail_display_server_error('errormoving');
e090a1 43         $OUTPUT->send();
T 44         exit;
45     }
c50d88 46     else {
A 47       $OUTPUT->show_message('messagemoved', 'confirmation');
48     }
928188 49
0b2ce9 50     $addrows = true;
f11541 51 }
4e17e6 52 // delete messages 
e090a1 53 else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) {
T 54     $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST))));
b72e2f 55     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true);
f52c93 56
928188 57     $del = $IMAP->delete_message($uids, $mbox);
c50d88 58
e090a1 59     if (!$del) {
T 60         // send error message
fb7ec5 61         if ($_POST['_from'] != 'show')
A 62             $OUTPUT->command('list_mailbox');
db1a87 63         rcmail_display_server_error('errordeleting');
e090a1 64         $OUTPUT->send();
T 65         exit;
66     }
c50d88 67     else {
A 68       $OUTPUT->show_message('messagedeleted', 'confirmation');
69     }
70
928188 71     $addrows = true;
f11541 72 }
4e17e6 73 // unknown action or missing query param
e090a1 74 else {
T 75     exit;
76 }
dc2fc0 77
110748 78 // refresh saved search set after moving some messages
e090a1 79 if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
f6aac3 80     $_SESSION['search'] = $IMAP->refresh_search();
e090a1 81 }
04c618 82
dc2fc0 83 if ($_POST['_from'] == 'show')
A 84 {
85   if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC))
86     $OUTPUT->command('show_message', $next);
87   else
88     $OUTPUT->command('command', 'list');
89 }
90 else
91 {
f52c93 92   $msg_count      = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL');
dc2fc0 93   $pages          = ceil($msg_count / $IMAP->page_size);
A 94   $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page;
95   $remaining      = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1);
c3ab87 96
dc2fc0 97   // jump back one page (user removed the whole last page)
a039c6 98   if ($IMAP->list_page > 1 && $remaining == 0) {
e090a1 99     $IMAP->set_page($IMAP->list_page-1);
T 100     $_SESSION['page'] = $IMAP->list_page;
101     $jump_back = true;
dc2fc0 102   }
c3ab87 103
dc2fc0 104   // update message count display
A 105   $OUTPUT->set_env('messagecount', $msg_count);
106   $OUTPUT->set_env('current_page', $IMAP->list_page);
107   $OUTPUT->set_env('pagecount', $pages);
4e17e6 108
dc2fc0 109   // update mailboxlist
A 110   $mbox = $IMAP->get_mailbox_name();
011b02 111   $unseen_count = $msg_count ? $IMAP->messagecount($mbox, 'UNSEEN') : 0;
db1a87 112   $old_unseen = rcmail_get_unseen_count($mbox);
T 113
78925f 114   if ($old_unseen != $unseen_count) {
A 115     $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX'));
db1a87 116     rcmail_set_unseen_count($mbox, $unseen_count);
78925f 117   }
7902df 118
448409 119   if ($RCMAIL->action=='moveto' && strlen($target)) {
cbeea3 120     rcmail_send_unread_count($target, true);
dc2fc0 121   }
4e17e6 122
5b3ed5 123   $OUTPUT->command('set_quota', rcmail_quota_content());
dc2fc0 124   $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
4e17e6 125
f52c93 126   if ($IMAP->threading)
T 127     $count = get_input_value('_count', RCUBE_INPUT_POST);
128
dc2fc0 129   // add new rows from next page (if any)
fb7ec5 130   if ($addrows && $count && $uids != '*' && ($jump_back || $nextpage_count > 0)) {
e090a1 131     $sort_col   = isset($_SESSION['sort_col'])   ? $_SESSION['sort_col']   : $CONFIG['message_sort_col'];
T 132     $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order'];
34ebe0 133
a039c6 134     $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order,
A 135       $jump_back ? NULL : $count);
34ebe0 136
e99d21 137     rcmail_js_message_list($a_headers, false);
dc2fc0 138   }
f11541 139 }
04c618 140
4e17e6 141 // send response
f11541 142 $OUTPUT->send();
dc2fc0 143
b25dfd 144