From: Jan Schneider Date: Tue, 22 Dec 2009 14:34:54 +0000 (+0100) Subject: Support composite header rules with IMAP backends (Bug #7343). X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=32b619aa77fa023460409b7161417071d90040ee;p=horde.git Support composite header rules with IMAP backends (Bug #7343). --- diff --git a/ingo/docs/CHANGES b/ingo/docs/CHANGES index 718523a94..bf873bda3 100644 --- a/ingo/docs/CHANGES +++ b/ingo/docs/CHANGES @@ -10,6 +10,7 @@ v2.0-git v1.2.4-cvs ---------- +[jan] Support composite header rules with IMAP backends (Bug #7343). [jan] Fix unconditional debug output with Net_Sieve earlier than 1.2.0 (Bug #8794). [jan] Add Sieve configuration to use UTF-8 encoded folder names (for Dovecot) diff --git a/ingo/lib/Script/Imap.php b/ingo/lib/Script/Imap.php index 74e16600b..5da4828ad 100644 --- a/ingo/lib/Script/Imap.php +++ b/ingo/lib/Script/Imap.php @@ -88,9 +88,10 @@ class Ingo_Script_Imap extends Ingo_Script * Perform the filtering specified in the rules. * * @param array $params The parameter array. It MUST contain: - *
-     * 'mailbox' - The name of the mailbox to filter.
-     * 
+ * - 'mailbox': The name of the mailbox to filter. + * - 'show_filter_msg': Show detailed filter status + * messages? + * - 'filter_seen': Only filter seen messages? * * @return boolean True if filtering performed, false if not. */ @@ -149,13 +150,7 @@ class Ingo_Script_Imap extends Ingo_Script $query = new Horde_Imap_Client_Search_Query(); foreach ($addr as $val) { - $ob = new Horde_Imap_Client_Search_Query(); - $ob->flag('\\deleted', false); - if ($params['filter_seen'] == Ingo_Script::FILTER_UNSEEN) { - $ob->flag('\\seen', false); - } elseif ($params['filter_seen'] == Ingo_Script::FILTER_SEEN) { - $ob->flag('\\seen', true); - } + $ob = $this->_getQuery($params); $ob->headerText('from', $val); $search_array[] = $ob; } @@ -198,13 +193,7 @@ class Ingo_Script_Imap extends Ingo_Script case Ingo_Storage::ACTION_DISCARD: $query = new Horde_Imap_Client_Search_Query(); foreach ($rule['conditions'] as $val) { - $ob = new Horde_Imap_Client_Search_Query(); - $ob->flag('\\deleted', false); - if ($params['filter_seen'] == Ingo_Script::FILTER_UNSEEN) { - $ob->flag('\\seen', false); - } elseif ($params['filter_seen'] == Ingo_Script::FILTER_SEEN) { - $ob->flag('\\seen', true); - } + $ob = $this->_getQuery($params); if (!empty($val['type']) && ($val['type'] == Ingo_Storage::TYPE_SIZE)) { $ob->size($val['value'], ($val['match'] == 'greater than')); @@ -212,7 +201,21 @@ class Ingo_Script_Imap extends Ingo_Script ($val['type'] == Ingo_Storage::TYPE_BODY)) { $ob->text($val['value'], true, ($val['match'] == 'not contain')); } else { - $ob->headerText($val['field'], $val['value'], ($val['match'] == 'not contain')); + if (strpos($val['field'], ',') == false) { + $ob->headerText($val['field'], $val['value'], $val['match'] == 'not contain'); + } else { + $headers = array(); + foreach (explode($val['field'], ',') as $header) { + $headerOb = $this->_getQuery($params); + $headerOb->headerText($header, $val['value'], $val['match'] == 'not contain'); + $headers[] = $headerOb; + } + if ($val['match'] == 'contains') { + $ob->orSearch($headers); + } elseif ($val['match'] == 'not contain') { + $ob->andSearch($headers); + } + } } $search_array[] = $ob; } @@ -359,4 +362,20 @@ class Ingo_Script_Imap extends Ingo_Script : false; } + /** + * Returns a query object prepared for adding further criteria. + * + * @param array $params The parameter array. It MUST contain: + * - 'filter_seen': Only filter seen messages? + * + * @return Ingo_IMAP_Search_Query A query object. + */ + protected function _getQuery($params) + { + $ob = new Horde_Imap_Client_Search_Query(); + $ob->flag('\\deleted', false); + $ob->flag('\\seen', $params['filter_seen'] == Ingo_Script::FILTER_SEEN); + return $ob; + } + }