Request #8659: Add mailing list message filter
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 22 Sep 2010 05:42:49 +0000 (23:42 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 22 Sep 2010 05:42:49 +0000 (23:42 -0600)
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/js/search.js
imp/lib/Search/Element/Mailinglist.php [new file with mode: 0644]
imp/lib/Search/Filter/Mailinglist.php [new file with mode: 0644]
imp/search.php

index 512f8ab..113e7f8 100644 (file)
@@ -402,9 +402,13 @@ $_prefs['filter'] = array(
     //     // Bulk filter, enabled by default
     //     new IMP_Search_Filter_Bulk(array(
     //         'disable' => false
+    //     )),
+    //     // Mailing list filter, enabled by default
+    //     new IMP_Search_Filter_Mailinglist(array(
+    //         'disable' => false
     //     ))
     // ))
-    'value' => 'a:1:{i:0;C:22:"IMP_Search_Filter_Bulk":88:{a:3:{s:1:"c";a:1:{i:0;C:23:"IMP_Search_Element_Bulk":5:{[1,0]}}s:1:"e";i:1;s:1:"v";i:1;}}}'
+    'value' => 'a:2:{i:0;C:22:"IMP_Search_Filter_Bulk":88:{a:3:{s:1:"c";a:1:{i:0;C:23:"IMP_Search_Element_Bulk":5:{[1,0]}}s:1:"e";i:1;s:1:"v";i:1;}}i:1;C:29:"IMP_Search_Filter_Mailinglist":95:{a:3:{s:1:"c";a:1:{i:0;C:30:"IMP_Search_Element_Mailinglist":5:{[1,0]}}s:1:"e";i:1;s:1:"v";i:1;}}}'
 );
 
 
index 53c6ba8..0a31ee4 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Add mailing list message filter (Request #8659).
 [mms] Add ability to define search criteria to be applied to any mailbox
       (Request #8659).
 [mms] Use recipient search (To/Cc/Bcc) by default instead of To search.
index f804b18..3e4c9e7 100644 (file)
@@ -76,6 +76,10 @@ var ImpSearch = {
                 }
                 break;
 
+            case 'IMP_Search_Element_Mailinglist':
+                this.insertFilter('mailinglist', crit);
+                break;
+
             case 'IMP_Search_Element_Or':
                 this.insertOr();
                 break;
diff --git a/imp/lib/Search/Element/Mailinglist.php b/imp/lib/Search/Element/Mailinglist.php
new file mode 100644 (file)
index 0000000..a74c92a
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+/**
+ * This class handles the mailing list search query.
+ *
+ * Uses the List-Id header defined by RFC 2919 to identify mailing list
+ * messages.
+ *
+ * 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_Mailinglist 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)
+    {
+        $queryob->headerText('list-id', '', $this->_data);
+
+        return $queryob;
+    }
+
+    /**
+     * Return search query text representation.
+     *
+     * @return array  The textual description of this search element.
+     */
+    public function queryText()
+    {
+        return ($this->_data ? _("not") . ' ' : '') . _("Mailing List Message");
+    }
+
+}
diff --git a/imp/lib/Search/Filter/Mailinglist.php b/imp/lib/Search/Filter/Mailinglist.php
new file mode 100644 (file)
index 0000000..9ebde46
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/**
+ * This class provides a filter for mailing list messages.
+ *
+ * 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_Mailinglist extends IMP_Search_Filter
+{
+    /**
+     * Can this query be edited?
+     *
+     * @var boolean
+     */
+    protected $_canEdit = false;
+
+    /**
+     * List of serialize entries not to save.
+     *
+     * @var array
+     */
+    protected $_nosave = array('i', 'l');
+
+    /**
+     * Constructor.
+     *
+     * The 'add', 'id', 'label', and 'mboxes' parameters are ignored.
+     *
+     * @see parent::__construct()
+     */
+    public function __construct(array $opts = array())
+    {
+        $this->enabled = empty($opts['disable']);
+
+        $this->add(new IMP_Search_Element_Mailinglist());
+
+        $this->_init();
+    }
+
+    /**
+     * Initialization tasks.
+     */
+    protected function _init()
+    {
+        $this->_id = 'filter_mlist';
+        $this->_label = _("Mailing List Messages");
+    }
+
+    /**
+     * Unserialization.
+     *
+     * @param string $data  Serialized data.
+     *
+     * @throws Exception
+     */
+    public function unserialize($data)
+    {
+        parent::unserialize($data);
+        $this->_init();
+    }
+
+}
index 36183f8..663e2a6 100644 (file)
@@ -108,6 +108,10 @@ $filters = array(
         'label' => _("Bulk Messages"),
         'type' => 'filter'
     ),
+    'mailinglist' => array(
+        'label' => _("Mailing List Messages"),
+        'type' => 'filter'
+    ),
 );
 
 /* Define some constants. */
@@ -224,6 +228,12 @@ if ($vars->criteria_form) {
             );
             break;
 
+        case 'mailinglist':
+            $c_list[] = new IMP_Search_Element_Mailinglist(
+                $val->n
+            );
+            break;
+
         case 'flag':
             /* Flag search. */
             $formdata = $imp_flags->parseFormId($val->v);