alecpl
2008-10-03 cf6a833c95a341c1eada992ed09afc650493fdaa
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
14 */
15
16 $REMOTE_REQUEST = TRUE;
17
04c618 18 // reset list_page and old search results
95c2c3 19 $IMAP->set_page(1);
04c618 20 $IMAP->set_search_set(NULL);
95c2c3 21 $_SESSION['page'] = 1;
T 22
4d4264 23 // using encodeURI with javascript "should" give us
T 24 // a correctly UTF-8 encoded query string
25 $imap_charset = 'UTF-8';
42000a 26
95c2c3 27 // get search string
f11541 28 $str = get_input_value('_q', RCUBE_INPUT_GET);
95c2c3 29 $mbox = get_input_value('_mbox', RCUBE_INPUT_GET);
04c618 30 $search_request = md5($mbox.$str);
95c2c3 31
T 32
33 // Check the search string for type of search
04c618 34 if (preg_match("/^from:/i", $str))
T 35 {
95c2c3 36   list(,$srch) = explode(":", $str);
04c618 37   $subject =  "HEADER FROM";
T 38   $search = trim($srch);
95c2c3 39 }
04c618 40 else if (preg_match("/^to:/i", $str))
T 41 {
95c2c3 42   list(,$srch) = explode(":", $str);
04c618 43   $subject = "HEADER TO";
T 44   $search = trim($srch);
95c2c3 45 }
04c618 46 else if (preg_match("/^cc:/i", $str))
T 47 {
95c2c3 48   list(,$srch) = explode(":", $str);
04c618 49   $subject = "HEADER CC";
T 50   $search = trim($srch);
95c2c3 51 }
04c618 52 else if (preg_match("/^subject:/i", $str))
T 53 {
95c2c3 54   list(,$srch) = explode(":", $str);
04c618 55   $subject = "HEADER SUBJECT";
T 56   $search = trim($srch);
95c2c3 57 }
04c618 58 else if (preg_match("/^body:/i", $str))
T 59 {
95c2c3 60   list(,$srch) = explode(":", $str);
04c618 61   $subject = "TEXT";
T 62   $search = trim($srch);
95c2c3 63 }
T 64 // search in subject and sender by default
04c618 65 else
T 66 {
e4867e 67   $from = ($mbox == $CONFIG['sent_mbox'] || $mbox == $CONFIG['drafts_mbox']) ? "TO" : "FROM";
T 68   $subject = array("HEADER SUBJECT", "HEADER $from");
04c618 69   $search = trim($str);
95c2c3 70 }
T 71
72
04c618 73 // execute IMAP search
T 74 $result = $IMAP->search($mbox, $subject, $search, $imap_charset);
75 $count = 0;
95c2c3 76   
04c618 77 // Make sure our $result is legit..
T 78 if (is_array($result) && $result[0] != '')
f11541 79 {
04c618 80   // Get the headers
T 81   $result_h = $IMAP->list_header_set($mbox, $result, 1, $_SESSION['sort_col'], $_SESSION['sort_order']);
4845a1 82   $count = $IMAP->messagecount();
04c618 83
T 84   // save search results in session
85   if (!is_array($_SESSION['search']))
86     $_SESSION['search'] = array();
87
88   // Make sure we got the headers
89   if ($result_h != NULL)
90   {
f11541 91     $_SESSION['search'][$search_request] = $IMAP->get_search_set();
1f020b 92     $_SESSION['last_text_search'] = $str;
f11541 93     rcmail_js_message_list($result_h);
T 94     $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $count));
04c618 95   }
f11541 96 }
T 97 else
98 {
b76275 99   $OUTPUT->show_message('searchnomatch', 'notice');
f11541 100   $search_request = -1;
T 101 }
04c618 102
T 103 // update message count display
104 $pages = ceil($count/$IMAP->page_size);
f11541 105 $OUTPUT->set_env('search_request', $search_request);
T 106 $OUTPUT->set_env('messagecount', $count);
107 $OUTPUT->set_env('pagecount', $pages);
108 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count, 1));
109 $OUTPUT->send();
95c2c3 110
1f020b 111 ?>