summaryrefslogtreecommitdiff
path: root/lib/KolabAdmin/Sieve/Segment/Delivery.php
blob: 1addd517eb0b17b5e247b888d2c6541ff65debe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
 * A sieve script that handles mail delivery to a specific folder.
 *
 * 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 handles mail delivery to a specific folder.
 *
 * 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_Delivery
extends KolabAdmin_Sieve_Segment
{
    /**
     * The segment type
     *
     * @var string
     */
    protected $type = 'delivery';

    /**
     * The folder to deliver mails to.
     *
     * @var string
     */
    private $_delivery_folder = 'Inbox';

    /**
     * Constructor.
     *
     * @param string $script The current script segment
     */
    public function __construct($script = '')
    {
        $this->template = 'if allof (%s' . "\r\n" .
            'header :contains ["X-Kolab-Scheduling-Message"] ["FALSE"]) {' . "\r\n" .
            'fileinto "INBOX/%s";' . "\r\n" .
            '}' . "\r\n";
        parent::__construct($script);
    }

    /**
     * Retrieve the delivery folder this script will deliver to.
     *
     * @return string The delivery folder.
     */
    public function getDeliveryFolder()
    {
        return $this->_delivery_folder;
    }

    /**
     * Set the delivery folder this script will deliver to.
     *
     * @param string $folder The delivery folder.
     *
     * @return NULL
     */
    public function setDeliveryFolder($folder)
    {
        $this->_delivery_folder = $folder;
    }

    public function getArguments()
    {
        return array(
            ($this->isActive()) ? 'true, ## delivery enabled' : 'false, ## delivery disabled',
            $this->getDeliveryFolder()
        );
    }

    public function parseArguments($script)
    {
        $this->parseDeliveryFolder($script);
    }

    public function parseDeliveryFolder($script)
    {
        if (preg_match("/fileinto \"INBOX\/([^\"]*)\";/", $script, $regs)) {
            $this->setDeliveryFolder($regs[1]);
        }
    }
}