Request #8659: Add personal recipient message filter
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 22 Sep 2010 06:08:00 +0000 (00:08 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 22 Sep 2010 06:17:25 +0000 (00:17 -0600)
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/js/search.js
imp/lib/Search/Element/Personal.php [new file with mode: 0644]
imp/lib/Search/Filter/Personal.php [new file with mode: 0644]
imp/search.php

index 4760312..0f5d773 100644 (file)
@@ -408,7 +408,7 @@ $_prefs['filter'] = array(
     //         'disable' => false
     //     ))
     // ))
-    'value' => 'a:2:{i:0;C:22:"IMP_Search_Filter_Bulk":30:{a:2:{s:1:"e";i:1;s:1:"v";i:1;}}i:1;C:29:"IMP_Search_Filter_Mailinglist":30:{a:2:{s:1:"e";i:1;s:1:"v";i:1;}}}'
+    'value' => 'a:3:{i:0;C:22:"IMP_Search_Filter_Bulk":30:{a:2:{s:1:"e";i:1;s:1:"v";i:1;}}i:1;C:29:"IMP_Search_Filter_Mailinglist":30:{a:2:{s:1:"e";i:1;s:1:"v";i:1;}}i:2;C:26:"IMP_Search_Filter_Personal":30:{a:2:{s:1:"e";i:1;s:1:"v";i:1;}}}'
 );
 
 
index 0a31ee4..df693d3 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Add personal recipient message filter (Request #8659).
 [mms] Add mailing list message filter (Request #8659).
 [mms] Add ability to define search criteria to be applied to any mailbox
       (Request #8659).
index 3e4c9e7..19a1486 100644 (file)
@@ -84,6 +84,10 @@ var ImpSearch = {
                 this.insertOr();
                 break;
 
+            case 'IMP_Search_Element_Personal':
+                this.insertFilter('personal', crit);
+                break;
+
             case 'IMP_Search_Element_Recipient':
                 this.insertText('recip', crit.t, crit.n);
                 break;
diff --git a/imp/lib/Search/Element/Personal.php b/imp/lib/Search/Element/Personal.php
new file mode 100644 (file)
index 0000000..62c6c9f
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * This class handles the personal recipient search query.
+ *
+ * This query matches if one of the e-mails defined in the identities
+ * matches the To/Cc/Bcc header of an email.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @package  IMP
+ */
+class IMP_Search_Element_Personal extends IMP_Search_Element
+{
+    /**
+     * Constructor.
+     *
+     * @param boolean $not  If true, do a 'NOT' search of $text.
+     */
+    public function __construct($not = false)
+    {
+        /* Data element: (integer) Do a NOT search? */
+        $this->_data = intval($not);
+    }
+
+    /**
+     * Adds the current query item to the query object.
+     *
+     * @param Horde_Imap_Client_Search_Query  The query object.
+     *
+     * @return Horde_Imap_Client_Search_Query  The query object.
+     */
+    public function createQuery($queryob)
+    {
+        $and_ob = new Horde_Imap_Client_Search_Query();
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
+
+        foreach ($identity->getAllIdentityAddresses() as $val) {
+            $ob = new Horde_Imap_Client_Search_Query();
+            $ob->headerText('to', $val, $this->_data);
+            $and_ob->orSearch(array($ob));
+
+            $ob = new Horde_Imap_Client_Search_Query();
+            $ob->headerText('cc', $val, $this->_data);
+            $and_ob->orSearch(array($ob));
+
+            $ob = new Horde_Imap_Client_Search_Query();
+            $ob->headerText('bcc', $val, $this->_data);
+            $and_ob->orSearch(array($ob));
+        }
+
+        $queryob->andSearch(array($and_ob));
+
+        return $queryob;
+    }
+
+    /**
+     * Return search query text representation.
+     *
+     * @return array  The textual description of this search element.
+     */
+    public function queryText()
+    {
+        return ($this->_data ? _("not") . ' ' : '') . _("Personal Messages");
+    }
+
+}
diff --git a/imp/lib/Search/Filter/Personal.php b/imp/lib/Search/Filter/Personal.php
new file mode 100644 (file)
index 0000000..6549b9c
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * This class provides a filter for the personal recipient search.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @package  IMP
+ */
+class IMP_Search_Filter_Personal extends IMP_Search_Filter_Builtin
+{
+    /**
+     * Initialization tasks.
+     */
+    protected function _init()
+    {
+        $this->_id = 'filter_personal';
+        $this->_label = _("Personal Messages");
+
+        $this->add(new IMP_Search_Element_Personal());
+    }
+
+}
index 663e2a6..f153309 100644 (file)
@@ -112,6 +112,10 @@ $filters = array(
         'label' => _("Mailing List Messages"),
         'type' => 'filter'
     ),
+    'personal' => array(
+        'label' => _("Personal Messages"),
+        'type' => 'filter'
+    ),
 );
 
 /* Define some constants. */
@@ -234,6 +238,12 @@ if ($vars->criteria_form) {
             );
             break;
 
+        case 'personal':
+            $c_list[] = new IMP_Search_Element_Personal(
+                $val->n
+            );
+            break;
+
         case 'flag':
             /* Flag search. */
             $formdata = $imp_flags->parseFormId($val->v);