From 1809bad8f78a708bd2df0c535a29b94ae21a24d1 Mon Sep 17 00:00:00 2001 From: lkehresman Date: Fri, 28 Jul 2000 15:20:50 +0000 Subject: [PATCH] - tweaked search functions - made the rest of SM aware of search so it works well with sessions git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@646 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_search.php | 297 +++++++++++++++++----------------- functions/mailbox_display.php | 12 +- src/delete_message.php | 5 +- src/move_messages.php | 10 +- src/read_body.php | 41 +++-- src/search.php | 110 +++++++------ 6 files changed, 253 insertions(+), 222 deletions(-) diff --git a/functions/imap_search.php b/functions/imap_search.php index 3759a45a..010d2c05 100644 --- a/functions/imap_search.php +++ b/functions/imap_search.php @@ -14,161 +14,164 @@ include("../functions/mime.php"); function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color) { - global $msgs; - $urlMailbox = urlencode($mailbox); -# Construct the Search QuERY - $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n"; - fputs($imapConnection,$ss); - -#Read Data Back From IMAP - $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message); - unset($messagelist); $msgs=""; $c = 0; -#Keep going till we find the SEARCH responce - while ($c < count($readin)) { -#Check to see if a SEARCH Responce was recived - if (substr($readin[$c],0,9) == "* SEARCH ") - $messagelist = explode(" ",substr($readin[$c],9)); - else - $errors = $errors.$readin[$c]; - $c++; - } -#If nothing is found * SEARCH should be the first error else echo errors - if (strstr($errors,"* SEARCH")) { - echo "
No Messages Found
"; - return; - } else { - echo ""; - } -echo "
"; -#HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify exsitising code with a search true/false varible. - - global $sent_folder; - - for ($q = 0; $q < count($messagelist); $q++) { - $messagelist[$q] = trim($messagelist[$q]); - if ($mailbox == $sent_folder) - $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], true); - else - $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false); - $from[$q] = $hdr->from; - $date[$q] = $hdr->date; - $subject[$q] = $hdr->subject; - $id[$q] = $messagelist[$q]; - - $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]); - } + global $msgs; + $urlMailbox = urlencode($mailbox); + + # Construct the Search QuERY + + $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n"; + fputs($imapConnection,$ss); + + # Read Data Back From IMAP + $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message); + unset($messagelist); $msgs=""; $c = 0; + + #Keep going till we find the SEARCH responce + while ($c < count($readin)) { + + #Check to see if a SEARCH Responce was recived + if (substr($readin[$c],0,9) == "* SEARCH ") + $messagelist = explode(" ",substr($readin[$c],9)); + else + $errors = $errors.$readin[$c]; + $c++; + } + + #If nothing is found * SEARCH should be the first error else echo errors + if (strstr($errors,"* SEARCH")) { + echo "
No Messages Found
"; + return; + } else { + echo ""; + } + + # HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify + # exsitising code with a search true/false varible. + + global $sent_folder; + for ($q = 0; $q < count($messagelist); $q++) { + $messagelist[$q] = trim($messagelist[$q]); + if ($mailbox == $sent_folder) + $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], true); + else + $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false); + $from[$q] = $hdr->from; + $date[$q] = $hdr->date; + $subject[$q] = $hdr->subject; + $id[$q] = $messagelist[$q]; - $j = 0; - while ($j < count($messagelist)) { - $date[$j] = ereg_replace(" ", " ", $date[$j]); - $tmpdate = explode(" ", trim($date[$j])); - - $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate); - $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]); - $messages[$j]["ID"] = $id[$j]; - $messages[$j]["FROM"] = decodeHeader($from[$j]); - $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]); - - $num = 0; - while ($num < count($flags[$j])) { - if ($flags[$j][$num] == "Deleted") { - $messages[$j]["FLAG_DELETED"] = true; - } - else if ($flags[$j][$num] == "Answered") { - $messages[$j]["FLAG_ANSWERED"] = true; - } - else if ($flags[$j][$num] == "Seen") { - $messages[$j]["FLAG_SEEN"] = true; - } - else if ($flags[$j][$num] == "Flagged") { - $messages[$j]["FLAG_FLAGGED"] = true; - } - $num++; - } - $j++; - } + $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]); + } - /** Find and remove the ones that are deleted */ - $i = 0; - $j = 0; - while ($j < count($messagelist)) { - if ($messages[$j]["FLAG_DELETED"] == true) { - $j++; - continue; + $j = 0; + while ($j < count($messagelist)) { + $date[$j] = ereg_replace(" ", " ", $date[$j]); + $tmpdate = explode(" ", trim($date[$j])); + + $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate); + $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]); + $messages[$j]["ID"] = $id[$j]; + $messages[$j]["FROM"] = decodeHeader($from[$j]); + $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]); + + $num = 0; + while ($num < count($flags[$j])) { + if ($flags[$j][$num] == "Deleted") { + $messages[$j]["FLAG_DELETED"] = true; + } + else if ($flags[$j][$num] == "Answered") { + $messages[$j]["FLAG_ANSWERED"] = true; + } + else if ($flags[$j][$num] == "Seen") { + $messages[$j]["FLAG_SEEN"] = true; } - $msgs[$i] = $messages[$j]; + else if ($flags[$j][$num] == "Flagged") { + $messages[$j]["FLAG_FLAGGED"] = true; + } + $num++; + } + $j++; + } - $i++; + /** Find and remove the ones that are deleted */ + $i = 0; + $j = 0; + while ($j < count($messagelist)) { + if ($messages[$j]["FLAG_DELETED"] == true) { $j++; + continue; } - $numMessages = $i; + $msgs[$i] = $messages[$j]; - // There's gotta be messages in the array for it to sort them. - -# Carn't Use the Display messages function it assumes messages are in order. -# Again More code Hacked from else where - -# AT THE MOMENT YOU CARN'T SORT SEARCH RESULTS - -# ACTULLY THE CODE IS PROLLY BROKEN ANY HOW! - - if (count($messagelist) > 0) { - $j=0; -echo "
"._("Found")." ".count($messagelist)." "._("Messages")."
\n"; -echo "
\n"; -echo ""; - echo ""; -echo "
"; - - echo "\n\n\n
"; - echo "\n"; - echo " \n"; - echo " \n"; - echo " "; - echo " \n"; - - echo "
\n"; - echo " ". _("Move selected to:") .""; - echo " "; + echo ""; + echo "
"; + + echo "\n\n\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo " "; + echo " \n"; + + echo "
\n"; + echo " ". _("Move selected to:") .""; + echo " "; + echo " \n"; + + echo " \n"; + echo "  ". _("checked messages") ."\n"; + echo "
\n\n\n"; + echo "
"; + echo ""; + echo ""; + echo " "; + /** FROM HEADER **/ + if ($mailbox == $sent_folder) + echo " "; + else + echo " "; + /** DATE HEADER **/ + echo " "; + echo " \n"; + /** SUBJECT HEADER **/ + echo " \n"; + echo ""; + + while ($j < count($msgs)) { + printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what); + //echo $msgs[$j]["SUBJECT"]."
"; + $j++; } + echo "
 ". _("To") ."". _("From") ."". _("Date") ." ". _("Subject") ."
"; + echo "
"; } - echo "
"; - echo "
\n"; - - echo "
\n"; - echo "  ". _("checked messages") ."\n"; - echo "
\n\n\n"; - echo "
"; - echo ""; - echo ""; - echo " "; - /** FROM HEADER **/ - if ($mailbox == $sent_folder) - echo " "; - else - echo " "; - /** DATE HEADER **/ - echo " "; - echo " \n"; - /** SUBJECT HEADER **/ - echo " \n"; - echo ""; - -while ($j < count($msgs)) { - printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0); - //echo $msgs[$j]["SUBJECT"]."
"; - $j++; - } -echo "
 ". _("To") ."". _("From") ."". _("Date") ." ". _("Subject") ."
"; -echo "
"; - } -} + } ?> diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 9b765664..c485afee 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -10,7 +10,7 @@ $mailbox_display_php = true; - function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage) { + function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) { global $color, $msgs, $msort; global $sent_folder; global $message_highlight_list; @@ -40,6 +40,10 @@ if (!$hlt_color) $hlt_color = $color[4]; + + if ($where && $what) { + $search_stuff = "&where=".urlencode($where)."&what=".urlencode($what); + } echo " \n"; echo " $italic$bold$flag$senderName$flag_end$bold_end$italic_end\n"; @@ -47,7 +51,7 @@ if ($msg["FLAG_ANSWERED"] == true) echo " A"; elseif (ereg("(1|2)",substr($msg["PRIORITY"],0,1))) echo " !"; else echo "  "; - echo " $bold$flag$subject$flag_end$bold_end\n"; + echo " $bold$flag$subject$flag_end$bold_end\n"; echo "\n"; } @@ -293,7 +297,7 @@ next($msort); $k++; } while (isset ($key) && ($k < $i)); - printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage); + printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, 0, 0); } else { $i = $startMessage; reset($msort); @@ -304,7 +308,7 @@ } while (isset ($key) && ($k < $i)); do { - printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage); + printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, 0, 0); $key = key($msort); $t++; $i++; diff --git a/src/delete_message.php b/src/delete_message.php index fd274d3e..3f281397 100644 --- a/src/delete_message.php +++ b/src/delete_message.php @@ -32,5 +32,8 @@ sqimap_mailbox_expunge($imapConnection, $mailbox); $location = get_location(); - header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=".urlencode($mailbox)); + if ($where && $what) + header ("Location: $location/search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=".urlencode($mailbox)); + else + header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=".urlencode($mailbox)); ?> diff --git a/src/move_messages.php b/src/move_messages.php index 3281867b..8b7b7cf8 100644 --- a/src/move_messages.php +++ b/src/move_messages.php @@ -69,7 +69,10 @@ sqimap_mailbox_expunge($imapConnection, $mailbox); } $location = get_location(); - header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); + if ($where && $what) + header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)); + else + header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); } else { displayPageHeader($color, $mailbox); error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); @@ -95,7 +98,10 @@ sqimap_mailbox_expunge($imapConnection, $mailbox); $location = get_location(); - header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); + if ($where && $what) + header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)); + else + header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); } else { displayPageHeader($color, $mailbox); error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); diff --git a/src/read_body.php b/src/read_body.php index 1440363b..1a7c4c24 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -185,29 +185,40 @@ echo " "; echo " "; echo " "; - echo " "; + if ($where && $what) { + echo " "; + } else { + echo " "; + } echo _("Message List"); echo " | "; - echo " "; + if ($where && $what) { + echo " "; + } else { + echo " "; + } echo _("Delete"); echo "  "; echo " "; echo " "; echo " \n"; - if ($currentArrayIndex == -1) { - echo "Previous | Next"; + if ($where && $what) { } else { - $prev = findPreviousMessage(); - $next = findNextMessage(); - if ($prev != -1) - echo "" . _("Previous") . " | "; - else - echo _("Previous") . " | "; - if ($next != -1) - echo "" . _("Next") . ""; - else - echo _("Next"); - } + if ($currentArrayIndex == -1) { + echo "Previous | Next"; + } else { + $prev = findPreviousMessage(); + $next = findNextMessage(); + if ($prev != -1) + echo "" . _("Previous") . " | "; + else + echo _("Previous") . " | "; + if ($next != -1) + echo "" . _("Next") . ""; + else + echo _("Next"); + } + } echo " \n"; echo " "; echo " "; diff --git a/src/search.php b/src/search.php index a82dc747..18ba2e51 100644 --- a/src/search.php +++ b/src/search.php @@ -18,7 +18,7 @@ include("../functions/page_header.php"); if (!isset($imap_php)) include("../functions/imap.php"); - if (!isset($imap_search_php)) + if (!isset($imap_search_php)) include("../functions/imap_search.php"); if (!isset($array_php)) include("../functions/array.php"); @@ -26,61 +26,65 @@ include("../src/load_prefs.php"); displayPageHeader($color, $mailbox); - $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); + $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); -if (empty($mailbox) || empty($what) || empty($where)) { + echo "
+ + +
+
"._("Search")."
+
"; -echo "
- -
-
"._("Search")."
-

"; - echo "\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; + echo " "; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; - echo " \n"; + echo " \n"; + echo " \n"; - echo " "; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; + echo " "; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " \n"; - echo "
\n"; - echo " \n"; - echo ""; -} else { - -sqimap_mailbox_select($imapConnection, $mailbox); - sqimap_search($imapConnection, $where, $what, $mailbox, $color); - -} -sqimap_logout ($imapConnection); + } + echo "
"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo ""; + echo "
"; + if ($where && $what) { + sqimap_mailbox_select($imapConnection, $mailbox); + sqimap_search($imapConnection, $where, $what, $mailbox, $color); + } + sqimap_logout ($imapConnection); ?> -- 2.25.1