Aleksander Machniak
2014-03-14 390eacc2afbd51960562ae0245f26ba6208298ff
plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
@@ -24,21 +24,21 @@
class rcube_sieve_engine
{
    private $rc;
    private $sieve;
    private $errors;
    private $form;
    private $tips = array();
    private $script = array();
    private $exts = array();
    private $list;
    private $active = array();
    private $headers = array(
    protected $rc;
    protected $sieve;
    protected $errors;
    protected $form;
    protected $tips = array();
    protected $script = array();
    protected $exts = array();
    protected $list;
    protected $active = array();
    protected $headers = array(
        'subject' => 'Subject',
        'from'    => 'From',
        'to'      => 'To',
    );
    private $addr_headers = array(
    protected $addr_headers = array(
        // Required
        "from", "to", "cc", "bcc", "sender", "resent-from", "resent-to",
        // Additional (RFC 822 / RFC 2822)
@@ -53,7 +53,7 @@
        "x-beenthere",
    );
    const VERSION  = '7.2';
    const VERSION  = '8.0';
    const PROGNAME = 'Roundcube (Managesieve)';
    const PORT     = 4190;
@@ -70,7 +70,7 @@
    /**
     * Loads configuration, initializes plugin (including sieve connection)
     */
    function start()
    function start($mode = null)
    {
        // register UI objects
        $this->rc->output->add_handlers(array(
@@ -137,13 +137,16 @@
                $this->rc->session->remove('managesieve_current');
            }
            if (!empty($_GET['_set']) || !empty($_POST['_set'])) {
                $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true);
            if ($mode != 'vacation') {
                if (!empty($_GET['_set']) || !empty($_POST['_set'])) {
                    $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true);
                }
                else if (!empty($_SESSION['managesieve_current'])) {
                    $script_name = $_SESSION['managesieve_current'];
                }
            }
            else if (!empty($_SESSION['managesieve_current'])) {
                $script_name = $_SESSION['managesieve_current'];
            }
            else {
            if ($script_name === null || $script_name === '') {
                // get (first) active script
                if (!empty($this->active[0])) {
                    $script_name = $this->active[0];
@@ -911,9 +914,12 @@
                    break;
                case 'vacation':
                    $reason        = $this->strip_value($reasons[$idx]);
                    $interval_type = $interval_types[$idx] == 'seconds' ? 'seconds' : 'days';
console('---------------');
console($_POST);
console($reason);
                    $this->form['actions'][$i]['reason']    = str_replace("\r\n", "\n", $reason);
                    $this->form['actions'][$i]['subject']   = $subject[$idx];
                    $this->form['actions'][$i]['addresses'] = array_shift($addresses);
@@ -980,7 +986,7 @@
            }
            if (!$this->errors && !$error) {
                // zapis skryptu
                // save the script
                if (!isset($this->script[$fid])) {
                    $fid = $this->sieve->script->add_rule($this->form);
                    $new = true;
@@ -1016,7 +1022,7 @@
        $this->send();
    }
    private function send()
    protected function send()
    {
        // Handle form action
        if (isset($_GET['_framed']) || isset($_POST['_framed'])) {
@@ -1026,7 +1032,8 @@
            else {
                $this->rc->output->send('managesieve.filteredit');
            }
        } else {
        }
        else {
            $this->rc->output->set_pagetitle($this->plugin->gettext('filters'));
            $this->rc->output->send('managesieve.managesieve');
        }
@@ -1809,12 +1816,12 @@
        return $out;
    }
    private function genid()
    protected function genid()
    {
        return preg_replace('/[^0-9]/', '', microtime(true));
    }
    private function strip_value($str, $allow_html = false, $trim = true)
    protected function strip_value($str, $allow_html = false, $trim = true)
    {
        if (is_array($str)) {
            foreach ($str as $idx => $val) {
@@ -1835,7 +1842,7 @@
        return $trim ? trim($str) : $str;
    }
    private function error_class($id, $type, $target, $elem_prefix='')
    protected function error_class($id, $type, $target, $elem_prefix='')
    {
        // TODO: tooltips
        if (($type == 'test' && ($str = $this->errors['tests'][$id][$target])) ||
@@ -1848,7 +1855,7 @@
        return '';
    }
    private function add_tip($id, $str, $error=false)
    protected function add_tip($id, $str, $error=false)
    {
        if ($error)
            $str = html::span('sieve error', $str);
@@ -1856,7 +1863,7 @@
        $this->tips[] = array($id, $str);
    }
    private function print_tips()
    protected function print_tips()
    {
        if (empty($this->tips))
            return;
@@ -1865,7 +1872,7 @@
        $this->rc->output->add_script($script, 'foot');
    }
    private function list_input($id, $name, $value, $enabled, $class, $size=null)
    protected function list_input($id, $name, $value, $enabled, $class, $size=null)
    {
        $value = (array) $value;
        $value = array_map(array('rcube', 'Q'), $value);
@@ -1881,7 +1888,7 @@
    /**
     * Validate input for date part elements
     */
    private function validate_date_part($type, $value)
    protected function validate_date_part($type, $value)
    {
        // we do simple validation of date/part format
        switch ($type) {
@@ -1926,7 +1933,7 @@
     *
     * @return string Mailbox name
     */
    private function mod_mailbox($mailbox, $mode = 'out')
    protected function mod_mailbox($mailbox, $mode = 'out')
    {
        $delimiter         = $_SESSION['imap_delimiter'];
        $replace_delimiter = $this->rc->config->get('managesieve_replace_delimiter');
@@ -2218,7 +2225,7 @@
    /**
     * Initializes internal script data
     */
    private function init_script()
    protected function init_script()
    {
        $this->script = $this->sieve->script->as_array();