fc05541b |
1 | <?php |
2 | /****************************************************************** |
3 | ** IMAP SEARCH ROUTIES |
4 | *****************************************************************/ |
5 | if (!isset($imap_php)) |
6 | include("../functions/imap.php"); |
7 | if (!isset($date_php)) |
8 | include("../functions/date.php"); |
9 | if (!isset($array_php)) |
10 | include("../functions/array.php"); |
11 | if (!isset($mailbox_display_php)) |
12 | include("../functions/mailbox_display.php"); |
13 | if (!isset($mime_php)) |
14 | include("../functions/mime.php"); |
15 | |
16 | function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color) { |
17 | global $msgs; |
18 | $urlMailbox = urlencode($mailbox); |
19 | # Construct the Search QuERY |
20 | $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n"; |
21 | fputs($imapConnection,$ss); |
22 | |
23 | #Read Data Back From IMAP |
24 | $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message); |
25 | unset($messagelist); $msgs=""; $c = 0; |
26 | #Keep going till we find the SEARCH responce |
27 | while ($c < count($readin)) { |
28 | #Check to see if a SEARCH Responce was recived |
29 | if (substr($readin[$c],0,9) == "* SEARCH ") |
30 | $messagelist = explode(" ",substr($readin[$c],9)); |
31 | else |
32 | $errors = $errors.$readin[$c]; |
33 | $c++; |
34 | } |
35 | #If nothing is found * SEARCH should be the first error else echo errors |
36 | if (strstr($errors,"* SEARCH")) { |
37 | echo "<br><CENTER>No Messages Found</CENTER>"; |
38 | return; |
39 | } else { |
40 | echo "<!-- ".$errors." -->"; |
41 | } |
42 | echo "<br>"; |
43 | #HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify exsitising code with a search true/false varible. |
44 | |
45 | global $sent_folder; |
46 | |
47 | for ($q = 0; $q < count($messagelist); $q++) { |
48 | $messagelist[$q] = trim($messagelist[$q]); |
49 | if ($mailbox == $sent_folder) |
50 | $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], true); |
51 | else |
52 | $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false); |
53 | $from[$q] = $hdr->from; |
54 | $date[$q] = $hdr->date; |
55 | $subject[$q] = $hdr->subject; |
56 | $id[$q] = $messagelist[$q]; |
57 | |
58 | $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]); |
59 | } |
60 | |
61 | $j = 0; |
62 | while ($j < count($messagelist)) { |
63 | $date[$j] = ereg_replace(" ", " ", $date[$j]); |
64 | $tmpdate = explode(" ", trim($date[$j])); |
65 | |
66 | $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate); |
67 | $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]); |
68 | $messages[$j]["ID"] = $id[$j]; |
69 | $messages[$j]["FROM"] = decodeHeader($from[$j]); |
70 | $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]); |
71 | |
72 | $num = 0; |
73 | while ($num < count($flags[$j])) { |
74 | if ($flags[$j][$num] == "Deleted") { |
75 | $messages[$j]["FLAG_DELETED"] = true; |
76 | } |
77 | else if ($flags[$j][$num] == "Answered") { |
78 | $messages[$j]["FLAG_ANSWERED"] = true; |
79 | } |
80 | else if ($flags[$j][$num] == "Seen") { |
81 | $messages[$j]["FLAG_SEEN"] = true; |
82 | } |
83 | else if ($flags[$j][$num] == "Flagged") { |
84 | $messages[$j]["FLAG_FLAGGED"] = true; |
85 | } |
86 | $num++; |
87 | } |
88 | $j++; |
89 | } |
90 | |
91 | /** Find and remove the ones that are deleted */ |
92 | $i = 0; |
93 | $j = 0; |
94 | while ($j < count($messagelist)) { |
95 | if ($messages[$j]["FLAG_DELETED"] == true) { |
96 | $j++; |
97 | continue; |
98 | } |
99 | $msgs[$i] = $messages[$j]; |
100 | |
101 | $i++; |
102 | $j++; |
103 | } |
104 | $numMessages = $i; |
105 | |
106 | // There's gotta be messages in the array for it to sort them. |
107 | |
108 | # Carn't Use the Display messages function it assumes messages are in order. |
109 | # Again More code Hacked from else where |
110 | |
111 | # AT THE MOMENT YOU CARN'T SORT SEARCH RESULTS |
112 | |
113 | # ACTULLY THE CODE IS PROLLY BROKEN ANY HOW! |
114 | |
115 | if (count($messagelist) > 0) { |
116 | $j=0; |
117 | echo "<CENTER>"._("Found")." ".count($messagelist)." "._("Messages")."</CENTER>\n"; |
118 | echo "<br>\n"; |
119 | echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>"; |
120 | echo "<TR><TD BGCOLOR=\"$color[0]\">"; |
121 | |
122 | echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=0\">"; |
123 | echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0>\n"; |
124 | echo " <TR>\n"; |
125 | echo " <TD WIDTH=60% ALIGN=LEFT>\n"; |
126 | echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>"; |
127 | echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">"; |
128 | |
129 | $boxes = sqimap_mailbox_list($imapConnection); |
130 | for ($i = 0; $i < count($boxes); $i++) { |
131 | if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") { |
132 | $box = $boxes[$i]["unformatted"]; |
133 | $box2 = replace_spaces($boxes[$i]["formatted"]); |
134 | echo " <OPTION VALUE=\"$box\">$box2\n"; |
135 | } |
136 | } |
137 | echo " </SELECT></SMALL></TT>"; |
138 | echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n"; |
139 | |
140 | echo " </TD>\n"; |
141 | echo " <TD WIDTH=40% ALIGN=RIGHT>\n"; |
142 | echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n"; |
143 | echo " </TD>"; |
144 | echo " </TR>\n"; |
145 | |
146 | echo "</TABLE>\n\n\n"; |
147 | echo "</TD></TR>"; |
148 | echo "<TR><TD BGCOLOR=\"$color[0]\">"; |
149 | echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[4]\">"; |
150 | echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">"; |
151 | echo " <TD WIDTH=1%><B> </B></TD>"; |
152 | /** FROM HEADER **/ |
153 | if ($mailbox == $sent_folder) |
e5837601 |
154 | echo " <TD WIDTH=30%><B>". _("To") ."</B></td>"; |
fc05541b |
155 | else |
e5837601 |
156 | echo " <TD WIDTH=30%><B>". _("From") ."</B></td>"; |
fc05541b |
157 | /** DATE HEADER **/ |
e5837601 |
158 | echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B></td>"; |
fc05541b |
159 | echo " <TD WIDTH=1%> </TD>\n"; |
160 | /** SUBJECT HEADER **/ |
e5837601 |
161 | echo " <TD WIDTH=%><B>". _("Subject") ."</B></td>\n"; |
fc05541b |
162 | echo "</TR>"; |
163 | |
164 | while ($j < count($msgs)) { |
165 | printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0); |
166 | //echo $msgs[$j]["SUBJECT"]."<br>"; |
167 | $j++; |
168 | } |
169 | echo "</table>"; |
e5837601 |
170 | echo "</tr></td></table>"; |
fc05541b |
171 | } |
172 | } |
173 | |
174 | ?> |