1: <?php
2: /**
3: * Copyright 2010-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2010-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * The attachment search query.
16: *
17: * Right now, uses a tremendously simplistic algorithm: it checks if the
18: * base part is 'multipart/mixed' or 'message/rfc822'.
19: *
20: * @author Michael Slusarz <slusarz@horde.org>
21: * @category Horde
22: * @copyright 2010-2014 Horde LLC
23: * @license http://www.horde.org/licenses/gpl GPL
24: * @package IMP
25: */
26: class IMP_Search_Element_Attachment extends IMP_Search_Element
27: {
28: /**
29: * Constructor.
30: *
31: * @param boolean $not If true, do a 'NOT' search of $text.
32: */
33: public function __construct($not = false)
34: {
35: /* Data element: (integer) Do a NOT search? */
36: $this->_data = intval(!empty($not));
37: }
38:
39: /**
40: */
41: public function createQuery($mbox, $queryob)
42: {
43: $ob = new Horde_Imap_Client_Search_Query();
44: $ob2 = clone $ob;
45: $ob3 = clone $ob;
46:
47: $ob->headerText('content-type', 'multipart/mixed', $this->_data);
48: $ob2->headerText('content-type', 'message/rfc822', $this->_data);
49:
50: /* If regular search, searches are OR'd: only one must match.
51: * If NOT search, searches are AND'd: both must not match. */
52: if ($this->_data) {
53: $ob3->andSearch(array($ob, $ob2));
54: } else {
55: $ob3->orSearch(array($ob, $ob2));
56: }
57:
58: /* ...but the combined search must be AND'd with the rest of the
59: * search terms. */
60: $queryob->andSearch($ob3);
61:
62: return $queryob;
63: }
64:
65: /**
66: */
67: public function queryText()
68: {
69: return $this->_data
70: ? _("messages without attachment(s)")
71: : _("messages with attachment(s)");
72: }
73:
74: }
75: