]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/move_del.inc
Imported Upstream version 0.3
[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-2009, 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 2758 2009-07-16 15:01:05Z thomasb $
19
20 */
21
22 // only process ajax requests
23 if (!$OUTPUT->ajax_call)
24   return;
25
26 // count messages before changing anything
27 $old_count = $IMAP->messagecount();
28 $old_pages = ceil($old_count / $IMAP->page_size);
29
30 // move messages
31 if ($RCMAIL->action=='moveto' && !empty($_POST['_uid']) && !empty($_POST['_target_mbox'])) {
32     $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST))));
33     $target = get_input_value('_target_mbox', RCUBE_INPUT_POST);
34     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
35
36     // flag messages as read before moving them
37     if ($CONFIG['read_when_deleted'] && $target == $CONFIG['trash_mbox'])
38         $IMAP->set_flag($uids, 'SEEN');
39
40     $moved = $IMAP->move_message($uids, $target, $mbox);
41   
42     if (!$moved) {
43         // send error message
44         if ($_POST['_from'] != 'show')
45           $OUTPUT->command('list_mailbox');
46         $OUTPUT->show_message('errormoving', 'error');
47         $OUTPUT->send();
48         exit;
49     }
50
51     $addrows = true;
52 }
53 // delete messages 
54 else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) {
55     $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST))));
56     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
57     $del = $IMAP->delete_message($uids, $mbox);
58   
59     if (!$del) {
60         // send error message
61         if ($_POST['_from'] != 'show')
62           $OUTPUT->command('list_mailbox');
63         $OUTPUT->show_message('errordeleting', 'error');
64         $OUTPUT->send();
65         exit;
66     }
67     
68     $addrows = true;
69 }
70 // unknown action or missing query param
71 else {
72     exit;
73 }
74
75 // refresh saved search set after moving some messages
76 if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
77     $_SESSION['search'][$search_request] = $IMAP->refresh_search();
78 }
79
80 if ($_POST['_from'] == 'show')
81 {
82   if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC))
83     $OUTPUT->command('show_message', $next);
84   else
85     $OUTPUT->command('command', 'list');
86 }
87 else
88 {
89   $msg_count      = $IMAP->messagecount();
90   $pages          = ceil($msg_count / $IMAP->page_size);
91   $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page;
92   $remaining      = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1);
93
94   // jump back one page (user removed the whole last page)
95   if ($IMAP->list_page > 1 && $nextpage_count <= 0 && $remaining == 0) {
96     $IMAP->set_page($IMAP->list_page-1);
97     $_SESSION['page'] = $IMAP->list_page;
98     $jump_back = true;
99   }
100
101   // update message count display
102   $OUTPUT->set_env('messagecount', $msg_count);
103   $OUTPUT->set_env('current_page', $IMAP->list_page);
104   $OUTPUT->set_env('pagecount', $pages);
105
106   // update mailboxlist
107   $mbox = $IMAP->get_mailbox_name();
108   $unseen_count = $msg_count ? $IMAP->messagecount($mbox, 'UNSEEN') : 0;
109   $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX'));
110
111   if ($RCMAIL->action=='moveto' && $target) {
112     $OUTPUT->command('set_unread_count', $target, $IMAP->messagecount($target, 'UNSEEN'));
113   }
114
115   $OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));
116   $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
117
118   // add new rows from next page (if any)
119   if ($addrows && ($jump_back || $nextpage_count > 0)) {
120     $sort_col   = isset($_SESSION['sort_col'])   ? $_SESSION['sort_col']   : $CONFIG['message_sort_col'];
121     $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order'];
122
123     $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order, $count);
124
125     rcmail_js_message_list($a_headers, false, false);
126   }
127 }
128
129 // send response
130 $OUTPUT->send();
131
132 ?>