source: subversion/trunk/roundcubemail/program/steps/mail/list.inc @ 5266

Last change on this file since 5266 was 5266, checked in by alec, 20 months ago
  • Fix bug where after delete message rows can be added to the list of another folder (#1487752)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/list.inc                                           |
6 |                                                                       |
7 | This file is part of the Roundcube Webmail client                     |
8 | Copyright (C) 2005-2007, The Roundcube Dev Team                       |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Send message list to client (as remote response)                    |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
22if (!$OUTPUT->ajax_call) {
23  return;
24}
25
26// is there a sort type for this request?
27if ($sort = get_input_value('_sort', RCUBE_INPUT_GET))
28{
29  // yes, so set the sort vars
30  list($sort_col, $sort_order) = explode('_', $sort);
31
32  // set session vars for sort (so next page and task switch know how to sort)
33  $save_arr = array();
34  $_SESSION['sort_col'] = $save_arr['message_sort_col'] = $sort_col;
35  $_SESSION['sort_order'] = $save_arr['message_sort_order'] = $sort_order;
36}
37else
38{
39  // use session settings if set, defaults if not
40  $sort_col   = isset($_SESSION['sort_col'])   ? $_SESSION['sort_col']   : $CONFIG['message_sort_col'];
41  $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order'];
42}
43
44// is there a set of columns for this request?
45if ($cols = get_input_value('_cols', RCUBE_INPUT_GET))
46{
47  $save_arr = array();
48  $save_arr['list_cols'] = explode(',', $cols);
49}
50
51if ($save_arr)
52  $RCMAIL->user->save_prefs($save_arr);
53
54$mbox_name = $IMAP->get_mailbox_name();
55
56// Synchronize mailbox cache, handle flag changes
57$IMAP->mailbox_sync($mbox_name);
58
59// initialize searching result if search_filter is used
60if ($_SESSION['search_filter'] && $_SESSION['search_filter'] != 'ALL')
61{
62  $search_request = md5($mbox_name.$_SESSION['search_filter']);
63  $IMAP->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $sort_col);
64  $_SESSION['search'] = $IMAP->get_search_set();
65  $_SESSION['search_request'] = $search_request;
66  $OUTPUT->set_env('search_request', $search_request);
67}
68
69// fetch message headers
70if ($count = $IMAP->messagecount($mbox_name, $IMAP->threading ? 'THREADS' : 'ALL', !empty($_REQUEST['_refresh'])))
71  $a_headers = $IMAP->list_headers($mbox_name, NULL, $sort_col, $sort_order);
72
73// update search set (possible change of threading mode)
74if (!empty($_REQUEST['_search']) && isset($_SESSION['search'])
75    && $_SESSION['search_request'] == $_REQUEST['_search']
76) {
77  $_SESSION['search'] = $IMAP->get_search_set();
78}
79// remove old search data
80else if (empty($_REQUEST['_search']) && isset($_SESSION['search'])) {
81  $RCMAIL->session->remove('search');
82}
83
84
85// empty result? we'll skip UNSEEN counting in rcmail_send_unread_count()
86if (empty($search_request) && empty($a_headers)) {
87    $unseen = 0;
88}
89
90// update mailboxlist
91rcmail_send_unread_count($mbox_name, !empty($_REQUEST['_refresh']), $unseen);
92
93// update message count display
94$pages = ceil($count/$IMAP->page_size);
95$OUTPUT->set_env('messagecount', $count);
96$OUTPUT->set_env('pagecount', $pages);
97$OUTPUT->set_env('threading', (bool) $IMAP->threading);
98$OUTPUT->set_env('current_page', $count ? $IMAP->list_page : 1);
99$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count), $mbox_name);
100$OUTPUT->command('set_mailboxname', rcmail_get_mailbox_name_text());
101
102// add message rows
103rcmail_js_message_list($a_headers, FALSE, $cols);
104if (isset($a_headers) && count($a_headers))
105{
106  if ($search_request)
107    $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $count));
108}
109else {
110  // handle IMAP errors (e.g. #1486905)
111  if ($err_code = $IMAP->get_error_code()) {
112    rcmail_display_server_error();
113  }
114  else if ($search_request)
115    $OUTPUT->show_message('searchnomatch', 'notice');
116  else
117    $OUTPUT->show_message('nomessagesfound', 'notice');
118}
119
120// send response
121$OUTPUT->send();
Note: See TracBrowser for help on using the repository browser.