X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsearch.php;h=b99fff9c81635bcd117ece3537cb8922e02c9d75;hb=b7043f905faff3c0e7e6ab8bfe7a658372de3ce2;hp=1c29fe064158efa19bb1960c49c0314f377c9b88;hpb=d7f8e6e69e33b218bf6d7775a53c811d839bce61;p=squirrelmail.git
diff --git a/src/search.php b/src/search.php
index 1c29fe06..b99fff9c 100644
--- a/src/search.php
+++ b/src/search.php
@@ -3,431 +3,1086 @@
/**
* search.php
*
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Copyright (c) 1999-2004 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
+ * IMAP search page
+ *
* $Id$
+ * @package squirrelmail
+ * @link http://www.ietf.org/rfc/rfc3501.txt
+ * @author Alex Lemaresquier - Brainstorm - alex at brainstorm.fr
+ *
+ * Subfolder search idea from Patch #806075 by Thomas Pohl xraven at users.sourceforge.net. Thanks Thomas!
*/
-require_once('../src/validate.php');
-require_once('../functions/imap.php');
-require_once('../functions/imap_search.php');
-require_once('../functions/imap_utf7_decode_local.php');
-require_once('../functions/array.php');
-require_once('../functions/strings.php');
-
-global $allow_thread_sort;
-
-/* here are some functions, could go in imap_search.php
-
- this was here, pretty handy */
-function s_opt( $val, $sel, $tit ) {
- echo " \n";
-}
-
-/* function to get the recent searches and put them in the attributes array */
-function get_recent($username, $data_dir) {
- $attributes = array();
- $types = array('search_what', 'search_where', 'search_folder');
- $recent_count = getPref($data_dir, $username, 'search_memory', 0);
- for ($x=1;$x<=$recent_count;$x++) {
- reset($types);
- foreach ($types as $key) {
- $attributes[$key][$x] = getPref($data_dir, $username, $key.$x, "");
- }
- }
- return $attributes;
-}
-
-/* function to get the saved searches and put them in the saved_attributes array */
-function get_saved($username, $data_dir) {
- $saved_attributes = array();
- $types = array('saved_what', 'saved_where', 'saved_folder');
- foreach ($types as $key) {
- for ($x=1;;$x++) {
- $saved_attributes[$key][$x] = getPref($data_dir, $username, $key."$x", "");
- if ($saved_attributes[$key][$x] == "") {
- array_pop($saved_attributes[$key]);
- break;
- }
- }
- }
- return $saved_attributes;
-}
-
-/* function to update recent pref arrays */
-function update_recent($what, $where, $mailbox, $username, $data_dir) {
- $attributes = array();
- $types = array('search_what', 'search_where', 'search_folder');
- $input = array($what, $where, $mailbox);
- $attributes = get_recent( $username, $data_dir);
- reset($types);
- $dupe = 'no';
- for ($i=1;$i<=count($attributes['search_what']);$i++) {
- if (isset($attributes['search_what'][$i])) {
- if ($what == $attributes['search_what'][$i] &&
- $where == $attributes['search_where'][$i] &&
- $mailbox == $attributes['search_folder'][$i]) {
- $dupe = 'yes';
- }
- }
- }
- if ($dupe == 'no') {
- $i = 0;
- foreach ($types as $key) {
- array_push ($attributes[$key], $input[$i]);
- array_shift ($attributes[$key]);
- $i++;
- }
- $recent_count = getPref($data_dir, $username, 'search_memory', 0);
- $n=0;
- for ($i=1;$i<=$recent_count;$i++) {
- reset($types);
- foreach ($types as $key) {
- setPref($data_dir, $username, $key.$i, $attributes[$key][$n]);
- }
- $n++;
- }
- }
-}
-
-/* function to forget a recent search */
-function forget_recent($forget_index, $username, $data_dir) {
- $attributes = array();
- $types = array('search_what', 'search_where', 'search_folder');
- $attributes = get_recent( $username, $data_dir);
- reset($types);
- foreach ($types as $key) {
- array_splice($attributes[$key], $forget_index, 1);
- array_unshift($attributes[$key], '');
- }
- reset($types);
- $recent_count = getPref($data_dir, $username, 'search_memory', 0);
- $n=0;
- for ($i=1;$i<=$recent_count;$i++) {
- reset($types);
- foreach ($types as $key) {
- setPref($data_dir, $username, $key.$i, $attributes[$key][$n]);
- }
- $n++;
- }
-}
-
-/* function to delete a saved search */
-function delete_saved($delete_index, $username, $data_dir) {
- $types = array('saved_what', 'saved_where', 'saved_folder');
- $attributes = get_saved($username, $data_dir);
- foreach ($types as $key) {
- array_splice($attributes[$key], $delete_index, 1);
- }
- reset($types);
- $n=0;
- $saved_count = count($attributes['saved_what']);
- $last_element = $saved_count + 1;
- for ($i=1;$i<=$saved_count;$i++) {
- reset($types);
- foreach ($types as $key) {
- setPref($data_dir, $username, $key.$i, $attributes[$key][$n]);
- }
- $n++;
- }
- reset($types);
- foreach($types as $key) {
- removePref($data_dir, $username, $key.$last_element);
- }
-}
-
-/* function to save a search from recent to saved */
-function save_recent($save_index, $username, $data_dir) {
- $attributes = array();
- $types = array('search_what', 'search_where', 'search_folder');
- $saved_types = array(0 => 'saved_what', 1 => 'saved_where', 2 => 'saved_folder');
- $saved_array = get_saved($username, $data_dir);
- $save_index = $save_index -1;
- $saved_count = (count($saved_array['saved_what']) + 1);
- $attributes = get_recent ($username, $data_dir);
- $n = 0;
- foreach ($types as $key) {
- $slice = array_slice($attributes[$key], $save_index, 1);
- $name = $saved_types[$n];
- setPref($data_dir, $username, $name.$saved_count, $slice[0]);
- $n++;
- }
+/** Path for SquirrelMail required files. */
+define('SM_PATH','../');
+
+/** SquirrelMail required files. */
+require_once(SM_PATH . 'include/validate.php');
+require_once(SM_PATH . 'functions/strings.php');
+require_once(SM_PATH . 'functions/imap_asearch.php');
+require_once(SM_PATH . 'functions/imap_mailbox.php');
+require_once(SM_PATH . 'functions/imap_messages.php');
+require_once(SM_PATH . 'functions/mime.php');
+require_once(SM_PATH . 'functions/mailbox_display.php'); //getButton()...
+
+/**
+ * @param string $a
+ * @param string $b
+ * @return bool strcoll()-like result
+ */
+function asearch_unhtml_strcoll($a, $b)
+{
+ return strcoll(asearch_unhtmlentities($a), asearch_unhtmlentities($b));
}
-/* ------------------------ main ------------------------ */
+/**
+ * @param string $mailbox mailbox name
+ * @return string mailbox name ready to display
+ */
+function imap_get_mailbox_display($mailbox)
+{
+ if (strtoupper($mailbox) == 'INBOX')
+ return _("INBOX");
+ return imap_utf7_decode_local($mailbox);
+}
-/* reset these arrays on each page load just in case */
-$attributes = array ();
-$saved_attributes = array ();
-$search_all = 'none';
-$perbox_count = array ();
-$recent_count = getPref($data_dir, $username, 'search_memory', 0);
+/**
+ * @param string $mailbox mailbox name
+ * @return string mailbox name ready to display
+ */
+function asearch_get_mailbox_display($mailbox)
+{
+ if ($mailbox == 'All Folders')
+ return _("All Folders");
+ return imap_get_mailbox_display($mailbox);
+}
-/* get mailbox names */
-$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-$boxes = sqimap_mailbox_list($imapConnection);
+/**
+ * @param array $color color array
+ * @param string $txt text to display
+ * @return string title ready to display
+ */
+function asearch_get_title_display($color, $txt)
+{
+ return '' . $txt . '';
+}
-/* set current mailbox to INBOX if none was selected or if page
- was called to search all folders. */
-if ( !isset($mailbox) || $mailbox == 'None' || $mailbox == '' ) {
- $mailbox = $boxes[0]['unformatted'];
+/**
+ * @param array $color color array
+ * @param string $txt text to display
+ * @return string error text ready to display
+ */
+function asearch_get_error_display($color, $txt)
+{
+ return '' . '' . $txt . '';
}
-if ($mailbox == 'All Folders') {
- $search_all = 'all';
+
+/**
+ * @param array $input_array array to serialize
+ * @return string a string containing a byte-stream representation of value that can be stored anywhere
+ */
+function asearch_serialize($input_array)
+{
+ return serialize($input_array);
}
-if (isset($composenew) && $composenew) {
- $comp_uri = "../src/compose.php?mailbox=". urlencode($mailbox).
- "&session=$composesession&attachedmessages=true&";
- displayPageHeader($color, $mailbox, "comp_in_new(false,'$comp_uri');", false);
-} else {
- displayPageHeader($color, $mailbox);
+/**
+ * @param string $input_string string to unserialize
+ * @return array
+ */
+function asearch_unserialize($input_string)
+{
+ return unserialize($input_string);
}
-/* See how the page was called and fire off correct function */
-if ((!isset($submit) || empty($submit)) && !empty($what)) {
- $submit = _("Search");
+
+/**
+ * @param string $data_dir prefs data dir or dsn
+ * @param string $username the username
+ * @param string $key the pref key
+ * @param integer $index the pref key index
+ * @param string $default default value
+ * @return string pref value
+ */
+function asearch_getPref($data_dir, $username, $key, $index, $default = '')
+{
+ return getPref($data_dir, $username, $key . $index, $default);
+}
+
+/**
+ * @param string $data_dir prefs data dir or dsn
+ * @param string $username the username
+ * @param string $key the pref key
+ * @param integer $index the pref key index
+ * @param string $value pref value to set
+ * @return bool status
+ */
+function asearch_setPref($data_dir, $username, $key, $index, $value)
+{
+ return setPref($data_dir, $username, $key . $index, $value);
}
-if ( !isset( $submit ) ) {
- $submit = '';
-} else if ($submit == _("Search") && !empty($what)) {
- if ($recent_count > 0) {
- update_recent($what, $where, $mailbox, $username, $data_dir);
- }
+
+/**
+ * @param string $data_dir prefs data dir or dsn
+ * @param string $username the username
+ * @param string $key the pref key
+ * @param integer $index the pref key index
+ * @return bool status
+ */
+function asearch_removePref($data_dir, $username, $key, $index)
+{
+ return removePref($data_dir, $username, $key . $index);
}
-elseif ($submit == 'forget') {
- forget_recent($count, $username, $data_dir);
+
+/** Sanity checks, done before running the imap command and before push_recent */
+function asearch_check_query($where_array, $what_array, $exclude_array)
+{
+ global $imap_asearch_opcodes;
+
+ if (empty($where_array))
+ return _("Please enter something to search for");
+ if (count($exclude_array) == count($where_array))
+ return _("There must be at least one criteria to search for");
+ for ($crit_num = 0; $crit_num < count($where_array); $crit_num++) {
+ $where = $where_array[$crit_num];
+ $what = $what_array[$crit_num];
+ if (!(($what == '') ^ ($imap_asearch_opcodes[$where] != '')))
+ return _("Error in criteria argument");
+ }
+ return '';
}
-elseif ($submit == 'save') {
- save_recent($count, $username, $data_dir);
+
+/** Read the recent searches */
+function asearch_read_recent($data_dir, $username)
+{
+ global $recent_prefkeys;
+
+ $recent_array = array();
+ $recent_max = getPref($data_dir, $username, 'search_memory', 0);
+ for ($recent_num = 0; $recent_num < $recent_max; $recent_num++) {
+ foreach ($recent_prefkeys as $prefkey) {
+ $pref = asearch_getPref($data_dir, $username, $prefkey, $recent_num);
+/* if (!empty($pref))*/
+ $recent_array[$prefkey][$recent_num] = $pref;
+ }
+ if (empty($recent_array[$recent_prefkeys[0]][$recent_num])) {
+ foreach ($recent_prefkeys as $key) {
+ array_pop($recent_array[$key]);
+ }
+ break;
+ }
+ }
+ return $recent_array;
}
-elseif ($submit == 'delete') {
- delete_saved($count, $username, $data_dir);
+
+/** Get the saved searches */
+function asearch_read_saved($data_dir, $username)
+{
+ global $saved_prefkeys;
+
+ $saved_array = array();
+ $saved_key = $saved_prefkeys[0];
+ for ($saved_count = 0; ; $saved_count++) {
+ $pref = asearch_getPref($data_dir, $username, $saved_key, $saved_count);
+ if (empty($pref))
+ break;
+ }
+ for ($saved_num = 0; $saved_num < $saved_count; $saved_num++) {
+ foreach ($saved_prefkeys as $key) {
+ $saved_array[$key][$saved_num] = asearch_getPref($data_dir, $username, $key, $saved_num);
+ }
+ }
+ return $saved_array;
}
-do_hook('search_before_form');
+/** Save a recent search */
+function asearch_save_recent($data_dir, $username, $recent_index)
+{
+ global $recent_prefkeys, $saved_prefkeys;
-echo "
\n".
- "
\n".
- "\n".
- "" . _("Search") . "\n".
- " |
\n".
- "
\n";
-
-/* update the recent and saved searches from the pref files */
-$attributes = get_recent($username, $data_dir);
-$saved_attributes = get_saved($username, $data_dir);
-$saved_count = count($saved_attributes['saved_what']);
-$count_all = 0;
-
-/* Saved Search Table */
-if ($saved_count > 0) {
- echo "
\n"
- . ""
- . 'Saved Searches |
'
- . '';
- for ($i=0; $i < $saved_count; ++$i) {
- if ($i % 2) {
- echo "";
- } else {
- echo " ";
- }
- echo "".$saved_attributes['saved_folder'][$i]." | "
- . "".$saved_attributes['saved_what'][$i]." | "
- . "".$saved_attributes['saved_where'][$i]." | "
- . ''
- . '' . _("edit") . ''
- . ' | '
- . '' . _("search") . ''
- . ' | '
- . ""
- . _("delete")
- . ''
- . ' | ';
- }
- echo " |
\n";
-}
-
-/* Recent Search Table */
-if ($recent_count > 0) {
- echo "
\n"
- . "\n"
- . '' . _("Recent Searches") . ' |
'
- . '';
- for ($i=1; $i <= $recent_count; ++$i) {
- if (isset($attributes['search_folder'][$i])) {
- if ($attributes['search_folder'][$i] == "") {
- $attributes['search_folder'][$i] = "INBOX";
- }
- }
- if ($i % 2) {
- echo "";
- } else {
- echo " ";
- }
- if (isset($attributes['search_what'][$i]) &&
- !empty($attributes['search_what'][$i])) {
- echo "".$attributes['search_folder'][$i]." | "
- . "".$attributes['search_what'][$i]." | "
- . "".$attributes['search_where'][$i]." | "
- . ''
- . ""
- . _("save")
- . ''
- . ' | '
- . '' . _("search") . ''
- . ' | '
- . ""
- . _("forget")
- . ''
- . ' | ';
- }
- }
- echo ' |
';
-}
-
-/* Search Form */
-echo '' . _("Current Search") . ''
- . '