alecpl
2010-07-26 d5d968048601fa1d519f7cfee11f23918afc186c
commit | author | age
4e17e6 1 <?php
T 2 /*
3  +-----------------------------------------------------------------------+
4  | program/steps/mail/mark.inc                                           |
5  |                                                                       |
6  | This file is part of the RoundCube Webmail client                     |
881217 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
0b2ce9 46   if ($marked == -1) {
A 47     // send error message
48     if ($_POST['_from'] != 'show')
49       $OUTPUT->command('list_mailbox');
50     $OUTPUT->show_message('errormarking', 'error');
51     $OUTPUT->send();
52     exit;
53   }
f11541 54
fb7ec5 55   if ($flag == 'DELETED' && $CONFIG['read_when_deleted'] && !empty($_POST['_ruid'])) {
A 56     $ruids = get_input_value('_ruid', RCUBE_INPUT_POST);
57     $read = $IMAP->set_flag($ruids, 'SEEN');
c833ed 58
0b2ce9 59     if ($read != -1 && !$CONFIG['skip_deleted'])
fb7ec5 60       $OUTPUT->command('flag_deleted_as_read', $ruids);
0b2ce9 61   }
fb7ec5 62
0b2ce9 63   if ($flag == 'SEEN' || $flag == 'UNSEEN' || ($flag == 'DELETED' && !$CONFIG['skip_deleted'])) {
cbeea3 64     rcmail_send_unread_count($IMAP->get_mailbox_name());
4e17e6 65   }
0b2ce9 66   else if ($flag == 'DELETED' && $CONFIG['skip_deleted']) {
A 67     if ($_POST['_from'] == 'show') {
68       if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC))
d5515f 69         $OUTPUT->command('show_message', $next);
0b2ce9 70       else
d5515f 71         $OUTPUT->command('command', 'list');
0b2ce9 72     } else {
A 73       // refresh saved search set after moving some messages
74       if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
75         $_SESSION['search'][$search_request] = $IMAP->refresh_search();
76       }
77
f52c93 78       $msg_count      = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL');
0b2ce9 79       $pages          = ceil($msg_count / $IMAP->page_size);
A 80       $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page;
81       $remaining      = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1);
82
83       // jump back one page (user removed the whole last page)
a039c6 84       if ($IMAP->list_page > 1 && $remaining == 0) {
d5515f 85         $IMAP->set_page($IMAP->list_page-1);
T 86         $_SESSION['page'] = $IMAP->list_page;
87         $jump_back = true;
0b2ce9 88       }
A 89
90       // update message count display
91       $OUTPUT->set_env('messagecount', $msg_count);
92       $OUTPUT->set_env('current_page', $IMAP->list_page);
93       $OUTPUT->set_env('pagecount', $pages);
94
95       // update mailboxlist
96       $mbox = $IMAP->get_mailbox_name();
011b02 97       $unseen_count = $msg_count ? $IMAP->messagecount($mbox, 'UNSEEN') : 0;
78925f 98       $old_unseen = $_SESSION['unseen_count'][$mbox];
a039c6 99
78925f 100       if ($old_unseen != $unseen_count) {
A 101         $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX'));
fb7ec5 102         $_SESSION['unseen_count'][$mbox] = $unseen_count;
78925f 103       }
0b2ce9 104       $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
A 105
f52c93 106       if ($IMAP->threading)
fb7ec5 107         $count = get_input_value('_count', RCUBE_INPUT_POST);
f52c93 108
0b2ce9 109       // add new rows from next page (if any)
fb7ec5 110       if ($count && $uids != '*' && ($jump_back || $nextpage_count > 0)) {
d5515f 111         $sort_col   = isset($_SESSION['sort_col'])   ? $_SESSION['sort_col']   : $CONFIG['message_sort_col'];
T 112         $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order'];
c833ed 113
a039c6 114         $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order,
fb7ec5 115         $jump_back ? NULL : $count);
c833ed 116
e99d21 117         rcmail_js_message_list($a_headers, false);
0b2ce9 118       }
A 119     }
120   }
c833ed 121
e70b3b 122   $OUTPUT->send();
f11541 123 }
c833ed 124
4e17e6 125 exit;
b25dfd 126