thomascube
2010-12-17 db1a87cd6c506f2afbd1a37c64cb56ae11120b49
commit | author | age
4e17e6 1 <?php
T 2 /*
3  +-----------------------------------------------------------------------+
4  | program/steps/mail/mark.inc                                           |
5  |                                                                       |
e019f2 6  | This file is part of the Roundcube Webmail client                     |
A 7  | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland                 |
30233b 8  | Licensed under the GNU GPL                                            |
4e17e6 9  |                                                                       |
T 10  | PURPOSE:                                                              |
11  |   Mark the submitted messages with the specified flag                 |
12  |                                                                       |
13  +-----------------------------------------------------------------------+
14  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
15  +-----------------------------------------------------------------------+
16
17  $Id$
18
19 */
20
881217 21 // only process ajax requests
T 22 if (!$OUTPUT->ajax_call)
23   return;
24
f11541 25 $a_flags_map = array(
T 26   'undelete' => 'UNDELETED',
27   'delete' => 'DELETED',
28   'read' => 'SEEN',
e189a6 29   'unread' => 'UNSEEN',
A 30   'flagged' => 'FLAGGED',
31   'unflagged' => 'UNFLAGGED');
4e17e6 32
8d0758 33 if (($uids = get_input_value('_uid', RCUBE_INPUT_POST)) && ($flag = get_input_value('_flag', RCUBE_INPUT_POST)))
f11541 34 {
b3ce79 35   $flag = $a_flags_map[$flag] ? $a_flags_map[$flag] : strtoupper($flag);
cd9a03 36
A 37   if ($flag == 'DELETED' && $CONFIG['skip_deleted'] && $_POST['_from'] != 'show') {
38     // count messages before changing anything
f52c93 39     $old_count = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL');
cd9a03 40     $old_pages = ceil($old_count / $IMAP->page_size);
A 41     $count = sizeof(explode(',', $uids));
42   }
43
b3ce79 44   $marked = $IMAP->set_flag($uids, $flag);
c833ed 45
c309cd 46   if (!$marked) {
0b2ce9 47     // send error message
A 48     if ($_POST['_from'] != 'show')
49       $OUTPUT->command('list_mailbox');
db1a87 50     rcmail_display_server_error('errormarking');
0b2ce9 51     $OUTPUT->send();
A 52     exit;
53   }
1555ac 54   else if (empty($_POST['_quiet'])) {
c50d88 55     $OUTPUT->show_message('messagemarked', 'confirmation');
A 56   }
f11541 57
fb7ec5 58   if ($flag == 'DELETED' && $CONFIG['read_when_deleted'] && !empty($_POST['_ruid'])) {
A 59     $ruids = get_input_value('_ruid', RCUBE_INPUT_POST);
60     $read = $IMAP->set_flag($ruids, 'SEEN');
c833ed 61
c309cd 62     if ($read && !$CONFIG['skip_deleted'])
fb7ec5 63       $OUTPUT->command('flag_deleted_as_read', $ruids);
0b2ce9 64   }
fb7ec5 65
0b2ce9 66   if ($flag == 'SEEN' || $flag == 'UNSEEN' || ($flag == 'DELETED' && !$CONFIG['skip_deleted'])) {
cbeea3 67     rcmail_send_unread_count($IMAP->get_mailbox_name());
4e17e6 68   }
0b2ce9 69   else if ($flag == 'DELETED' && $CONFIG['skip_deleted']) {
A 70     if ($_POST['_from'] == 'show') {
71       if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC))
d5515f 72         $OUTPUT->command('show_message', $next);
0b2ce9 73       else
d5515f 74         $OUTPUT->command('command', 'list');
0b2ce9 75     } else {
A 76       // refresh saved search set after moving some messages
77       if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
f6aac3 78         $_SESSION['search'] = $IMAP->refresh_search();
0b2ce9 79       }
A 80
f52c93 81       $msg_count      = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL');
0b2ce9 82       $pages          = ceil($msg_count / $IMAP->page_size);
A 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)
a039c6 87       if ($IMAP->list_page > 1 && $remaining == 0) {
d5515f 88         $IMAP->set_page($IMAP->list_page-1);
T 89         $_SESSION['page'] = $IMAP->list_page;
90         $jump_back = true;
0b2ce9 91       }
A 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();
011b02 100       $unseen_count = $msg_count ? $IMAP->messagecount($mbox, 'UNSEEN') : 0;
db1a87 101       $old_unseen = rcmail_get_unseen_count($mbox);
a039c6 102
78925f 103       if ($old_unseen != $unseen_count) {
A 104         $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX'));
db1a87 105         rcmail_set_unseen_count($mbox, $unseen_count);
78925f 106       }
0b2ce9 107       $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
A 108
f52c93 109       if ($IMAP->threading)
fb7ec5 110         $count = get_input_value('_count', RCUBE_INPUT_POST);
f52c93 111
0b2ce9 112       // add new rows from next page (if any)
fb7ec5 113       if ($count && $uids != '*' && ($jump_back || $nextpage_count > 0)) {
d5515f 114         $sort_col   = isset($_SESSION['sort_col'])   ? $_SESSION['sort_col']   : $CONFIG['message_sort_col'];
T 115         $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order'];
c833ed 116
a039c6 117         $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order,
fb7ec5 118         $jump_back ? NULL : $count);
c833ed 119
e99d21 120         rcmail_js_message_list($a_headers, false);
0b2ce9 121       }
A 122     }
123   }
c833ed 124
e70b3b 125   $OUTPUT->send();
f11541 126 }
c833ed 127
4e17e6 128 exit;
b25dfd 129