summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Wrobel <wrobel@pardus.de>2010-04-06 08:56:32 (GMT)
committerGunnar Wrobel <wrobel@pardus.de>2010-04-06 08:56:32 (GMT)
commit9dd0682b030653b6f848f56104e458a50b3050be (patch)
treed34f5520b59f2db0526298631790058a0b80abda
parent7aa1182bf26431260bad1496dab6209a2be0efd9 (diff)
downloadkolab-webadmin-9dd0682b030653b6f848f56104e458a50b3050be.tar.gz
Add the vacation segment.
-rw-r--r--Makefile.am6
-rw-r--r--lib/KolabAdmin/Sieve.php23
-rw-r--r--lib/KolabAdmin/Sieve/Segment.php10
-rw-r--r--lib/KolabAdmin/Sieve/Segment/Vacation.php286
4 files changed, 321 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am
index c773c8e..392ded7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -121,7 +121,8 @@ phpincludes_DATA = $(PHP_INCLUDES) \
php/admin/include/mysmarty.php
EXTRA_DIST += $(PHP_INCLUDES)
-PEARKA_FILES = lib/KolabAdmin/Ldap.php
+PEARKA_FILES = lib/KolabAdmin/Ldap.php \
+ lib/KolabAdmin/Sieve.php
pearkadir = $(phplibdir)/KolabAdmin
dist_pearka_DATA = $(PEARKA_FILES)
@@ -131,7 +132,8 @@ pearkasievedir = $(phplibdir)/KolabAdmin/Sieve
dist_pearkasieve_DATA = $(PEARKA_SIEVE_FILES)
PEARKA_SIEVE_SEGMENT_FILES = lib/KolabAdmin/Sieve/Segment/Delivery.php \
- lib/KolabAdmin/Sieve/Segment/Forward.php
+ lib/KolabAdmin/Sieve/Segment/Forward.php \
+ lib/KolabAdmin/Sieve/Segment/Vacation.php
pearkasievesegmentdir = $(phplibdir)/KolabAdmin/Sieve/Segment
dist_pearkasievesegment_DATA = $(PEARKA_SIEVE_SEGMENT_FILES)
diff --git a/lib/KolabAdmin/Sieve.php b/lib/KolabAdmin/Sieve.php
index c8626b9..3c636f0 100644
--- a/lib/KolabAdmin/Sieve.php
+++ b/lib/KolabAdmin/Sieve.php
@@ -33,7 +33,9 @@ class KolabAdmin_Sieve
const OLD_SCRIPT_DELIVERY = 'kolab-deliver.siv';
- const OLD_SCRIPT_FORWARD = 'kolab-forward.siv';
+ const OLD_SCRIPT_FORWARD = 'kolab-forward.siv';
+
+ const OLD_SCRIPT_VACATION = 'kolab-vacation.siv';
/**
@@ -83,6 +85,14 @@ class KolabAdmin_Sieve
$this->_segments['forward']->setActive();
}
}
+ if (in_array(self::OLD_SCRIPT_VACATION, $scripts)) {
+ $this->_segments['vacation'] = new KolabAdmin_Sieve_Segment_Vacation(
+ $this->_sieve->getScript(self::OLD_SCRIPT_VACATION)
+ );
+ if ($this->_sieve->getActive() == self::OLD_SCRIPT_VACATION) {
+ $this->_segments['vacation']->setActive();
+ }
+ }
}
}
if (!isset($this->_segments['delivery'])) {
@@ -91,6 +101,9 @@ class KolabAdmin_Sieve
if (!isset($this->_segments['forward'])) {
$this->_segments['forward'] = new KolabAdmin_Sieve_Segment_Forward();
}
+ if (!isset($this->_segments['vacation'])) {
+ $this->_segments['vacation'] = new KolabAdmin_Sieve_Segment_Vacation();
+ }
}
}
@@ -104,7 +117,7 @@ class KolabAdmin_Sieve
$type = strtolower($id[1]);
$class = 'KolabAdmin_Sieve_Segment_' . ucfirst($type);
$segments[$type] = new $class($match[0]);
- if ($id[2] == 'ENABLED') {
+ if (isset($id[2]) && $id[2] == 'ENABLED') {
$segments[$type]->setActive();
}
} else {
@@ -125,4 +138,10 @@ class KolabAdmin_Sieve
$this->_init();
return $this->_segments['forward'];
}
+
+ public function fetchVacationSegment()
+ {
+ $this->_init();
+ return $this->_segments['vacation'];
+ }
} \ No newline at end of file
diff --git a/lib/KolabAdmin/Sieve/Segment.php b/lib/KolabAdmin/Sieve/Segment.php
index a4ec999..6c3af6b 100644
--- a/lib/KolabAdmin/Sieve/Segment.php
+++ b/lib/KolabAdmin/Sieve/Segment.php
@@ -99,6 +99,16 @@ abstract class KolabAdmin_Sieve_Segment
'### SEGMENT END ' . strtoupper($this->type) . "\r\n";
}
+ protected function dotstuff($str)
+ {
+ return str_replace("\n.", "\n..", $str);
+ }
+
+ protected function undotstuff($str)
+ {
+ return str_replace("\n..", "\n.", $str);
+ }
+
abstract public function getArguments();
abstract public function parseArguments($script);
diff --git a/lib/KolabAdmin/Sieve/Segment/Vacation.php b/lib/KolabAdmin/Sieve/Segment/Vacation.php
new file mode 100644
index 0000000..70c73f6
--- /dev/null
+++ b/lib/KolabAdmin/Sieve/Segment/Vacation.php
@@ -0,0 +1,286 @@
+<?php
+/**
+ * A sieve script that responds automatically during vacations.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package KolabAdmin
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://www.kolab.org
+ */
+
+/**
+ * A sieve script that responds automatically during vacations.
+ *
+ * Copyright 2010 Klarälvdalens Datakonsult AB
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you did not
+ * receive this file, see
+ * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ *
+ * @category Kolab
+ * @package KolabAdmin
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://www.kolab.org
+ */
+class KolabAdmin_Sieve_Segment_Vacation
+extends KolabAdmin_Sieve_Segment
+{
+ /**
+ * The segment type.
+ *
+ * @var string
+ */
+ protected $type = 'vacation';
+
+ /**
+ * The text of the automatic response.
+ *
+ * @var string
+ */
+ private $_response;
+
+ /**
+ * Resend response after this amount of days elapsed.
+ *
+ * @var string
+ */
+ private $_resend_after = 7;
+
+ /**
+ * Recipient addresses for which the response should be sent.
+ *
+ * @var array
+ */
+ private $_recipient_addresses = array();
+
+ /**
+ * Should a response be sent in case the incoming message has been tagged as
+ * spam?
+ *
+ * @var boolean
+ */
+ private $_react_to_spam = false;
+
+ /**
+ * The sender address must be part of this domain for the automatic
+ * responses to be sent.
+ *
+ * @var string
+ */
+ private $_domain = '';
+
+ /**
+ * Constructor.
+ *
+ * @param string $script The current script segment
+ */
+ public function __construct($script = '')
+ {
+ $this->_response = '';
+
+ $this->template = 'if allof (%s' . "\r\n" .
+ '%s' . "\r\n" .
+ '%s) {' . "\r\n" .
+ 'vacation :addresses [ %s ] :days %s text:' . "\r\n" .
+ '%s' . "\r\n" .
+ '.' . "\r\n" .
+ ';' . "\r\n" .
+ '}' . "\r\n";
+ parent::__construct($script);
+ }
+
+ /**
+ * Fetch the text of the automatic response.
+ *
+ * @return string The response.
+ */
+ public function getResponse()
+ {
+ return $this->undotstuff($this->_response);
+ }
+
+ /**
+ * Set the text of the automatic response.
+ *
+ * @param string $response The response.
+ *
+ * @return NULL
+ */
+ public function setResponse($response)
+ {
+ $this->_response = $this->dotstuff($response);
+ }
+
+ /**
+ * Resend the automatic response after how many days?
+ *
+ * @return int The number of days.
+ */
+ public function getResendAfter()
+ {
+ return $this->_resend_after;
+ }
+
+ /**
+ * Set after how many days the automatic response should get sent again.
+ *
+ * @param int $days Resend after this many days.
+ *
+ * @return NULL
+ */
+ public function setResendAfter($days)
+ {
+ $this->_resend_after = $days;
+ }
+
+ /**
+ * Send the responses to which recipient addresses?
+ *
+ * @return array The recipient addresses.
+ */
+ public function getRecipientAddresses()
+ {
+ return $this->_recipient_addresses;
+ }
+
+ /**
+ * Set the recipient addresses for which the automatic reply will be sent.
+ *
+ * @param array $addresses The recipient addresses.
+ *
+ * @return NULL
+ */
+ public function setRecipientAddresses(array $addresses)
+ {
+ $this->_recipient_addresses = $addresses;
+ }
+
+ /**
+ * Should the vacation notice also be sent in reply to messages
+ * flagged as spam?
+ *
+ * @return boolean True in case the reply should also be sent to
+ * potential spam messages.
+ */
+ public function getReactToSpam()
+ {
+ return $this->_react_to_spam;
+ }
+
+ /**
+ * Set whether the replies during vacation should also get sent to
+ * potential spam messages.
+ *
+ * @param boolean $react_to_spam Should the replies also be sent
+ * for potential spam messages?
+ *
+ * @return NULL
+ */
+ public function setReactToSpam($react_to_spam)
+ {
+ $this->_react_to_spam = $react_to_spam;
+ }
+
+ /**
+ * Should we only react to messages recieved from a specific domain?
+ *
+ * @return string The domain for which the vacation response will be sent.
+ */
+ public function getDomain()
+ {
+ return $this->_domain;
+ }
+
+ /**
+ * Set the domain for which vacation replies will be sent.
+ *
+ * @param string $domain The domain for which the vacation response will be sent.
+ *
+ * @return NULL
+ */
+ public function setDomain($domain)
+ {
+ $this->_domain = $domain;
+ }
+
+ public function getArguments()
+ {
+ $domain = $this->getDomain();
+ if (!empty($domain)) {
+ $domain = 'address :domain :contains "From" "' . $domain . '"';
+ } else {
+ $domain = '';
+ }
+ if (!$this->getReactToSpam()) {
+ $react_to_spam = 'not header :contains "X-Spam-Flag" "YES"';
+ } else {
+ $react_to_spam = '';
+ }
+ return array(
+ ($this->isActive()) ? 'true, ## vacation enabled' : 'false, ## vacation disabled',
+ $domain,
+ $react_to_spam,
+ '"' . join('", "', $this->getRecipientAddresses()) . '"',
+ $this->getResendAfter(),
+ $this->getResponse()
+ );
+ }
+
+ public function parseArguments($script)
+ {
+ $this->parseResponse($script);
+ $this->parseResendAfter($script);
+ $this->parseDomain($script);
+ $this->parseRecipientAddresses($script);
+ $this->parseReactToSpam($script);
+ }
+
+ public function parseResponse($script)
+ {
+ if (preg_match("/text:(.*\r\n)\\.\r\n/s", $script, $regs)) {
+ $this->_response = trim(str_replace( '\n', "\r\n", $regs[1]));
+ }
+ }
+
+ public function parseResendAfter($script)
+ {
+ if (preg_match("/:days ([0-9]+)/s", $script, $regs)) {
+ $this->_resend_after = $regs[1];
+ }
+ }
+
+ public function parseDomain($script)
+ {
+ if (preg_match('/address :domain :contains "From" "(.*)"/i', $script, $regs)) {
+ $this->_domain = $regs[1];
+ }
+ }
+
+ public function parseRecipientAddresses($script)
+ {
+ if (preg_match("/:addresses \\[([^\\]]*)\\]/s", $script, $regs)) {
+ $tmp = split(',', $regs[1]);
+ $this->_recipient_addresses = array();
+ foreach ($tmp as $a) {
+ if (preg_match('/^ *"(.*)" *$/', $a, $regs)) {
+ $this->_recipient_addresses[] = $regs[1];
+ } else {
+ $this->_recipient_addresses[] = $a;
+ }
+ }
+ }
+ }
+
+ public function parseReactToSpam($script)
+ {
+ if (preg_match('/header :contains "X-Spam-Flag" "YES"/i', $script)) {
+ $this->_react_to_spam = false;
+ } else {
+ $this->_react_to_spam = true;
+ }
+ }
+} \ No newline at end of file