Skip to content

Commit

Permalink
[jan] Add support for Sieve date extension to vacation messages (Requ…
Browse files Browse the repository at this point in the history
…est #12520).
  • Loading branch information
yunosh committed Nov 9, 2016
1 parent d6cd5bc commit 28ac8bf
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ingo/basic.php
Expand Up @@ -18,7 +18,7 @@
*/

require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('ingo');
Horde_Registry::appInit('ingo', array('timezone' => true));

$vars = $injector->getInstance('Horde_Variables');

Expand Down
5 changes: 5 additions & 0 deletions ingo/config/backends.php
Expand Up @@ -289,6 +289,11 @@
Ingo::RULE_ALL => array(
'driver' => 'sieve',
'params' => array(
// If false, use less reliable regular expression parsing of
// Received: headers instead of the standardized 'date' and
// 'relational' extensions for date-limiting vacation messages.
'date' => true,

// If true, use the deprecated 'imapflags' extension to set
// flag status instead of the newer, standardized
// 'imap4flags'.
Expand Down
2 changes: 2 additions & 0 deletions ingo/docs/CHANGES
Expand Up @@ -2,6 +2,8 @@
v3.3.0-git
----------

[jan] Add support for Sieve date extension to vacation messages (Request
#12520).
[mjr] Export active vacation messages via the timeObjects API (Request #10885).
[mms] Added a NoSQL (MongoDB) driver for the storage backend.
[mms] Rule code has been separated from the storage backend drivers.
Expand Down
8 changes: 8 additions & 0 deletions ingo/docs/UPGRADING
Expand Up @@ -51,6 +51,14 @@ Configuration Options (conf.php)
Added a NoSQL (MongoDB) driver for the storage backend.


Backend Configuration (backends.php)
------------------------------------

The Sieve driver now uses the 'date' and 'relational' extensions for timed
vacation messages by default. If using a Sieve version that doesn't support
those extensions, set 'date' to false in the sieve script parameters to use the
older regular expression parsing (see backends.php).


Upgrading Ingo From 3.1.x To 3.2
================================
Expand Down
3 changes: 2 additions & 1 deletion ingo/lib/Script/Sieve.php
Expand Up @@ -345,7 +345,8 @@ protected function _addVacationBlocks(Ingo_Rule $rule)
'end_year' => $rule->end_year,
'end_month' => $rule->end_month,
'end_day' => $rule->end_day,
'reason' => $rule->reason
'reason' => $rule->reason,
'date' => !empty($this->_params['date']),
));

if ($rule->ignore_list) {
Expand Down
47 changes: 43 additions & 4 deletions ingo/lib/Script/Sieve/Action/Vacation.php
Expand Up @@ -52,6 +52,24 @@ public function __construct($vars = array())
* @return string A Sieve script snippet.
*/
public function generate()
{
if (empty($this->_vars['start']) || empty($this->_vars['end'])) {
return $this->_vacationCode();
}

if ($this->_vars['date']) {
return $this->_dateCheck();
}

return $this->_regexCheck();
}

/**
* Uses regular expression parsing to limit vacation messages by date.
*
* @return string A Sieve script snippet.
*/
protected function _regexCheck()
{
$start_year = $this->_vars['start_year'];
$start_month = $this->_vars['start_month'];
Expand All @@ -63,9 +81,7 @@ public function generate()

$code = '';

if (empty($this->_vars['start']) || empty($this->_vars['end'])) {
return $this->_vacationCode();
} elseif ($end_year > $start_year + 1) {
if ($end_year > $start_year + 1) {
$code .= 'if ' . $this->_yearCheck($start_year + 1, $end_year - 1)
. " {\n"
. ' ' . $this->_vacationCode()
Expand Down Expand Up @@ -148,12 +164,31 @@ public function generate()
. $this->_vacationCode()
. "\n }\n";
}
$code .= " }";
$code .= ' }';
}

return $code;
}

/**
* Uses 'date' and 'relative' extensions to limit vacation messages by
* date.
*
* @return string A Sieve script snippet.
*/
protected function _dateCheck()
{
return 'if allof ( currentdate :zone '
. date('O', $this->_vars['start']) . ' :value "ge" "date" "'
. date('Y-m-d', $this->_vars['start']) . "\",\n"
. ' currentdate :zone '
. date('O', $this->_vars['end']) . ' :value "le" "date" "'
. date('Y-m-d', $this->_vars['end']) . "\" ) {\n"
. ' '
. $this->_vacationCode()
. "\n }";
}

/**
* Checks if the rule parameters are valid.
*
Expand All @@ -175,6 +210,10 @@ public function check()
*/
public function requires()
{
if ($this->_vars['date']) {
return array('vacation', 'date', 'relational');
}

return array('vacation', 'regex');
}

Expand Down
2 changes: 2 additions & 0 deletions ingo/package.xml
Expand Up @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/apache">ASL</license>
<notes>
* [jan] Add support for Sieve date extension to vacation messages (Request #12520).
* [mjr] Export active vacation messages via the timeObjects API (Request #10885).
* [mms] Added a NoSQL (MongoDB) driver for the storage backend.
* [mms] Rule code has been separated from the storage backend drivers.
Expand Down Expand Up @@ -1747,6 +1748,7 @@
</stability>
<license uri="http://www.horde.org/licenses/apache">ASL</license>
<notes>
* [jan] Add support for Sieve date extension to vacation messages (Request #12520).
* [mjr] Export active vacation messages via the timeObjects API (Request #10885).
* [mms] Added a NoSQL (MongoDB) driver for the storage backend.
* [mms] Rule code has been separated from the storage backend drivers.
Expand Down

0 comments on commit 28ac8bf

Please sign in to comment.