imap_search.php 6.8 KB

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