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

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