Add attachment message filter
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 10 Nov 2010 22:32:57 +0000 (15:32 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 11 Nov 2010 16:11:53 +0000 (09:11 -0700)
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/lib/Search/Element/Attachment.php [new file with mode: 0644]
imp/lib/Search/Filter/Attachment.php [new file with mode: 0644]
imp/search.php

index a67d895..1e4d31d 100644 (file)
@@ -399,6 +399,10 @@ $_prefs['vfolder'] = array(
 
 $_prefs['filter'] = array(
     // 'value' => serialize(array(
+    //     // Attachments filter, enabled by default
+    //     new IMP_Search_Filter_Attachment(array(
+    //         'disable' => false
+    //     )),
     //     // Bulk filter, enabled by default
     //     new IMP_Search_Filter_Bulk(array(
     //         'disable' => false
@@ -406,9 +410,13 @@ $_prefs['filter'] = array(
     //     // Mailing list filter, enabled by default
     //     new IMP_Search_Filter_Mailinglist(array(
     //         'disable' => false
+    //     )),
+    //     // Personal filter, enabled by default
+    //     new IMP_Search_Filter_Personal(array(
+    //         'disable' => false
     //     ))
     // ))
-    '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;}}}'
+    'value' => 'a:4:{i:0;C:28:"IMP_Search_Filter_Attachment":30:{a:2:{s:1:"e";i:1;s:1:"v";i:1;}}i:1;C:22:"IMP_Search_Filter_Bulk":30:{a:2:{s:1:"e";i:1;s:1:"v";i:1;}}i:2;C:29:"IMP_Search_Filter_Mailinglist":30:{a:2:{s:1:"e";i:1;s:1:"v";i:1;}}i:3;C:26:"IMP_Search_Filter_Personal":30:{a:2:{s:1:"e";i:1;s:1:"v";i:1;}}}'
 );
 
 
index 62f7b4b..19cacde 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Add attachment message filter.
 [mms] Add post_spam hook called after reporting spam/ham (Request #6455).
 [mms] Implement stationery support in DIMP.
 [mms] Add preference to control displayed content for multipart/alternative
diff --git a/imp/lib/Search/Element/Attachment.php b/imp/lib/Search/Element/Attachment.php
new file mode 100644 (file)
index 0000000..cbd9904
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * This class handles the attachment search query.
+ *
+ * Right now, uses a tremendously simplistic algorithm: it checks if the
+ * base part is 'multipart/mixed' or 'message/rfc822'.
+ *
+ * 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_Attachment 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);
+    }
+
+    /**
+     */
+    public function createQuery($mbox, $queryob)
+    {
+        $ob = new Horde_Imap_Client_Search_Query();
+        $ob2 = clone $ob;
+        $ob3 = clone $ob;
+
+        $ob->headerText('content-type', 'multipart/mixed');
+        $ob2->headerText('content-type', 'message/rfc822');
+
+        /* These searches are OR'd together.  Only 1 must match. */
+        $ob3->orSearch(array($ob, $ob2));
+
+        /* ...but the combined OR search must be AND'd with the rest of the
+         * search terms. */
+        $queryob->andSearch(array($ob3));
+
+        return $queryob;
+    }
+
+    /**
+     */
+    public function queryText()
+    {
+        return $this->_data
+            ? _("messages without attachment(s)")
+            : _("messages with attachment(s)");
+    }
+
+}
diff --git a/imp/lib/Search/Filter/Attachment.php b/imp/lib/Search/Filter/Attachment.php
new file mode 100644 (file)
index 0000000..e199443
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+/**
+ * This class provides a filter for messages with attachments.
+ *
+ * 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_Attachment extends IMP_Search_Filter_Builtin
+{
+    /**
+     */
+    protected function _init()
+    {
+        $this->_id = 'filter_attach';
+        $this->_label = _("Messages with Attachments");
+
+        $this->add(new IMP_Search_Element_Attachment());
+    }
+
+}
index 2230634..716bfa4 100644 (file)
@@ -108,6 +108,10 @@ $filters = array(
         'label' => _("Bulk Messages"),
         'type' => 'filter'
     ),
+    'attach' => array(
+        'label' => _("Contains Attachment(s)"),
+        'type' => 'filter'
+    ),
     'mailinglist' => array(
         'label' => _("Mailing List Messages"),
         'type' => 'filter'
@@ -232,6 +236,12 @@ if ($vars->criteria_form) {
             );
             break;
 
+        case 'attach':
+            $c_list[] = new IMP_Search_Element_Attachment(
+                $val->n
+            );
+            break;
+
         case 'mailinglist':
             $c_list[] = new IMP_Search_Element_Mailinglist(
                 $val->n