From 553216ba5135fba3287054ffa84d16ae9e21c8bf Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 10 Nov 2010 15:32:57 -0700 Subject: [PATCH] Add attachment message filter --- imp/config/prefs.php.dist | 10 +++++- imp/docs/CHANGES | 1 + imp/lib/Search/Element/Attachment.php | 61 +++++++++++++++++++++++++++++++++++ imp/lib/Search/Filter/Attachment.php | 27 ++++++++++++++++ imp/search.php | 10 ++++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 imp/lib/Search/Element/Attachment.php create mode 100644 imp/lib/Search/Filter/Attachment.php diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index a67d89573..1e4d31d7f 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -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;}}}' ); diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 62f7b4bdf..19cacde3f 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -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 index 000000000..cbd9904f0 --- /dev/null +++ b/imp/lib/Search/Element/Attachment.php @@ -0,0 +1,61 @@ + + * @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 index 000000000..e199443d4 --- /dev/null +++ b/imp/lib/Search/Filter/Attachment.php @@ -0,0 +1,27 @@ + + * @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()); + } + +} diff --git a/imp/search.php b/imp/search.php index 2230634a7..716bfa4c8 100644 --- a/imp/search.php +++ b/imp/search.php @@ -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 -- 2.11.0