thomascube
2010-02-21 47d8d39cf49310b688967f7571b0d66b5971b39c
plugins/managesieve/managesieve.php
@@ -7,10 +7,12 @@
 * It's clickable interface which operates on text scripts and communicates
 * with server using managesieve protocol. Adds Filters tab in Settings.
 *
 * @version 2.0
 * @version 2.2
 * @author Aleksander 'A.L.E.C' Machniak <alec@alec.pl>
 *
 * Configuration (see config.inc.php.dist):
 * Configuration (see config.inc.php.dist)
 *
 * $Id$
 */
class managesieve extends rcube_plugin
@@ -61,11 +63,13 @@
    require_once($this->home . '/lib/Net/Sieve.php');
    require_once($this->home . '/lib/rcube_sieve.php');
    $host = str_replace('%h', $_SESSION['imap_host'], $this->rc->config->get('managesieve_host', 'localhost'));
    $port = $this->rc->config->get('managesieve_port', 2000);
    // try to connect to managesieve server and to fetch the script
    $this->sieve = new rcube_sieve($_SESSION['username'],
   $this->rc->decrypt($_SESSION['password']), 
   str_replace('%h', $_SESSION['imap_host'], $this->rc->config->get('managesieve_host', 'localhost')),
   $this->rc->config->get('managesieve_port', 2000),
   $host, $port,
   $this->rc->config->get('managesieve_usetls', false),
   $this->rc->config->get('managesieve_disabled_extensions'),
   $this->rc->config->get('managesieve_debug', false)
@@ -120,6 +124,9 @@
          $this->rc->output->show_message('managesieve.filterunknownerror', 'error');
   break;
      }
      raise_error(array('code' => 403, 'type' => 'php', 'message' => "Unable to connect to managesieve on $host:$port"), true, false);
      // to disable 'Add filter' button set env variable
      $this->rc->output->set_env('filterconnerror', true);
      $this->script = array();
@@ -271,7 +278,7 @@
    // filter add/edit action
    else if (isset($_POST['_name']))
    {
      $name = trim(get_input_value('_name', RCUBE_INPUT_POST));
      $name = trim(get_input_value('_name', RCUBE_INPUT_POST, true));
      $fid = trim(get_input_value('_fid', RCUBE_INPUT_POST));
      $join = trim(get_input_value('_join', RCUBE_INPUT_POST));
  
@@ -318,7 +325,7 @@
      else foreach($headers as $idx => $header)
      {
   $header = $this->strip_value($header);
   $target = $this->strip_value($targets[$idx]);
   $target = $this->strip_value($targets[$idx], true);
   $op = $this->strip_value($ops[$idx]);
   // normal header
@@ -480,9 +487,7 @@
   {
     $this->rc->output->show_message('managesieve.filtersaved', 'confirmation');
     $this->rc->output->add_script(sprintf("rcmail.managesieve_updatelist('%s', '%s', %d);",
       isset($new) ? 'add' : 'update', $this->form['name'], $fid), 'foot');
//     $this->rc->output->command('managesieve_updatelist', isset($new) ? 'add' : 'update', $this->form['name'], $fid);
//     $this->rc->output->send();
       isset($new) ? 'add' : 'update', Q($this->form['name']), $fid), 'foot');
   }
   else
   {
@@ -547,10 +552,12 @@
  
    $select = new html_select(array('name' => '_set', 'id' => $attrib['id'], 'onchange' => 'rcmail.managesieve_set()'));
    asort($list, SORT_LOCALE_STRING);
    if ($list) {
      asort($list, SORT_LOCALE_STRING);
    foreach($list as $set)
      $select->add($set . ($set == $active ? ' ('.$this->gettext('active').')' : ''), $set);
      foreach($list as $set)
        $select->add($set . ($set == $active ? ' ('.$this->gettext('active').')' : ''), $set);
    }
    
    $out = $select->show($this->sieve->current);
    
@@ -894,7 +901,7 @@
    $out .= '<select id="action_mailbox' .$id. '" name="_action_mailbox[]" style="display:' 
   .(!isset($action) || $action['type']=='fileinto' ? 'inline' : 'none'). '">';
    $this->rc->imap_init(true);
    $this->rc->imap_connect();
    $a_folders = $this->rc->imap->list_mailboxes();
    $delimiter = $this->rc->imap->get_hierarchy_delimiter();
@@ -955,9 +962,12 @@
    return $result;
  }
  private function strip_value($str)
  private function strip_value($str, $allow_html=false)
  {
    return trim(strip_tags($str));
    if (!$allow_html)
      $str = strip_tags($str);
    return trim($str);
  }
  private function error_class($id, $type, $target, $name_only=false)