Changeset 3460 in subversion


Ignore:
Timestamp:
Apr 1, 2010 2:59:30 AM (3 years ago)
Author:
alec
Message:
  • managesieve: import/export
Location:
trunk/plugins/managesieve
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/managesieve/Changelog

    r3454 r3460  
     1* version 2.4 [2010-04-01] 
     2----------------------------------------------------------- 
    13- Fixed bug in DIGEST-MD5 authentication (http://pear.php.net/bugs/bug.php?id=17285) 
    24- Fixed disabling rules with many tests 
    35- Small css unification with core 
     6- Scripts import/export 
    47 
    58* version 2.3 [2010-03-18] 
  • trunk/plugins/managesieve/lib/rcube_sieve.php

    r3398 r3460  
    224224 
    225225        // try to parse from Roundcube format 
    226         $this->script = new rcube_sieve_script($script, $this->disabled); 
     226        $this->script = $this->_parse($script); 
     227 
     228        $this->current = $name; 
     229 
     230        return true; 
     231    } 
     232 
     233    /** 
     234    * Loads script from text content 
     235    */ 
     236    public function load_script($script) 
     237    { 
     238        if (!$this->sieve) 
     239            return $this->_set_error(SIEVE_ERROR_INTERNAL); 
     240 
     241        // try to parse from Roundcube format 
     242        $this->script = $this->_parse($script); 
     243    } 
     244 
     245    /** 
     246    * Creates rcube_sieve_script object from text script 
     247    */ 
     248    private function _parse($txt) 
     249    { 
     250        // try to parse from Roundcube format 
     251        $script = new rcube_sieve_script($txt, $this->disabled); 
    227252 
    228253        // ... else try to import from different formats 
    229         if (empty($this->script->content)) { 
    230             $script = $this->_import_rules($script); 
    231             $this->script = new rcube_sieve_script($script, $this->disabled); 
     254        if (empty($script->content)) { 
     255            $script = $this->_import_rules($txt); 
     256            $script = new rcube_sieve_script($script, $this->disabled); 
    232257        } 
    233258 
    234259        // replace all elsif with if+stop, we support only ifs 
    235         foreach ($this->script->content as $idx => $rule) { 
    236             if (!isset($this->script->content[$idx+1]) 
    237                 || preg_match('/^else|elsif$/', $this->script->content[$idx+1]['type'])) { 
     260        foreach ($script->content as $idx => $rule) { 
     261            if (!isset($script->content[$idx+1]) 
     262                || preg_match('/^else|elsif$/', $script->content[$idx+1]['type'])) { 
    238263                // 'stop' not found? 
    239264                if (!preg_match('/^(stop|vacation)$/', $rule['actions'][count($rule['actions'])-1]['type'])) { 
    240                     $this->script->content[$idx]['actions'][] = array( 
     265                    $script->content[$idx]['actions'][] = array( 
    241266                        'type' => 'stop' 
    242267                    ); 
     
    245270        } 
    246271 
    247         $this->current = $name; 
    248  
    249         return true; 
     272        return $script; 
     273    } 
     274 
     275    /** 
     276    * Gets specified script as text 
     277    */ 
     278    public function get_script($name) 
     279    { 
     280        if (!$this->sieve) 
     281            return $this->_set_error(SIEVE_ERROR_INTERNAL); 
     282 
     283        $content = $this->sieve->getScript($name); 
     284 
     285        if (PEAR::isError($content)) 
     286            return $this->_set_error(SIEVE_ERROR_OTHER); 
     287         
     288        return $content; 
    250289    } 
    251290 
     
    267306        return $this->save_script($name, $content); 
    268307    } 
    269  
    270308 
    271309    private function _import_rules($script) 
  • trunk/plugins/managesieve/localization/en_US.inc

    r3376 r3460  
    4141$labels['filtersetdel'] = 'Delete current filters set'; 
    4242$labels['filtersetact'] = 'Activate current filters set'; 
     43$labels['filtersetget'] = 'Download filters set in text format'; 
    4344$labels['filterdef'] = 'Filter definition'; 
    4445$labels['filtersetname'] = 'Filters set name'; 
    4546$labels['newfilterset'] = 'New filters set'; 
    4647$labels['active'] = 'active'; 
    47 $labels['copyfromset'] = 'Copy filters from set'; 
    48 $labels['none'] = '- none -'; 
     48$labels['none'] = 'none'; 
     49$labels['fromset'] = 'from set'; 
     50$labels['fromfile'] = 'from file'; 
    4951$labels['filterdisabled'] = 'Filter disabled'; 
    5052 
  • trunk/plugins/managesieve/localization/pl_PL.inc

    r3376 r3460  
    5151$labels['filtersetact'] = 'Aktywuj bierzÄ 
    5252cy zbiór filtrów'; 
     53$labels['filtersetget'] = 'Pobierz bierzÄ 
     54cy zbiór filtrów w formacie tekstowym'; 
    5355$labels['filterdef'] = 'Definicja filtra'; 
    54 $labels['filtersetname'] = 'Nazwa zbioru filtrów'; 
     56$labels['filtersetname'] = 'Nazwa zbioru'; 
    5557$labels['newfilterset'] = 'Nowy zbiór filtrów'; 
    5658$labels['active'] = 'aktywny'; 
    57 $labels['copyfromset'] = 'Skopiuj filtry ze zbioru'; 
    58 $labels['none'] = '- brak -'; 
     59$labels['none'] = 'brak'; 
     60$labels['fromset'] = 'ze zbioru'; 
     61$labels['fromfile'] = 'z pliku'; 
    5962$labels['filterdisabled'] = 'Filtr wyłĠ
    6063czony'; 
  • trunk/plugins/managesieve/managesieve.js

    r3376 r3460  
    2424    rcmail.register_command('plugin.managesieve-setdel', function() { rcmail.managesieve_setdel() }, true); 
    2525    rcmail.register_command('plugin.managesieve-setact', function() { rcmail.managesieve_setact() }, true); 
     26    rcmail.register_command('plugin.managesieve-setget', function() { rcmail.managesieve_setget() }, true); 
    2627 
    2728    if (rcmail.env.action == 'plugin.managesieve') 
     
    3435            'plugin.managesieve-down', false); 
    3536          rcmail.enable_command('plugin.managesieve-add', 'plugin.managesieve-setadd', !rcmail.env.sieveconnerror); 
    36           rcmail.enable_command('plugin.managesieve-set', rcmail.gui_objects.filtersetslist != null); 
     37          rcmail.enable_command('plugin.managesieve-set', 'plugin.managesieve-setget', 
     38            rcmail.gui_objects.filtersetslist != null); 
    3739          rcmail.enable_command('plugin.managesieve-setact', 
    3840            (rcmail.gui_objects.filtersetslist && rcmail.gui_objects.filtersetslist.length > 1 
     
    411413    { 
    412414    var script = $(this.gui_objects.filtersetslist).val(); 
    413     location.href = this.env.comm_path+'&_action=plugin.managesieve&_sid='+script; 
     415    location.href = this.env.comm_path+'&_action=plugin.managesieve&_set='+script; 
     416    }; 
     417 
     418  // Script download 
     419  rcube_webmail.prototype.managesieve_setget = function() 
     420    { 
     421    var script = $(this.gui_objects.filtersetslist).val(); 
     422    location.href = this.env.comm_path+'&_action=plugin.managesieve&_act=setget&_set='+script; 
    414423    }; 
    415424 
     
    467476    }; 
    468477 
    469  
    470478  rcube_webmail.prototype.managesieve_reload = function(set) 
    471479    { 
     
    473481      window.setTimeout(function() { 
    474482        location.href = rcmail.env.comm_path + '&_action=plugin.managesieve' 
    475           + (rcmail.env.reload_set ? '&_sid=' + rcmail.env.reload_set : '') 
     483          + (rcmail.env.reload_set ? '&_set=' + rcmail.env.reload_set : '') 
    476484        }, 500); 
    477485    }; 
  • trunk/plugins/managesieve/managesieve.php

    r3376 r3460  
    88 * with server using managesieve protocol. Adds Filters tab in Settings. 
    99 * 
    10  * @version 2.3 
     10 * @version 2.4 
    1111 * @author Aleksander 'A.L.E.C' Machniak <alec@alec.pl> 
    1212 * 
     
    8080      $_SESSION['managesieve_active'] = $active; 
    8181       
    82       if (!empty($_GET['_sid'])) { 
    83         $script_name = get_input_value('_sid', RCUBE_INPUT_GET); 
     82      if (!empty($_GET['_set'])) { 
     83        $script_name = get_input_value('_set', RCUBE_INPUT_GET); 
    8484      } else if (!empty($_SESSION['managesieve_current'])) { 
    8585        $script_name = $_SESSION['managesieve_current']; 
     
    225225        } 
    226226      } 
     227      else if ($action=='setget') 
     228      { 
     229        $script_name = get_input_value('_set', RCUBE_INPUT_GPC); 
     230        $script = $this->sieve->get_script($script_name); 
     231 
     232        if (PEAR::isError($script)) 
     233          exit; 
     234 
     235        $browser = new rcube_browser; 
     236         
     237        // send download headers 
     238        header("Content-Type: application/octet-stream"); 
     239        header("Content-Length: ".strlen($script)); 
     240 
     241        if ($browser->ie) 
     242          header("Content-Type: application/force-download"); 
     243        if ($browser->ie && $browser->ver < 7) 
     244          $filename = rawurlencode(abbreviate_string($script_name, 55)); 
     245        else if ($browser->ie) 
     246          $filename = rawurlencode($script_name); 
     247        else 
     248          $filename = addcslashes($script_name, '\\"'); 
     249         
     250        header("Content-Disposition: attachment; filename=\"$filename.txt\""); 
     251        echo $script; 
     252        exit;                                                                                               
     253      } 
    227254      elseif ($action=='ruleadd') 
    228255      { 
     
    256283    if (!empty($_POST['_newset'])) 
    257284    { 
    258       $name = get_input_value('_name', RCUBE_INPUT_GPC); 
    259       $copy = get_input_value('_copy', RCUBE_INPUT_GPC); 
     285      $name = get_input_value('_name', RCUBE_INPUT_POST); 
     286      $copy = get_input_value('_copy', RCUBE_INPUT_POST); 
     287      $from = get_input_value('_from', RCUBE_INPUT_POST); 
    260288 
    261289      if (!$name) 
     
    263291      else if (mb_strlen($name)>128) 
    264292        $error = 'managesieve.nametoolong'; 
    265       else if (!$this->sieve->copy($name, $copy)) 
     293      else if ($from == 'file') { 
     294        // from file 
     295        if (is_uploaded_file($_FILES['_file']['tmp_name'])) { 
     296          $file = file_get_contents($_FILES['_file']['tmp_name']); 
     297          $file = preg_replace('/\r/', '', $file); 
     298          // for security don't save script directly 
     299          // check syntax before, like this... 
     300          $this->sieve->load_script($file); 
     301          if (!$this->sieve->save($name)) { 
     302            $error = 'managesieve.setcreateerror';   
     303          } 
     304        } 
     305        else {  // upload failed 
     306          $err = $_FILES['_file']['error']; 
     307          $error = true; 
     308          if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { 
     309            $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => 
     310                show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); 
     311          } 
     312          else { 
     313            $error = 'fileuploaderror'; 
     314          } 
     315        } 
     316      } 
     317      else if (!$this->sieve->copy($name, $from == 'set' ? $copy : '')) { 
    266318        $error = 'managesieve.setcreateerror'; 
    267                  
     319      } 
     320 
    268321      if (!$error) { 
    269322        $this->rc->output->show_message('managesieve.setcreated', 'confirmation'); 
    270323        $this->rc->output->command('parent.managesieve_reload', $name); 
    271 //      $this->rc->session->remove('managesieve_current'); 
     324      } else if ($msg) { 
     325        $this->rc->output->command('display_message', $msg, 'error'); 
    272326      } else { 
    273327        $this->rc->output->show_message($error, 'error'); 
     
    597651      $attrib['id'] = 'rcmfiltersetform'; 
    598652 
    599     $out = '<form name="filtersetform" action="./" method="post">'."\n"; 
     653    $out = '<form name="filtersetform" action="./" method="post" enctype="multipart/form-data">'."\n"; 
    600654 
    601655    $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $this->rc->task)); 
     
    606660    $out .= $hiddenfields->show(); 
    607661 
    608     $name = get_input_value('_name', RCUBE_INPUT_GPC); 
    609     $copy = get_input_value('_copy', RCUBE_INPUT_GPC); 
     662    $name = get_input_value('_name', RCUBE_INPUT_POST); 
     663    $copy = get_input_value('_copy', RCUBE_INPUT_POST); 
     664    $selected = get_input_value('_from', RCUBE_INPUT_POST); 
    610665 
    611666    $table = new html_table(array('cols' => 2)); 
     
    618673    $table->add(null, $input_name->show($name)); 
    619674 
     675    $from ='<div class="itemlist">'; 
     676    $from .= '<input type="radio" id="from_none" name="_from" value="none"' 
     677        .(!$selected || $selected=='none' ? ' checked="checked"' : '').'></input>'; 
     678    $from .= sprintf('<label for="%s">%s</label> ', 'from_none', Q($this->gettext('none'))); 
     679 
    620680    // filters set list 
    621681    $list = $this->sieve->get_scripts(); 
     
    626686    asort($list, SORT_LOCALE_STRING); 
    627687 
    628     $select->add($this->gettext('none'), ''); 
    629688    foreach($list as $set) 
    630689      $select->add($set . ($set == $active ? ' ('.$this->gettext('active').')' : ''), $set); 
    631690     
    632     $table->add('title', '<label>'.$this->gettext('copyfromset').':</label>'); 
    633     $table->add(null, $select->show($copy)); 
     691    $from .= '<br /><input type="radio" id="from_set" name="_from" value="set"' 
     692        .($selected=='set' ? ' checked="checked"' : '').'></input>'; 
     693    $from .= sprintf('<label for="%s">%s:</label> ', 'from_set', Q($this->gettext('fromset'))); 
     694    $from .= $select->show($copy); 
     695 
     696    // script upload box 
     697    $upload = new html_inputfield(array('name' => '_file', 'id' => '_file', 'size' => 30, 
     698        'type' => 'file', 'class' => ($this->errors['name'] ? 'error' : ''))); 
     699 
     700    $from .= '<br /><input type="radio" id="from_file" name="_from" value="file"' 
     701        .($selected=='file' ? ' checked="checked"' : '').'></input>'; 
     702    $from .= sprintf('<label for="%s">%s:</label> ', 'from_file', Q($this->gettext('fromfile'))); 
     703    $from .= $upload->show(); 
     704    $from .= '</div>'; 
     705 
     706    $table->add('title', '<label>'.$this->gettext('filters').':</label>'); 
     707    $table->add(null, $from); 
    634708 
    635709    $out .= $table->show(); 
  • trunk/plugins/managesieve/skins/default/managesieve.css

    r3422 r3460  
    132132} 
    133133 
     134#filtersetsbuttons a.setget { 
     135  background-position: -224px 0px; 
     136} 
     137 
     138#filtersetsbuttons a.setgetsel { 
     139  background-position: -224px -32px; 
     140} 
     141 
    134142#filtersetselect 
    135143{ 
    136144  position: absolute; 
    137   left: 360px; 
     145  left: 375px; 
    138146  top: 90px; 
    139147} 
     
    272280  float: right; 
    273281} 
     282 
     283div .itemlist 
     284{ 
     285  line-height: 25px; 
     286} 
     287 
     288div .itemlist input 
     289{ 
     290  vertical-align: middle; 
     291} 
  • trunk/plugins/managesieve/skins/default/templates/managesieve.html

    r3376 r3460  
    3333<roundcube:button command="plugin.managesieve-setdel" type="link" class="buttonPas setdel" classSel="button setdelsel" classAct="button setdel" title="managesieve.filtersetdel" content=" " /> 
    3434<roundcube:button command="plugin.managesieve-setact" type="link" class="buttonPas setset" classSel="button setsetsel" classAct="button setset" title="managesieve.filtersetact" content=" " /> 
     35<roundcube:button command="plugin.managesieve-setget" type="link" class="buttonPas setget" classSel="button setgetsel" classAct="button setget" title="managesieve.filtersetget" content=" " /> 
    3536</div> 
    3637<div id="filtersetselect"> 
Note: See TracChangeset for help on using the changeset viewer.