Source for file search.php
Documentation is available at search.php
* Subfolder search idea from Patch #806075 by Thomas Pohl xraven at users.sourceforge.net. Thanks Thomas!
* @author Alex Lemaresquier - Brainstorm <alex at brainstorm.fr>
* @copyright © 1999-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: search.php,v 1.167 2006/08/31 18:12:27 stevetruckstuff Exp $
* @link http://www.ietf.org/rfc/rfc3501.txt
* @todo explain why references are used in function calls
* Include the SquirrelMail initialization file.
require
('../include/init.php');
/** SquirrelMail required files.
require_once(SM_PATH .
'functions/imap_asearch.php');
require_once(SM_PATH .
'functions/imap_messages.php');
require_once(SM_PATH .
'functions/imap_general.php');
require_once(SM_PATH .
'functions/mime.php');
require_once(SM_PATH .
'functions/mailbox_display.php'); //getButton()
require_once(SM_PATH .
'functions/forms.php');
require_once(SM_PATH .
'functions/date.php');
/** Prefs array ordinals. Must match $recent_prefkeys and $saved_prefkeys
define('ASEARCH_CRITERIA', 'criteria');
* Array sort callback used to sort $imap_asearch_options
* @return bool strcoll()-like result
// FIXME: Translation policy says "no html entities in translations"
* @param string $mailbox mailbox name or special case 'All Folders'
* @return string mailbox name ready to display (utf7 decoded or localized 'All Folders')
if ($mailbox ==
'All Folders') {
* @param array $input_array array to serialize
* @return string a string containing a byte-stream representation of value that can be stored anywhere
* @param string $input_string string to unserialize
return array($input_string);
* Gets user's advanced search preferences
* Arguments are different in 1.5.0.
* @param string $key the pref key
* @param integer $index the pref key index
* @param string $default default value
* @return string pref value
return getPref($data_dir, $username, $key .
($index +
!$search_advanced), $default);
* Sets user's advanced search preferences
* Arguments are different in 1.5.0.
* @param string $key the pref key
* @param integer $index the pref key index
* @param string $value pref value to set
return setPref($data_dir, $username, $key .
($index +
!$search_advanced), $value);
* Deletes user's advanced search preferences
* Arguments are different in 1.5.0.
* @param string $key the pref key
* @param integer $index the pref key index
return removePref($data_dir, $username, $key .
($index +
!$search_advanced));
* Sanity checks, done before running the imap command and before calling push_recent
* @param array $where_array search location data
* @param array $what_array search criteria data
* @param array $exclude_array excluded criteria data
* @return string error message or empty string
return _("Please enter something to search for");
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");
* Read the recent searches from the prefs
* Function arguments are different in 1.5.0
* @return array recent searches
for ($pref_num =
0; $pref_num <
$search_memory; $pref_num++
) {
foreach ($recent_prefkeys as $prefkey) {
$recent_array[$prefkey][$recent_num] =
$pref;
if (empty($recent_array[$recent_prefkeys[0]][$recent_num])) {
foreach ($recent_prefkeys as $key) {
// break; //Disabled to support old search code broken prefs
* Read the saved searches from the prefs
* Function arguments are different in 1.5.0
* @return array saved searches
$saved_key =
$saved_prefkeys[0];
for ($saved_count =
0; ; $saved_count++
) {
for ($saved_num =
0; $saved_num <
$saved_count; $saved_num++
) {
foreach ($saved_prefkeys as $key) {
* Save a recent search to the prefs
* Function arguments are different in 1.5.0
* @param integer $recent_index
if (isset
($saved_array[$saved_prefkeys[0]])) {
$saved_index =
count($saved_array[$saved_prefkeys[0]]);
foreach ($recent_prefkeys as $key) {
$recent_slice =
array_slice($recent_array[$key], $recent_index, 1);
if (!empty($recent_slice[0]))
* Write a recent search to prefs
* Function arguments are different in 1.5.0
* @param array $recent_array
$recent_count =
min($search_memory, count($recent_array[$recent_prefkeys[0]]));
for ($recent_num =
0; $recent_num <
$recent_count; $recent_num++
) {
foreach ($recent_prefkeys as $key) {
for (; $recent_num <
$search_memory; $recent_num++
) {
foreach ($recent_prefkeys as $key) {
* Remove a recent search from prefs
* Function arguments are different in 1.5.0
* @param integer $forget_index removed search number
foreach ($recent_prefkeys as $key) {
* Find a recent search in the prefs (used to avoid saving duplicates)
* @param array $recent_array
* @param array $mailbox_array
* @param array $biop_array
* @param array $unop_array
* @param array $where_array
* @param array $what_array
* @param array $exclude_array
* @param array $sub_array
function asearch_find_recent(&$recent_array, &$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array)
for ($recent_num =
0; $recent_num <
$recent_count; $recent_num++
) {
if (isset
($recent_array[$recent_prefkeys[ASEARCH_WHERE]][$recent_num])) {
$where_string ==
$recent_array[$recent_prefkeys[ASEARCH_WHERE]][$recent_num] &&
$mailbox_string ==
$recent_array[$recent_prefkeys[ASEARCH_MAILBOX]][$recent_num] &&
$what_string ==
$recent_array[$recent_prefkeys[ASEARCH_WHAT]][$recent_num] &&
$unop_string ==
$recent_array[$recent_prefkeys[ASEARCH_UNOP]][$recent_num] &&
($biop_string ==
$recent_array[$recent_prefkeys[ASEARCH_BIOP]][$recent_num] &&
$exclude_string ==
$recent_array[$recent_prefkeys[ASEARCH_EXCLUDE]][$recent_num] &&
$sub_string ==
$recent_array[$recent_prefkeys[ASEARCH_SUB]][$recent_num]))
* Push a recent search into the prefs
* @param array $recent_array
* @param array $mailbox_array
* @param array $biop_array
* @param array $unop_array
* @param array $where_array
* @param array $what_array
* @param array $exclude_array
* @param array $sub_array
function asearch_push_recent(&$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array)
//global $what; // Hack to access issued search from read_body.php
* Update search history and store it in the session so we can retrieve the
* issued search when returning from an external page like read_body.php
$criteria[$what] =
array($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
if ($search_memory >
0) {
$recent_found =
asearch_find_recent($recent_array, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
if ($recent_found >=
0) { // Remove identical recent
foreach ($recent_prefkeys as $key) {
$input =
array($where_array, $mailbox_array, $what_array, $unop_array, $biop_array, $exclude_array, $sub_array);
foreach ($recent_prefkeys as $key) {
* Function arguments are different in 1.5.0
* @global array mailbox_array searched mailboxes
* Get last search criteria from session or prefs
* Function arguments are different in 1.5.0
* FIXME, try to avoid globals
$mailbox_array =
$criteria[$index][0];
$biop_array =
$criteria[$index][1];
$unop_array =
$criteria[$index][2];
$where_array =
$criteria[$index][3];
$what_array =
$criteria[$index][4];
$exclude_array =
$criteria[$index][5];
$sub_array =
$criteria[$index][6];
unset
($criteria[$index]);
//sqsession_unregister(ASEARCH_CRITERIA);
if ($search_memory >
0) {
* Function arguments are different in 1.5.0
* Write a saved search to the prefs
* Function arguments are different in 1.5.0
* @param array $saved_array
$saved_count =
count($saved_array[$saved_prefkeys[0]]);
for ($saved_num=
0; $saved_num <
$saved_count; $saved_num++
) {
foreach ($saved_prefkeys as $key) {
foreach ($saved_prefkeys as $key) {
* Delete a saved search from the prefs
* Function arguments are different in 1.5.0
* @param integer $saved_index
$asearch_keys =
$saved_prefkeys;
foreach ($asearch_keys as $key) {
/** Translate the input date to imap date to local date display,
* so the user can know if the date is wrong or illegal
* @param string $what date string
* @return string locally formatted date or error text
if (count($what_parts) ==
4) {
if (checkdate($what_parts[2], $what_parts[1], $what_parts[3]))
return date_intl(_("M j, Y"), mktime(0,0,0,$what_parts[2],$what_parts[1],$what_parts[3]));
//return $what_parts[1] . ' ' . getMonthName($what_parts[2]) . ' ' . $what_parts[3];
return _("(Illegal date)");
return _("(Wrong date)");
* Translate the query to rough natural display
* @param array $mailbox_array
* @param array $biop_array
* @param array $unop_array
* @param array $where_array
* @param array $what_array
* @param array $exclude_array
* @param array $sub_array
* @return string rough natural query ready to display
function asearch_get_query_display(&$color, &$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array)
global $imap_asearch_biops_in, $imap_asearch_biops, $imap_asearch_unops, $imap_asearch_options;
$last_mailbox =
$mailbox_array[0];
if (empty($last_mailbox))
for ($crit_num=
0; $crit_num <
count($where_array); $crit_num++
) {
if ((!isset
($exclude_array[$crit_num])) ||
(!$exclude_array[$crit_num])) {
$cur_mailbox =
$mailbox_array[$crit_num];
if (($query_display ==
'') ||
($cur_mailbox !=
$last_mailbox)) {
if ($query_display ==
'')
$biop_display =
$imap_asearch_biops_in[$biop];
$last_mailbox =
$cur_mailbox;
$biop_display =
$imap_asearch_biops[$biop];
$unop =
$unop_array[$crit_num];
$unop_display =
$imap_asearch_unops[$unop];
$where =
$where_array[$crit_num];
$where_display =
$unop_display .
asearch_nz($imap_asearch_options[$where], $where);
$what_type =
$imap_asearch_opcodes[$where];
$what =
$what_array[$crit_num];
if ($what_type) { /* Check opcode parameter */
$what_display =
' <span class="error">' .
_("(Missing argument)") .
'</span>';
if ($what_type ==
'adate')
$what_display =
' <span class="value">' .
$what_display .
'</span>';
$what_display =
' <span class="error">' .
_("(Spurious argument)") .
'</span>';
if ($mailbox_display !=
'')
$query_display .=
' <span class="operator">' .
$biop_display .
'</span>' .
$mailbox_display .
' <span class="conditions">' .
$where_display .
'</span>' .
$what_display;
$query_display .=
' <span class="operator">' .
$biop_display .
'</span> <span class="conditions">' .
$where_display .
'</span>' .
$what_display;
* @deprecated see form functions available in 1.5.1 and 1.4.3.
function getButton($type, $name, $value, $js =
'', $enabled =
TRUE) {
$disabled =
( $enabled ?
'' :
'disabled ' );
$js =
( $js ?
$js.
' ' :
'' );
return '<input '.
$disabled.
$js.
'" style="padding: 0px; margin: 0px" />';
* Print a whole query array, recent or saved
* Function arguments are different in 1.5.0
* @param array $boxes (unused)
* @param array $query_array
* @param mixed $query_keys
* @param array $action_array
* @param string $show_pref
$show_flag =
getPref($data_dir, $username, $show_pref, 0) & 1;
$query_count =
count($query_array[$main_key]);
for ($query_num =
0, $row_num =
0; $query_num <
$query_count; $query_num++
) {
if (!empty($query_array[$main_key][$query_num])) {
foreach ($query_keys as $query_key) {
$query_display =
asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
$a[$query_num] =
$query_display;
$oTemplate->assign('list_title', $title);
$oTemplate->assign('show_list', $show_flag==
1);
$oTemplate->assign('is_recent_list', $title==
_("Recent Searches"));
$oTemplate->assign('expand_collapse_toggle', '../src/search.php?'.
$show_pref.
'='.
($show_flag==
1 ?
0 :
1));
$oTemplate->assign('query_list', $a);
$oTemplate->assign('save_recent', '../src/search.php?submit=save_recent&rownum=');
$oTemplate->assign('do_recent', '../src/search.php?submit=search_recent&rownum=');
$oTemplate->assign('forget_recent', '../src/search.php?submit=forget_recent&rownum=');
$oTemplate->assign('edit_saved', '../src/search.php?submit=edit_saved&rownum=');
$oTemplate->assign('do_saved', '../src/search.php?submit=search_saved&rownum=');
$oTemplate->assign('delete_saved', '../src/search.php?submit=delete_saved&rownum=');
$oTemplate->display('search_list.tpl');
/** Print the saved array
* Function arguments are different in 1.5.0
* @param array $boxes (unused, see asearch_print_query_array())
if (isset
($saved_array[$saved_prefkeys[0]])) {
$saved_count =
count($saved_array[$saved_prefkeys[0]]);
$saved_actions =
array('edit_saved' =>
_("Edit"), 'search_saved' =>
_("Search"), 'delete_saved' =>
_("Delete"));
* Function arguments are different in 1.5.0
* @param array $boxes (unused, see asearch_print_query_array())
if (isset
($recent_array[$recent_prefkeys[0]])) {
$recent_count =
count($recent_array[$recent_prefkeys[0]]);
if (min($recent_count, $search_memory) >
0) {
$recent_actions =
array('save_recent' =>
_("save"), 'search_recent' =>
_("search"), 'forget_recent' =>
_("forget"));
/** Verify that a mailbox exists
* @return bool mailbox exists
* @deprecated FIXME use standard functions
foreach ($boxes as $box) {
if ($box['unformatted'] ==
$mailbox)
/** Print the advanced search form
* @param stream $imapConnection
* @param array $mailbox_array
* @param array $biop_array
* @param array $unop_array
* @param array $where_array
* @param array $what_array
* @param array $exclude_array
* @param array $sub_array
function asearch_print_form($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
$imap_asearch_unops, $imap_asearch_biops_in, $imap_asearch_options;
# Build the criteria array
for ($row_num =
0; $row_num <
count($where_array); $row_num++
) {
$a['MailboxSel'] =
asearch_nz($mailbox_array[$row_num]);
# Build the mailbox array
if ($allow_advanced_search >
1) {
$link =
'../src/search.php?advanced='.
($search_advanced ?
0 :
1);
$txt =
$search_advanced ?
_("Standard Search") :
_("Advanced search");
$oTemplate->assign('allow_advanced_search', $allow_advanced_search >
1);
$oTemplate->assign('adv_toggle_text', $txt);
$oTemplate->assign('adv_toggle_link', $link);
$oTemplate->assign('mailbox_options', $a);
$oTemplate->assign('logical_options', $imap_asearch_biops_in);
$oTemplate->assign('unary_options', $imap_asearch_unops);
$oTemplate->assign('where_options', $imap_asearch_options);
$oTemplate->assign('criteria', $c);
echo
'<form action="../src/search.php" name="form_asearch">' .
"\n";
$oTemplate->display('search_advanced.tpl');
/** Print the basic search form
* @param stream $imapConnection
* @param array $mailbox_array
* @param array $biop_array
* @param array $unop_array
* @param array $where_array
* @param array $what_array
* @param array $exclude_array
* @param array $sub_array
function asearch_print_form_basic($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
# Build the mailbox array
if ($allow_advanced_search >
1) {
$link =
'../src/search.php?advanced='.
($search_advanced ?
0 :
1);
$txt =
$search_advanced ?
_("Standard Search") :
_("Advanced search");
$oTemplate->assign('allow_advanced_search', $allow_advanced_search >
1);
$oTemplate->assign('adv_toggle_text', $txt);
$oTemplate->assign('adv_toggle_link', $link);
$oTemplate->assign('mailbox_options', $a);
$oTemplate->assign('unary_options', $imap_asearch_unops);
$oTemplate->assign('where_options', $imap_asearch_options);
$oTemplate->assign('unary_sel', $unop);
$oTemplate->assign('where_sel', $where);
$oTemplate->assign('what_val', $what);
echo
'<form action="../src/search.php" name="form_asearch">' .
"\n";
$oTemplate->display('search.tpl');
* @param array $boxes mailboxes array (reference)
* @return array selectable unformatted mailboxes names
$boxcount =
count($boxes);
for ($boxnum =
0; $boxnum <
$boxcount; $boxnum++
) {
if (!in_array('noselect', $boxes[$boxnum]['flags']))
$mboxes_array[] =
$boxes[$boxnum]['unformatted'];
/* ------------------------ main ------------------------ */
/* get globals we will need */
* Retrieve the mailbox cache from the session.
$search_button_html =
_("Search");
$add_criteria_button_html =
_("Add New Criteria");
$del_excluded_button_html =
_("Remove Excluded Criteria");
$del_all_button_html =
_("Remove All Criteria");
/** Maximum number of recent searches to handle
* @global integer $search_memory
$search_memory =
getPref($data_dir, $username, 'search_memory', 0);
/** Advanced search control
* - 0 => allow basic interface only
* - 1 => allow advanced interface only
$allow_advanced_search =
asearch_nz($allow_advanced_search, 2);
* Toggle advanced/basic search
setPref($data_dir, $username, 'search_advanced', $search_advanced & 1);
/** If 1, show advanced search interface
* Default from allow_advanced_search pref
* @global integer $search_advanced
if ($allow_advanced_search >
1) {
$search_advanced =
getPref($data_dir, $username, 'search_advanced', 0);
$search_advanced =
$allow_advanced_search;
/** Set recent prefkeys according to $search_advanced
* @global array $recent_prefkeys
$recent_prefkeys =
array('asearch_recent_where', 'asearch_recent_mailbox', 'asearch_recent_what', 'asearch_recent_unop', 'asearch_recent_biop', 'asearch_recent_exclude', 'asearch_recent_sub');
/** Set saved prefkeys according to $search_advanced
* @global array $saved_prefkeys
$saved_prefkeys =
array('asearch_saved_where', 'asearch_saved_mailbox', 'asearch_saved_what', 'asearch_saved_unop', 'asearch_saved_biop', 'asearch_saved_exclude', 'asearch_saved_sub');
/*$asearch_prefkeys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude', 'sub');*/
$recent_prefkeys =
array('search_where', 'search_folder', 'search_what', 'search_unop');
$saved_prefkeys =
array('saved_where', 'saved_folder', 'saved_what', 'saved_unop');
/** How we did enter the form
* - unset : Enter key, or called from outside (eg read_body)
* - $search_button_text : Search button
* - 'Search_no_update' : Search but don't update recent
* - 'Search_last' : Same as no_update but reload and search last
* - 'Search_silent' : Same as no_update but only display results
* - $add_criteria_button_text : Add New Criteria button
* - $del_excluded_button_text : Remove Excluded Criteria button
* - $del_all_button_text : Remove All Criteria button
if (isset
($_GET['submit'])) {
* @global array $mailbox_array
if (isset
($_GET['mailbox'])) {
$mailbox_array =
$_GET['mailbox'];
$targetmailbox =
$_GET['mailbox'];
$mailbox_array =
array($mailbox_array);
$mailbox_array =
array();
$targetmailbox =
array();
$aMailboxGlobalPref =
array(
// MBX_PREF_FUTURE => (var) $future
* system wide admin settings and incoming vars.
// 'allow_thread_sort' => $allow_thread_sort,
// 'allow_server_sort' => $allow_server_sort,
* @global array $biop_array
if (isset
($_GET['biop'])) {
$biop_array =
$_GET['biop'];
$biop_array =
array($biop_array);
* @global array $unop_array
if (isset
($_GET['unop'])) {
$unop_array =
$_GET['unop'];
$unop_array =
array($unop_array);
* @global array $where_array
if (isset
($_GET['where'])) {
$where_array =
$_GET['where'];
$where_array =
array($where_array);
* @global array $what_array
if (isset
($_GET['what'])) {
$what_array =
$_GET['what'];
$what_array =
array($what_array);
/** Whether to exclude this criteria from search
* @global array $exclude_array
if (isset
($_GET['exclude'])) {
$exclude_array =
$_GET['exclude'];
$exclude_array =
array();
/** Search within subfolders
* @global array $sub_array
if (isset
($_GET['sub'])) {
$sub_array =
$_GET['sub'];
/** Row number used by recent and saved stuff
if (isset
($_GET['rownum'])) {
// asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
$startMessage = (int)
$temp;
// asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
// asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
* Incoming submit buttons from the message list with search results
asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
/** Toggle show/hide saved searches
setPref($data_dir, $username, 'search_show_saved', $search_show_saved & 1);
/** Toggle show/hide recent searches
setPref($data_dir, $username, 'search_show_recent', $search_show_recent & 1);
/** If TRUE, do not show search interface
* @global bool $search_silent
/* See how the page was called and fire off correct function */
if ((empty($submit)) &&
(!empty($where_array))) {
/* This happens when the Enter key is used or called from outside */
$submit =
$search_button_text;
/* Hack needed to handle coming back from read_body et als */
* Hack to use already existen where and what vars.
* where now contains the initiator page of the messagelist
* and in this case 'search'. what contains an index to access
case $search_button_text:
asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
$submit =
$search_button_text;
case $del_excluded_button_text:
while (!empty($delarray)) {
/* array_splice($exclude_array, $delrow, 1);*/ /* There is still some php magic that eludes me */
$exclude_array =
array();
case $del_all_button_text:
$mailbox_array =
array();
$exclude_array =
array();
$submit =
$search_button_text;
asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
case 'edit_recent':
/* no link to do this, yet */
$submit =
$search_button_text;
asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
//Texts in both basic and advanced form
$imap_asearch_unops =
array(
//Texts in advanced form only
$imap_asearch_options =
array(
//'ALL' is binary operator
'ANSWERED' =>
_("Answered"),
'BODY' =>
_("Message Body"),
'DELETED' =>
_("Deleted"),
'FLAGGED' =>
_("Flagged"),
'HEADER' =>
_("Header Field"),
'KEYWORD' =>
_("Keyword"),
'LARGER' =>
_("Larger Than"),
//'NOT' is unary operator
//'OR' is binary operator
'SENTBEFORE' =>
_("Sent Before"),
'SENTON' =>
_("Sent On"),
'SENTSINCE' =>
_("Sent Since"),
'SMALLER' =>
_("Smaller Than"),
'SUBJECT' =>
_("Subject Contains"),
'TEXT' =>
_("Header and Body"),
'UNKEYWORD' => _("Unkeyword"),
'UNSEEN' => _("Unseen"),*/
$imap_asearch_biops_in =
array(
$imap_asearch_biops =
array(
//Texts in basic form only
$imap_asearch_options =
array(
'SUBJECT' =>
_("Subject"),
'TEXT' =>
_("Everywhere"),
uasort($imap_asearch_options, 'asearch_unhtml_strcoll');
/* open IMAP connection */
$imapConnection =
sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
/* get mailboxes once here */
/* ensure we have a valid default mailbox name */
if (($mailbox ==
'') ||
($mailbox ==
'None')) //Workaround for sm quirk IMHO (what if I really have a mailbox called None?)
$mailbox =
$boxes[0]['unformatted']; //Usually INBOX ;)
* Handle form actions like flag / unflag, seen / unseen, delete
* system wide admin settings and incoming vars.
$aConfig['setindex'] =
1; // $what $where = 'search'
* Set the max cache size to the number of mailboxes to avoid cache cleanups
* when searching all mailboxes
$aConfig['max_cache_size'] =
count($boxes) +
1;
/* add the mailbox to the cache */
$mailbox_cache[$iAccount.
'_'.
$aMailbox['NAME']] =
$aMailbox;
if (isset
($aMailbox['FORWARD_SESSION'])) {
/* add the mailbox to the cache */
$mailbox_cache[$iAccount.
'_'.
$aMailbox['NAME']] =
$aMailbox;
// write the session in order to make sure that the compose window has
// access to the composemessages array which is stored in the session
// restart the session. Do not use sqsession_is_active because the session_id
// isn't empty after a session_write_close
if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
// do not use &, it will break the query string and $session will not be detected!!!
'&session='.
$aMailbox['FORWARD_SESSION'];
displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", false);
// we have to redirect to the compose page
'&session='.
$aMailbox['FORWARD_SESSION'];
header("Location: $location");
// $compose_uri = $base_uri.'src/compose.php?newmessage=1';
$oTemplate->assign('note', $note);
$oTemplate->display('note.tpl');
if (empty($where_array)) {
$mailbox_array[0] =
$mailbox;
if ($mailbox ==
$sent_folder) {
$where_array[0] =
'FROM';
//Display advanced or basic form
if ($submit ==
$add_criteria_button_text) {
$last_index =
max(count($where_array) -
1, 0);
$mailbox_array[] =
asearch_nz($mailbox_array[$last_index]);
$biop_array[] =
asearch_nz($biop_array[$last_index]);
$unop_array[] =
asearch_nz($unop_array[$last_index]);
$where_array[] =
asearch_nz($where_array[$last_index]);
$what_array[] =
asearch_nz($what_array[$last_index]);
$exclude_array[] =
asearch_nz($exclude_array[$last_index]);
$sub_array[] =
asearch_nz($sub_array[$last_index]);
asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
asearch_print_form_basic($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
if ($submit ==
$search_button_text) {
$oTemplate->assign('query_has_error', $err!=
'');
$oTemplate->assign('query_error', $err==
'' ?
NULL :
$err);
$oTemplate->assign('query', asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array));
$oTemplate->display('search_result_top.tpl');
* Retrieve the search queries
$mboxes_mailbox =
sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array);
foreach($mboxes_mailbox as $mbx =>
$search) {
* until there is no per mailbox option screen to set prefs we override
* the mailboxprefs by the default ones
$aMailboxPrefSer=
getPref($data_dir, $username,'pref_'.
$iAccount.
'_'.
$mbx);
$aMailboxPref =
$default_mailbox_pref;
if (isset
($srt) &&
$targetmailbox ==
$mbx) {
$trash_folder =
(isset
($trash_folder)) ?
$trash_folder :
false;
$sent_folder =
(isset
($sent_folder)) ?
$sent_folder :
false;
$draft_folder =
(isset
($draft_folder)) ?
$draft_folder :
false;
* until there is no per mailbox option screen to set prefs we override
* the mailboxprefs by the default ones
* Replace From => To in case it concerns a draft or sent folder
if (($mbx ==
$sent_folder ||
$mbx ==
$draft_folder) &&
$aNewOrder =
array(); // nice var name ;)
$aConfig['search'] =
$search['search'];
$aConfig['charset'] =
$search['charset'];
* Set the max cache size to the number of mailboxes to avoid cache cleanups
* when searching all mailboxes
$aConfig['max_cache_size'] =
count($mboxes_mailbox) +
1;
if (isset
($startMessage) &&
$targetmailbox ==
$mbx) {
$aConfig['offset'] =
$startMessage;
if (isset
($showall) &&
$targetmailbox ==
$mbx) {
$aConfig['showall'] =
$showall;
if (isset
($aConfig['showall'])) {
unset
($aConfig['showall']);
* Set the config options for the messages list
$aColumns[$iCol] =
array();
$aColumns[$iCol]['truncate'] =
$truncate_subject;
$aColumns[$iCol]['truncate'] =
$truncate_sender;
'config' =>
array('alt_index_colors' =>
$alt_index_colors,
'highlight_list' =>
$message_highlight_list,
'fancy_index_highlite' =>
$fancy_index_highlite,
'show_flag_buttons' =>
(isset
($show_flag_buttons)) ?
$show_flag_buttons :
true,
'lastTargetMailbox' =>
(isset
($lastTargetMailbox)) ?
$lastTargetMailbox :
'',
'trash_folder' =>
$trash_folder,
'sent_folder' =>
$sent_folder,
'draft_folder' =>
$draft_folder,
'account' =>
(isset
($iAccount)) ?
$iAccount :
0,
// in th future we can make use of multiple message sets, now set it to 1 for search.
if (isset
($aMailbox['UIDSET'][$iSetIndex])) {
$iMsgCnt +=
count($aMailbox['UIDSET'][$iSetIndex]);
* In the future, move this the the initialisation area
* TODO: Clean up handling of message list once the template is cleaned up.
if ($aMailbox['EXISTS'] >
0) {
echo
"ERROR occured, errorhandler will be implemented very soon";
foreach ($aTemplate as $k =>
$v) {
$oTemplate->assign($k, $v);
$mailbox_display =
_("INBOX");
$oTemplate->display('search_result_mailbox.tpl');
$oTemplate->assign('page_selector', $page_selector);
$oTemplate->assign('page_selector_max', $page_selector_max);
$oTemplate->assign('compact_paginator', $compact_paginator);
$oTemplate->assign('javascript_on', $javascript_on);
$oTemplate->assign('enablesort', (isset
($aProps['config']['enablesort'])) ?
$aProps['config']['enablesort'] :
false);
$oTemplate->assign('icon_theme_path', $icon_theme_path);
$oTemplate->assign('use_icons', (isset
($use_icons)) ?
$use_icons :
false);
$oTemplate->assign('aOrder', array_keys($aColumns));
$oTemplate->assign('alt_index_colors', isset
($alt_index_colors) ?
$alt_index_colors:
false);
$oTemplate->assign('color', $color);
$oTemplate->assign('align', $align);
$oTemplate->display('message_list.tpl');
/* add the mailbox to the cache */
$mailbox_cache[$iAccount.
'_'.
$aMailbox['NAME']] =
$aMailbox;
$oTemplate->display('search_result_empty.tpl');
$oTemplate->display('footer.tpl');
Documentation generated on Sat, 07 Oct 2006 16:13:28 +0300 by phpDocumentor 1.3.0RC6