imap_search.php 6.4 KB

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