imap_search.php 7.0 KB

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