]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/move_del.inc
Imported Upstream version 0.2~stable
[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 2018 2008-10-27 10:53:56Z 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     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
31
32     // flag messages as read before moving them
33     if ($CONFIG['read_when_deleted'] && $target == $CONFIG['trash_mbox'])
34         $IMAP->set_flag($uids, 'SEEN');
35
36     $moved = $IMAP->move_message($uids, $target, $mbox);
37   
38     if (!$moved) {
39         // send error message
40         $OUTPUT->command('list_mailbox');
41         $OUTPUT->show_message('errormoving', 'error');
42         $OUTPUT->send();
43         exit;
44     }
45
46     if (!$CONFIG['flag_for_deletion'])
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     $del = $IMAP->delete_message($uids, $mbox);
54   
55     if (!$del) {
56         // send error message
57         $OUTPUT->command('list_mailbox');
58         $OUTPUT->show_message('errordeleting', 'error');
59         $OUTPUT->send();
60         exit;
61     }
62     
63     $addrows = true;
64 }
65 // unknown action or missing query param
66 else {
67     exit;
68 }
69 // refresh saved search set after moving some messages
70 if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
71     $_SESSION['search'][$search_request] = $IMAP->refresh_search();
72 }
73
74 $msg_count      = $IMAP->messagecount();
75 $pages          = ceil($msg_count / $IMAP->page_size);
76 $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page;
77 $remaining      = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1);
78
79 // jump back one page (user removed the whole last page)
80 if ($IMAP->list_page > 1 && $nextpage_count <= 0 && $remaining == 0) {
81     $IMAP->set_page($IMAP->list_page-1);
82     $_SESSION['page'] = $IMAP->list_page;
83     $jump_back = true;
84 }
85
86 // update message count display
87 $OUTPUT->set_env('pagecount', $pages);
88 $OUTPUT->set_env('messagecount', $msg_count);
89 $OUTPUT->set_env('current_page', $IMAP->list_page);
90 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
91
92 // update mailboxlist
93 $mbox = $IMAP->get_mailbox_name();
94 $OUTPUT->command('set_unread_count', $mbox, $IMAP->messagecount($mbox, 'UNSEEN'), ($mbox == 'INBOX'));
95
96 if ($RCMAIL->action=='moveto' && $target) {
97     $OUTPUT->command('set_unread_count', $target, $IMAP->messagecount($target, 'UNSEEN'));
98 }
99
100 $OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));
101
102 // add new rows from next page (if any)
103 if ($addrows && $_POST['_from']!='show' && ($jump_back || $nextpage_count > 0)) {
104     $sort_col   = isset($_SESSION['sort_col'])   ? $_SESSION['sort_col']   : $CONFIG['message_sort_col'];
105     $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order'];
106   
107     $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order);
108     if (!$jump_back) {
109         $a_headers = array_slice($a_headers, -$count, $count);
110     }
111     rcmail_js_message_list($a_headers);
112 }
113
114 // send response
115 $OUTPUT->send();