]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/mark.inc
Imported Upstream version 0.3
[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, RoundCube Dev. - Switzerland                 |
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 2758 2009-07-16 15:01:05Z 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();
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 == -1) {
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   }
54
55   if($flag == 'DELETED' && $CONFIG['read_when_deleted'] && !empty($_POST['_ruid'])) {
56     $uids = get_input_value('_ruid', RCUBE_INPUT_POST);
57     $read = $IMAP->set_flag($uids, 'SEEN');
58     
59     if ($read != -1 && !$CONFIG['skip_deleted'])
60       $OUTPUT->command('flag_deleted_as_read', $uids);
61   }
62     
63   if ($flag == 'SEEN' || $flag == 'UNSEEN' || ($flag == 'DELETED' && !$CONFIG['skip_deleted'])) {
64     $mbox_name = $IMAP->get_mailbox_name();
65     $OUTPUT->command('set_unread_count', $mbox_name, $IMAP->messagecount($mbox_name, 'UNSEEN'), ($mbox_name == 'INBOX'));
66   }
67   else if ($flag == 'DELETED' && $CONFIG['skip_deleted']) {
68     if ($_POST['_from'] == 'show') {
69       if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC))
70         $OUTPUT->command('show_message', $next);
71       else
72         $OUTPUT->command('command', 'list');
73     } else {
74       // refresh saved search set after moving some messages
75       if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
76         $_SESSION['search'][$search_request] = $IMAP->refresh_search();
77       }
78
79       $msg_count      = $IMAP->messagecount();
80       $pages          = ceil($msg_count / $IMAP->page_size);
81       $nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page;
82       $remaining      = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1);
83
84       // jump back one page (user removed the whole last page)
85       if ($IMAP->list_page > 1 && $nextpage_count <= 0 && $remaining == 0) {
86         $IMAP->set_page($IMAP->list_page-1);
87         $_SESSION['page'] = $IMAP->list_page;
88         $jump_back = true;
89       }
90
91       // update message count display
92       $OUTPUT->set_env('messagecount', $msg_count);
93       $OUTPUT->set_env('current_page', $IMAP->list_page);
94       $OUTPUT->set_env('pagecount', $pages);
95
96       // update mailboxlist
97       $mbox = $IMAP->get_mailbox_name();
98       $unseen_count = $msg_count ? $IMAP->messagecount($mbox, 'UNSEEN') : 0;
99       $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX'));
100       $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
101
102       // add new rows from next page (if any)
103       if (($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, $count);
108       
109         rcmail_js_message_list($a_headers, false, false);
110       }
111     }
112   }
113   
114   $OUTPUT->send();
115 }
116   
117 exit;
118 ?>