6e189ce2 |
1 | <?php |
2ba13803 |
2 | |
35586184 |
3 | /** |
15e6162e |
4 | * imap_search.php |
35586184 |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
35586184 |
8 | * |
15e6162e |
9 | * IMAP search routines |
35586184 |
10 | * |
15e6162e |
11 | * $Id$ |
35586184 |
12 | */ |
13 | |
35586184 |
14 | require_once('../functions/imap.php'); |
15 | require_once('../functions/date.php'); |
16 | require_once('../functions/array.php'); |
17 | require_once('../functions/mailbox_display.php'); |
18 | require_once('../functions/mime.php'); |
2ba13803 |
19 | |
29eb5486 |
20 | function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color) { |
2ba13803 |
21 | |
29eb5486 |
22 | global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order; |
2ba13803 |
23 | |
29eb5486 |
24 | $urlMailbox = urlencode($mailbox); |
25 | $isid = sqimap_session_id(); |
2ba13803 |
26 | |
29eb5486 |
27 | /* Construct the Search QuERY */ |
28 | $ss = $isid; |
29 | if (isset($languages[$squirrelmail_language]['CHARSET']) && |
30 | $languages[$squirrelmail_language]['CHARSET']) { |
31 | $ss .= " SEARCH CHARSET ".$languages[$squirrelmail_language]['CHARSET']." ALL $search_where \"$search_what\"\r\n"; |
32 | } else { |
33 | $ss .= " SEARCH ALL $search_where \"$search_what\"\r\n"; |
34 | } |
35 | fputs($imapConnection,$ss); |
36 | |
37 | /* Read Data Back From IMAP */ |
38 | $readin = sqimap_read_data ($imapConnection, $isid, false, $result, $message); |
39 | if (isset($languages[$squirrelmail_language]['CHARSET']) && strtolower($result) == 'no') { |
40 | $ss = $isid . " SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"\r\n"; |
41 | fputs ($imapConnection, $ss); |
42 | $readin = sqimap_read_data ($imapConnection, $isid, true, $result, $message); |
43 | } |
2ba13803 |
44 | |
29eb5486 |
45 | unset($messagelist); $msgs=""; $c = 0; |
2ba13803 |
46 | |
29eb5486 |
47 | /* Keep going till we find the SEARCH responce */ |
48 | while ($c < count( $readin )) { |
2ba13803 |
49 | |
29eb5486 |
50 | /* Check to see if a SEARCH Responce was recived */ |
51 | if (substr($readin[$c],0,9) == "* SEARCH ") |
52 | $messagelist = explode(" ",substr($readin[$c],9)); |
53 | else if (isset($errors)) |
54 | $errors = $errors.$readin[$c]; |
55 | else |
56 | $errors = $readin[$c]; |
57 | $c++; |
58 | } |
2ba13803 |
59 | |
29eb5486 |
60 | /* If nothing is found * SEARCH should be the first error else echo errors */ |
61 | if (isset($errors) && strstr($errors,"* SEARCH")) { |
62 | echo '<br><CENTER>' . _("No Messages Found") . '</CENTER>'; |
63 | return; |
64 | } else if (isset($errors)) { |
65 | echo "<!-- ".$errors." -->"; |
66 | } |
2ba13803 |
67 | |
29eb5486 |
68 | /* |
69 | HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify |
70 | exsitising code with a search true/false varible. |
71 | */ |
2ba13803 |
72 | |
29eb5486 |
73 | global $sent_folder; |
74 | for ($q = 0; $q < count($messagelist); $q++) { |
75 | $id[$q] = trim($messagelist[$q]); |
76 | } |
77 | $issent = ($mailbox == $sent_folder); |
78 | $hdr_list = sqimap_get_small_header_list($imapConnection, $id, $issent); |
79 | $flags = sqimap_get_flags_list($imapConnection, $id, $issent); |
80 | foreach ($hdr_list as $hdr) { |
81 | $from[] = $hdr->from; |
82 | $date[] = $hdr->date; |
83 | $subject[] = $hdr->subject; |
84 | $to[] = $hdr->to; |
85 | $priority[] = $hdr->priority; |
86 | $cc[] = $hdr->cc; |
87 | $size[] = $hdr->size; |
88 | $type[] = $hdr->type0; |
89 | } |
2ba13803 |
90 | |
29eb5486 |
91 | $j = 0; |
92 | while ($j < count($messagelist)) { |
93 | $date[$j] = ereg_replace(' ', ' ', $date[$j]); |
94 | $tmpdate = explode(" ", trim($date[$j])); |
95 | |
96 | $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate); |
97 | $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]); |
98 | $messages[$j]["ID"] = $id[$j]; |
99 | $messages[$j]["FROM"] = decodeHeader($from[$j]); |
100 | $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j]))); |
101 | $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]); |
102 | $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j])); |
103 | $messages[$j]["TO"] = decodeHeader($to[$j]); |
104 | $messages[$j]["PRIORITY"] = $priority[$j]; |
105 | $messages[$j]["CC"] = $cc[$j]; |
106 | $messages[$j]["SIZE"] = $size[$j]; |
107 | $messages[$j]["TYPE0"] = $type[$j]; |
108 | |
109 | $num = 0; |
110 | while ($num < count($flags[$j])) { |
111 | if ($flags[$j][$num] == 'Deleted') { |
112 | $messages[$j]['FLAG_DELETED'] = true; |
113 | } else if ($flags[$j][$num] == 'Answered') { |
114 | $messages[$j]['FLAG_ANSWERED'] = true; |
115 | } else if ($flags[$j][$num] == 'Seen') { |
116 | $messages[$j]['FLAG_SEEN'] = true; |
117 | } else if ($flags[$j][$num] == 'Flagged') { |
118 | $messages[$j]['FLAG_FLAGGED'] = true; |
2ba13803 |
119 | } |
29eb5486 |
120 | $num++; |
fc05541b |
121 | } |
29eb5486 |
122 | $j++; |
123 | } |
2ba13803 |
124 | |
29eb5486 |
125 | /* Find and remove the ones that are deleted */ |
126 | $i = 0; |
127 | $j = 0; |
128 | while ($j < count($messagelist)) { |
129 | if (isset($messages[$j]["FLAG_DELETED"]) && $messages[$j]["FLAG_DELETED"] == true) { |
1809bad8 |
130 | $j++; |
29eb5486 |
131 | continue; |
2ba13803 |
132 | } |
29eb5486 |
133 | $msgs[$i] = $messages[$j]; |
2ba13803 |
134 | |
29eb5486 |
135 | $i++; |
136 | $j++; |
137 | } |
138 | $numMessages = $i; |
2ba13803 |
139 | |
29eb5486 |
140 | /* There's gotta be messages in the array for it to sort them. */ |
2ba13803 |
141 | |
29eb5486 |
142 | if (count($messagelist) > 0) { |
143 | $j=0; |
144 | if (!isset ($msg)) { $msg = ""; } |
145 | |
146 | mail_message_listing_beginning( $imapConnection, |
147 | "move_messages.php?msg=$msg&mailbox=$urlMailbox&where=" . urlencode($search_where) . "&what=".urlencode($search_what), |
148 | $mailbox, |
149 | -1, |
150 | '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>', |
151 | get_selectall_link($start_msg, $sort) ); |
2ba13803 |
152 | |
29eb5486 |
153 | |
154 | while ($j < count($msgs)) { |
155 | printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, '', 0, $search_where, $search_what); |
156 | $j++; |
2ba13803 |
157 | } |
29eb5486 |
158 | echo '</table></tr></td></table>'; |
2ba13803 |
159 | } |
29eb5486 |
160 | } |
fc05541b |
161 | |
15e6162e |
162 | ?> |