commit | author | age
|
95c2c3
|
1 |
<?php |
T |
2 |
/* |
|
3 |
+-----------------------------------------------------------------------+ |
|
4 |
| steps/mail/search.inc | |
|
5 |
| | |
|
6 |
| Search functions for rc webmail | |
|
7 |
| Licensed under the GNU GPL | |
|
8 |
| | |
|
9 |
+-----------------------------------------------------------------------+ |
|
10 |
| Author: Benjamin Smith <defitro@gmail.com> | |
42000a
|
11 |
| Thomas Bruederli <roundcube@gmail.com> | |
95c2c3
|
12 |
+-----------------------------------------------------------------------+ |
T |
13 |
|
580ff9
|
14 |
$Id$ |
A |
15 |
|
95c2c3
|
16 |
*/ |
T |
17 |
|
|
18 |
$REMOTE_REQUEST = TRUE; |
|
19 |
|
04c618
|
20 |
// reset list_page and old search results |
95c2c3
|
21 |
$IMAP->set_page(1); |
04c618
|
22 |
$IMAP->set_search_set(NULL); |
95c2c3
|
23 |
$_SESSION['page'] = 1; |
T |
24 |
|
4d4264
|
25 |
// using encodeURI with javascript "should" give us |
ecb9fb
|
26 |
// a correctly encoded query string |
A |
27 |
$imap_charset = RCMAIL_CHARSET; |
42000a
|
28 |
|
95c2c3
|
29 |
// get search string |
f11541
|
30 |
$str = get_input_value('_q', RCUBE_INPUT_GET); |
e538b3
|
31 |
$filter = get_input_value('_filter', RCUBE_INPUT_GET); |
95c2c3
|
32 |
$mbox = get_input_value('_mbox', RCUBE_INPUT_GET); |
30b152
|
33 |
$headers = get_input_value('_headers', RCUBE_INPUT_GET); |
e538b3
|
34 |
$search_request = md5($mbox.$filter.$str); |
95c2c3
|
35 |
|
e538b3
|
36 |
// add list filter string |
A |
37 |
$search_str = $filter && $filter != 'ALL' ? $filter : ''; |
|
38 |
|
|
39 |
$_SESSION['search_filter'] = $filter; |
95c2c3
|
40 |
|
T |
41 |
// Check the search string for type of search |
e538b3
|
42 |
if (preg_match("/^from:.*/i", $str)) |
04c618
|
43 |
{ |
95c2c3
|
44 |
list(,$srch) = explode(":", $str); |
30b152
|
45 |
$subject['from'] = "HEADER FROM"; |
95c2c3
|
46 |
} |
1af6fe
|
47 |
else if (preg_match("/^to:.*/i", $str)) |
04c618
|
48 |
{ |
95c2c3
|
49 |
list(,$srch) = explode(":", $str); |
30b152
|
50 |
$subject['to'] = "HEADER TO"; |
95c2c3
|
51 |
} |
e538b3
|
52 |
else if (preg_match("/^cc:.*/i", $str)) |
04c618
|
53 |
{ |
95c2c3
|
54 |
list(,$srch) = explode(":", $str); |
30b152
|
55 |
$subject['cc'] = "HEADER CC"; |
A |
56 |
} |
|
57 |
else if (preg_match("/^bcc:.*/i", $str)) |
|
58 |
{ |
|
59 |
list(,$srch) = explode(":", $str); |
|
60 |
$subject['bcc'] = "HEADER BCC"; |
95c2c3
|
61 |
} |
e538b3
|
62 |
else if (preg_match("/^subject:.*/i", $str)) |
04c618
|
63 |
{ |
95c2c3
|
64 |
list(,$srch) = explode(":", $str); |
30b152
|
65 |
$subject['subject'] = "HEADER SUBJECT"; |
95c2c3
|
66 |
} |
e538b3
|
67 |
else if (preg_match("/^body:.*/i", $str)) |
04c618
|
68 |
{ |
95c2c3
|
69 |
list(,$srch) = explode(":", $str); |
30b152
|
70 |
$subject['text'] = "TEXT"; |
95c2c3
|
71 |
} |
e538b3
|
72 |
else if(trim($str)) |
04c618
|
73 |
{ |
30b152
|
74 |
if ($headers) { |
7910c0
|
75 |
foreach(explode(',', $headers) as $header) |
30b152
|
76 |
switch ($header) { |
A |
77 |
case 'text': $subject['text'] = 'TEXT'; break; |
7910c0
|
78 |
default: $subject[$header] = 'HEADER '.strtoupper($header); |
30b152
|
79 |
} |
7910c0
|
80 |
|
T |
81 |
// save search modifiers for the current folder to user prefs |
|
82 |
$search_mods = $RCMAIL->config->get('search_mods', $SEARCH_MODS_DEFAULT); |
|
83 |
$search_mods[$mbox] = array_fill_keys(array_keys($subject), 1); |
|
84 |
$RCMAIL->user->save_prefs(array('search_mods' => $search_mods)); |
30b152
|
85 |
} else { |
ae119b
|
86 |
// search in subject by default |
30b152
|
87 |
$subject['subject'] = 'HEADER SUBJECT'; |
A |
88 |
} |
95c2c3
|
89 |
} |
T |
90 |
|
30b152
|
91 |
$search = $srch ? trim($srch) : trim($str); |
A |
92 |
|
|
93 |
if ($subject) { |
|
94 |
$search_str .= str_repeat(' OR', count($subject)-1); |
|
95 |
foreach ($subject as $sub) |
0cb967
|
96 |
$search_str .= sprintf(" %s {%d}\r\n%s", $sub, strlen($search), $search); |
e538b3
|
97 |
} |
A |
98 |
|
|
99 |
$search_str = trim($search_str); |
|
100 |
|
04c618
|
101 |
// execute IMAP search |
697cc5
|
102 |
if ($search_str) |
A |
103 |
$result = $IMAP->search($mbox, $search_str, $imap_charset, $_SESSION['sort_col']); |
0803fb
|
104 |
|
697cc5
|
105 |
// Get the headers |
A |
106 |
$result_h = $IMAP->list_headers($mbox, 1, $_SESSION['sort_col'], $_SESSION['sort_order']); |
f52c93
|
107 |
$count = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL'); |
697cc5
|
108 |
|
A |
109 |
// save search results in session |
|
110 |
if (!is_array($_SESSION['search'])) |
|
111 |
$_SESSION['search'] = array(); |
|
112 |
|
2a466a
|
113 |
if ($search_str) { |
f6aac3
|
114 |
$_SESSION['search'] = $IMAP->get_search_set(); |
2a466a
|
115 |
$_SESSION['last_text_search'] = $str; |
A |
116 |
} |
f6aac3
|
117 |
$_SESSION['search_request'] = $search_request; |
2a466a
|
118 |
|
697cc5
|
119 |
// Make sure we got the headers |
f6aac3
|
120 |
if (!empty($result_h)) { |
3414c5
|
121 |
rcmail_js_message_list($result_h); |
2a466a
|
122 |
if ($search_str) |
f52c93
|
123 |
$OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $IMAP->messagecount(NULL, 'ALL'))); |
f11541
|
124 |
} |
2d1d68
|
125 |
// handle IMAP errors (e.g. #1486905) |
A |
126 |
else if ($err_code = $IMAP->get_error_code()) { |
db1a87
|
127 |
rcmail_display_server_error(); |
2d1d68
|
128 |
} |
f6aac3
|
129 |
else { |
b76275
|
130 |
$OUTPUT->show_message('searchnomatch', 'notice'); |
f11541
|
131 |
} |
04c618
|
132 |
|
T |
133 |
// update message count display |
bdb13a
|
134 |
$OUTPUT->set_env('search_request', $search_str ? $search_request : ''); |
f11541
|
135 |
$OUTPUT->set_env('messagecount', $count); |
697cc5
|
136 |
$OUTPUT->set_env('pagecount', ceil($count/$IMAP->page_size)); |
f11541
|
137 |
$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count, 1)); |
T |
138 |
$OUTPUT->send(); |
95c2c3
|
139 |
|
b25dfd
|
140 |
|