summaryrefslogtreecommitdiff
path: root/program/steps
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2008-11-13 10:30:06 +0000
committeralecpl <alec@alec.pl>2008-11-13 10:30:06 +0000
commite538b3dc7d740c5a9213ef352437f249be856d3a (patch)
tree5ff0bf1bf9b0a336ad5da3e29d11e4e3305f6558 /program/steps
parent6fa87f3fa5579da0935dc6ee29af77aea19ad872 (diff)
- Added message status filter + fixes for r2046 (searching with SORT)
Diffstat (limited to 'program/steps')
-rw-r--r--program/steps/mail/func.inc31
-rw-r--r--program/steps/mail/list.inc13
-rw-r--r--program/steps/mail/search.inc33
-rw-r--r--program/steps/mail/show.inc17
4 files changed, 75 insertions, 19 deletions
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index ca7c4e727..d2bc6a9be 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -1292,6 +1292,36 @@ function rcmail_send_mdn($uid)
}
+function rcmail_search_filter($attrib)
+{
+ global $OUTPUT;
+
+ if (!strlen($attrib['id']))
+ $attrib['id'] = 'rcmlistfilter';
+
+ $attrib['onchange'] = JS_OBJECT_NAME.'.filter_mailbox(this.value)';
+
+ /*
+ RFC3501 (6.4.4): 'ALL', 'RECENT',
+ 'ANSWERED', 'DELETED', 'FLAGGED', 'SEEN',
+ 'UNANSWERED', 'UNDELETED', 'UNFLAGGED', 'UNSEEN',
+ 'NEW', // = (RECENT UNSEEN)
+ 'OLD' // = NOT RECENT
+ */
+
+ $select_filter = new html_select($attrib);
+ $select_filter->add(rcube_label('all'), 'ALL');
+ $select_filter->add(rcube_label('unread'), 'UNSEEN');
+ $select_filter->add(rcube_label('flagged'), 'FLAGGED');
+ $select_filter->add(rcube_label('unanswered'), 'UNANSWERED');
+
+ $out = $select_filter->show($_SESSION['search_filter']);
+
+ $OUTPUT->add_gui_object('search_filter', $attrib['id']);
+
+ return $out;
+}
+
// register UI objects
$OUTPUT->add_handlers(array(
'mailboxlist' => 'rcmail_mailbox_list',
@@ -1304,6 +1334,7 @@ $OUTPUT->add_handlers(array(
'messagecontentframe' => 'rcmail_messagecontent_frame',
'messagepartframe' => 'rcmail_message_part_frame',
'messagepartcontrols' => 'rcmail_message_part_controls',
+ 'searchfilter' => 'rcmail_search_filter',
'searchform' => array($OUTPUT, 'search_form'),
));
diff --git a/program/steps/mail/list.inc b/program/steps/mail/list.inc
index a868f9cc6..2078262eb 100644
--- a/program/steps/mail/list.inc
+++ b/program/steps/mail/list.inc
@@ -41,6 +41,17 @@ else
$mbox_name = $IMAP->get_mailbox_name();
+// initialize searching result if search_filter is used
+if ($_SESSION['search_filter'] && $_SESSION['search_filter'] != 'ALL')
+{
+ $search_request = md5($mbox_name.$_SESSION['search_filter']);
+
+ $IMAP->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $sort_col);
+ $_SESSION['search'][$search_request] = $IMAP->get_search_set();
+ $OUTPUT->set_env('search_request', $search_request);
+}
+
+
// fetch message headers
if ($IMAP->messagecount($mbox_name, 'ALL', !empty($_REQUEST['_refresh'])))
$a_headers = $IMAP->list_headers($mbox_name, NULL, $sort_col, $sort_order);
@@ -55,8 +66,6 @@ $OUTPUT->set_env('pagecount', $pages);
$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count));
$OUTPUT->command('set_mailboxname', rcmail_get_mailbox_name_text());
-
-
// add message rows
if (isset($a_headers) && count($a_headers))
rcmail_js_message_list($a_headers);
diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc
index 6f3676891..18335ba15 100644
--- a/program/steps/mail/search.inc
+++ b/program/steps/mail/search.inc
@@ -26,51 +26,66 @@ $imap_charset = 'UTF-8';
// get search string
$str = get_input_value('_q', RCUBE_INPUT_GET);
+$filter = get_input_value('_filter', RCUBE_INPUT_GET);
$mbox = get_input_value('_mbox', RCUBE_INPUT_GET);
-$search_request = md5($mbox.$str);
+$search_request = md5($mbox.$filter.$str);
+// add list filter string
+$search_str = $filter && $filter != 'ALL' ? $filter : '';
+
+$_SESSION['search_filter'] = $filter;
// Check the search string for type of search
-if (preg_match("/^from:/i", $str))
+if (preg_match("/^from:.*/i", $str))
{
list(,$srch) = explode(":", $str);
- $subject = "HEADER FROM";
+ $subject = "HEADER FROM";
$search = trim($srch);
}
-else if (preg_match("/^to:/i", $str))
+else if (preg_match("/^to.*:/i", $str))
{
list(,$srch) = explode(":", $str);
$subject = "HEADER TO";
$search = trim($srch);
}
-else if (preg_match("/^cc:/i", $str))
+else if (preg_match("/^cc:.*/i", $str))
{
list(,$srch) = explode(":", $str);
$subject = "HEADER CC";
$search = trim($srch);
}
-else if (preg_match("/^subject:/i", $str))
+else if (preg_match("/^subject:.*/i", $str))
{
list(,$srch) = explode(":", $str);
$subject = "HEADER SUBJECT";
$search = trim($srch);
}
-else if (preg_match("/^body:/i", $str))
+else if (preg_match("/^body:.*/i", $str))
{
list(,$srch) = explode(":", $str);
$subject = "TEXT";
$search = trim($srch);
}
// search in subject and sender by default
-else
+else if(trim($str))
{
$from = ($mbox == $CONFIG['sent_mbox'] || $mbox == $CONFIG['drafts_mbox']) ? "TO" : "FROM";
$subject = array("HEADER SUBJECT", "HEADER $from");
$search = trim($str);
}
+if ($subject && !is_array($subject))
+ $search_str .= sprintf(" %s {%d}\r\n%s", $subject, strlen($search), $search);
+else if ($subject) {
+ $search_str .= ' OR';
+ foreach($subject as $sub)
+ $search_str .= sprintf(" (%s {%d}\r\n%s)", $sub, strlen($search), $search);
+}
+
+$search_str = trim($search_str);
+
// execute IMAP search
-$result = $IMAP->search($mbox, $subject, $search, $imap_charset, $_SESSION['sort_col']);
+$result = $IMAP->search($mbox, $search_str, $imap_charset, $_SESSION['sort_col']);
$count = 0;
// Make sure our $result is legit..
diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc
index 8b36c9acd..15c1c54a6 100644
--- a/program/steps/mail/show.inc
+++ b/program/steps/mail/show.inc
@@ -110,12 +110,13 @@ if ($_GET['_uid']) {
{
// Only if we use custom sorting
$a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
-
- $MESSAGE->index = array_search((string)$MESSAGE->uid, $a_msg_index, TRUE);
- $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $a_msg_index[$MESSAGE->index-1] : -1 ;
- $first = count($a_msg_index)>0 ? $a_msg_index[0] : -1;
- $next = isset($a_msg_index[$MESSAGE->index+1]) ? $a_msg_index[$MESSAGE->index+1] : -1 ;
- $last = count($a_msg_index)>0 ? $a_msg_index[count($a_msg_index)-1] : -1;
+
+ $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index);
+
+ $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ;
+ $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1;
+ $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ;
+ $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1;
}
else
{
@@ -130,11 +131,11 @@ if ($_GET['_uid']) {
if ($prev > 0)
$OUTPUT->set_env('prev_uid', $prev);
- if ($first >0)
+ if ($first > 0)
$OUTPUT->set_env('first_uid', $first);
if ($next > 0)
$OUTPUT->set_env('next_uid', $next);
- if ($last >0)
+ if ($last > 0)
$OUTPUT->set_env('last_uid', $last);
// mark message as read