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