]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/mark.inc
94009fbc7612cf003a066db2934f742d4a510fa1
[roundcube.git] / program / steps / mail / mark.inc
1 <?php
2 /*
3  +-----------------------------------------------------------------------+
4  | program/steps/mail/mark.inc                                           |
5  |                                                                       |
6  | This file is part of the Roundcube Webmail client                     |
7  | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
8  | Licensed under the GNU GPL                                            |
9  |                                                                       |
10  | PURPOSE:                                                              |
11  |   Mark the submitted messages with the specified flag                 |
12  |                                                                       |
13  +-----------------------------------------------------------------------+
14  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
15  +-----------------------------------------------------------------------+
16
17  $Id: mark.inc 4410 2011-01-12 18:25:02Z thomasb $
18
19 */
20
21 // only process ajax requests
22 if (!$OUTPUT->ajax_call)
23   return;
24
25 $a_flags_map = array(
26   'undelete' => 'UNDELETED',
27   'delete' => 'DELETED',
28   'read' => 'SEEN',
29   'unread' => 'UNSEEN',
30   'flagged' => 'FLAGGED',
31   'unflagged' => 'UNFLAGGED');
32
33 if (($uids = get_input_value('_uid', RCUBE_INPUT_POST)) && ($flag = get_input_value('_flag', RCUBE_INPUT_POST)))
34 {
35   $flag = $a_flags_map[$flag] ? $a_flags_map[$flag] : strtoupper($flag);
36
37   if ($flag == 'DELETED' && $CONFIG['skip_deleted'] && $_POST['_from'] != 'show') {
38     // count messages before changing anything
39     $old_count = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL');
40     $old_pages = ceil($old_count / $IMAP->page_size);
41     $count = sizeof(explode(',', $uids));
42   }
43
44   $marked = $IMAP->set_flag($uids, $flag);
45
46   if (!$marked) {
47     // send error message
48     if ($_POST['_from'] != 'show')
49       $OUTPUT->command('list_mailbox');
50     rcmail_display_server_error('errormarking');
51     $OUTPUT->send();
52     exit;
53   }
54   else if (empty($_POST['_quiet'])) {
55     $OUTPUT->show_message('messagemarked', 'confirmation');
56   }
57
58   if ($flag == 'DELETED' && $CONFIG['read_when_deleted'] && !empty($_POST['_ruid'])) {
59     $ruids = get_input_value('_ruid', RCUBE_INPUT_POST);
60     $read = $IMAP->set_flag($ruids, 'SEEN');
61
62     if ($read && !$CONFIG['skip_deleted'])
63       $OUTPUT->command('flag_deleted_as_read', $ruids);
64   }
65
66   if ($flag == 'SEEN' || $flag == 'UNSEEN' || ($flag == 'DELETED' && !$CONFIG['skip_deleted'])) {
67     rcmail_send_unread_count($IMAP->get_mailbox_name());
68   }
69   else if ($flag == 'DELETED' && $CONFIG['skip_deleted']) {
70     if ($_POST['_from'] == 'show') {
71       if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC))
72         $OUTPUT->command('show_message', $next);
73       else
74         $OUTPUT->command('command', 'list');
75     } else {
76       // refresh saved search set after moving some messages
77       if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
78         $_SESSION['search'] = $IMAP->refresh_search();
79       }
80
81       $msg_count      = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL');
82       $pages          = ceil($msg_count / $IMAP->page_size);
83       $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page;
84       $remaining      = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1);
85
86       // jump back one page (user removed the whole last page)
87       if ($IMAP->list_page > 1 && $remaining == 0) {
88         $IMAP->set_page($IMAP->list_page-1);
89         $_SESSION['page'] = $IMAP->list_page;
90         $jump_back = true;
91       }
92
93       // update message count display
94       $OUTPUT->set_env('messagecount', $msg_count);
95       $OUTPUT->set_env('current_page', $IMAP->list_page);
96       $OUTPUT->set_env('pagecount', $pages);
97
98       // update mailboxlist
99       $mbox = $IMAP->get_mailbox_name();
100       $unseen_count = $msg_count ? $IMAP->messagecount($mbox, 'UNSEEN') : 0;
101       $old_unseen = rcmail_get_unseen_count($mbox);
102
103       if ($old_unseen != $unseen_count) {
104         $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX'));
105         rcmail_set_unseen_count($mbox, $unseen_count);
106       }
107       $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
108
109       if ($IMAP->threading)
110             $count = get_input_value('_count', RCUBE_INPUT_POST);
111
112       // add new rows from next page (if any)
113       if ($count && $uids != '*' && ($jump_back || $nextpage_count > 0)) {
114         $sort_col   = isset($_SESSION['sort_col'])   ? $_SESSION['sort_col']   : $CONFIG['message_sort_col'];
115         $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order'];
116
117         $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order,
118             $jump_back ? NULL : $count);
119
120         rcmail_js_message_list($a_headers, false);
121       }
122     }
123   }
124
125   $OUTPUT->send();
126 }
127
128 exit;
129