]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/move_del.inc
Imported Upstream version 0.2~alpha
[roundcube.git] / program / steps / mail / move_del.inc
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-2007, 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: move_del.inc 1359 2008-05-06 16:56:42Z alec $
19
20 */
21
22 // count messages before changing anything
23 $old_count = $IMAP->messagecount();
24 $old_pages = ceil($old_count / $IMAP->page_size);
25
26 // move messages
27 if ($RCMAIL->action=='moveto' && !empty($_POST['_uid']) && !empty($_POST['_target_mbox'])) {
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));
31   
32     if (!$moved) {
33         // send error message
34         $OUTPUT->command('list_mailbox');
35         $OUTPUT->show_message('errormoving', 'error');
36         $OUTPUT->send();
37         exit;
38     }
39 }
40 // delete messages 
41 else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) {
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));
44   
45     if (!$del) {
46         // send error message
47         $OUTPUT->command('list_mailbox');
48         $OUTPUT->show_message('errordeleting', 'error');
49         $OUTPUT->send();
50         exit;
51     }
52 }
53 // unknown action or missing query param
54 else {
55     exit;
56 }
57 // refresh saved search set after moving some messages
58 if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
59     $_SESSION['search'][$search_request] = $IMAP->refresh_search();
60 }
61
62 $msg_count      = $IMAP->messagecount();
63 $pages          = ceil($msg_count / $IMAP->page_size);
64 $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page;
65 $remaining      = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1);
66
67 // jump back one page (user removed the whole last page)
68 if ($IMAP->list_page > 1 && $nextpage_count <= 0 && $remaining == 0) {
69     $IMAP->set_page($IMAP->list_page-1);
70     $_SESSION['page'] = $IMAP->list_page;
71     $jump_back = true;
72 }
73
74 // update message count display
75 $OUTPUT->set_env('pagecount', $pages);
76 $OUTPUT->set_env('messagecount', $msg_count);
77 $OUTPUT->set_env('current_page', $IMAP->list_page);
78 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
79
80
81 // update mailboxlist
82 $mbox = $IMAP->get_mailbox_name();
83 $OUTPUT->command('set_unread_count', $mbox, $IMAP->messagecount($mbox, 'UNSEEN'), ($mbox == 'INBOX'));
84
85 if ($RCMAIL->action=='moveto' && $target) {
86     $OUTPUT->command('set_unread_count', $target, $IMAP->messagecount($target, 'UNSEEN'));
87 }
88
89 $OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));
90
91 // add new rows from next page (if any)
92 if ($_POST['_from']!='show' && ($jump_back || $nextpage_count > 0)) {
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'];
95   
96     $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order);
97     if (!$jump_back) {
98         $a_headers = array_slice($a_headers, -$count, $count);
99     }
100     rcmail_js_message_list($a_headers);
101 }
102
103 // send response
104 $OUTPUT->send();