Changeset 5155 in subversion


Ignore:
Timestamp:
Sep 4, 2011 2:44:18 AM (22 months ago)
Author:
alec
Message:
  • Added possibility to create a filter based on selected message "in-place"
Location:
trunk/plugins/managesieve
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/managesieve/Changelog

    r4983 r5155  
     1- Added possibility to create a filter based on selected message "in-place" 
     2 
    13* version 4.3 [2011-07-28] 
    24----------------------------------------------------------- 
  • trunk/plugins/managesieve/localization/en_US.inc

    r4523 r5155  
    7878$labels['flagflagged'] = 'Flagged'; 
    7979$labels['flagdraft'] = 'Draft'; 
     80$labels['filtercreate'] = 'Create filter'; 
     81$labels['usedata'] = 'Use following data in the filter:'; 
     82$labels['nextstep'] = 'Next Step'; 
    8083 
    8184$messages = array(); 
     
    101104$messages['setcreated'] = 'Filters set created successfully'; 
    102105$messages['emptyname'] = 'Unable to create filters set. Empty set name'; 
    103 $messages['nametoolong'] = 'Unable to create filters set. Name too long' 
     106$messages['nametoolong'] = 'Unable to create filters set. Name too long'; 
     107$messages['nodata'] = 'At least one position must be selected!'; 
    104108 
    105109?> 
  • trunk/plugins/managesieve/localization/pl_PL.inc

    r4629 r5155  
    9292$labels['flagflagged'] = 'Oflagowana'; 
    9393$labels['flagdraft'] = 'Szkic'; 
     94$labels['filtercreate'] = 'UtwóŌ filtr'; 
     95$labels['usedata'] = 'UÅŒyj następujÄ 
     96cych danych do utworzenia filtra:'; 
     97$labels['nextstep'] = 'Następny krok'; 
    9498 
    9599$messages = array(); 
     
    135139$messages['emptyname'] = 'Nie moÅŒna utworzyć zbioru filtrów. Pusta nazwa zbioru'; 
    136140$messages['nametoolong'] = 'Nie moÅŒna utworzyć zbioru filtrów. Nazwa zbyt długa' 
     141$messages['nodata'] = 'NaleÅŒy wybrać co najmniej jednÄ 
     142 pozycję!'; 
    137143 
    138144?> 
  • trunk/plugins/managesieve/managesieve.js

    r4865 r5155  
    1 /* Sieve Filters (tab) */ 
     1/* (Manage)Sieve Filters */ 
    22 
    33if (window.rcmail) { 
    44  rcmail.addEventListener('init', function(evt) { 
    5  
    6     var tab = $('<span>').attr('id', 'settingstabpluginmanagesieve').addClass('tablink'); 
    7     var button = $('<a>').attr('href', rcmail.env.comm_path+'&_action=plugin.managesieve') 
    8       .attr('title', rcmail.gettext('managesieve.managefilters')) 
    9       .html(rcmail.gettext('managesieve.filters')) 
    10       .appendTo(tab); 
    11  
    12     // add button and register commands 
    13     rcmail.add_element(tab, 'tabs'); 
    14     rcmail.register_command('plugin.managesieve-save', function() { rcmail.managesieve_save() }, true); 
    15     rcmail.register_command('plugin.managesieve-add', function() { rcmail.managesieve_add() }, true); 
    16     rcmail.register_command('plugin.managesieve-del', function() { rcmail.managesieve_del() }, true); 
    17     rcmail.register_command('plugin.managesieve-up', function() { rcmail.managesieve_up() }, true); 
    18     rcmail.register_command('plugin.managesieve-down', function() { rcmail.managesieve_down() }, true); 
    19     rcmail.register_command('plugin.managesieve-set', function() { rcmail.managesieve_set() }, true); 
    20     rcmail.register_command('plugin.managesieve-setadd', function() { rcmail.managesieve_setadd() }, true); 
    21     rcmail.register_command('plugin.managesieve-setdel', function() { rcmail.managesieve_setdel() }, true); 
    22     rcmail.register_command('plugin.managesieve-setact', function() { rcmail.managesieve_setact() }, true); 
    23     rcmail.register_command('plugin.managesieve-setget', function() { rcmail.managesieve_setget() }, true); 
    24  
    25     if (rcmail.env.action == 'plugin.managesieve') { 
    26       if (rcmail.gui_objects.sieveform) { 
    27         rcmail.enable_command('plugin.managesieve-save', true); 
    28       } 
    29       else { 
    30         rcmail.enable_command('plugin.managesieve-del', 'plugin.managesieve-up', 
    31           'plugin.managesieve-down', false); 
    32         rcmail.enable_command('plugin.managesieve-add', 'plugin.managesieve-setadd', !rcmail.env.sieveconnerror); 
    33       } 
    34  
     5    // add managesieve-create command to message_commands array, 
     6    // so it's state will be updated on message selection/unselection 
     7    if (rcmail.env.task == 'mail') { 
     8      if (rcmail.env.action != 'show') 
     9        rcmail.env.message_commands.push('managesieve-create'); 
     10      else 
     11        rcmail.enable_command('managesieve-create', true); 
     12    } 
     13    else { 
     14      var tab = $('<span>').attr('id', 'settingstabpluginmanagesieve').addClass('tablink'), 
     15        button = $('<a>').attr('href', rcmail.env.comm_path+'&_action=plugin.managesieve') 
     16          .attr('title', rcmail.gettext('managesieve.managefilters')) 
     17          .html(rcmail.gettext('managesieve.filters')) 
     18          .appendTo(tab); 
     19 
     20      // add tab 
     21      rcmail.add_element(tab, 'tabs'); 
     22    } 
     23 
     24    if (rcmail.env.task == 'mail' || rcmail.env.action.indexOf('plugin.managesieve') != -1) { 
    3525      // Create layer for form tips 
    3626      if (!rcmail.env.framed) { 
    3727        rcmail.env.ms_tip_layer = $('<div id="managesieve-tip" class="popupmenu"></div>'); 
    3828        rcmail.env.ms_tip_layer.appendTo(document.body); 
     29      } 
     30    } 
     31 
     32    // register commands 
     33    rcmail.register_command('plugin.managesieve-save', function() { rcmail.managesieve_save() }); 
     34    rcmail.register_command('plugin.managesieve-add', function() { rcmail.managesieve_add() }); 
     35    rcmail.register_command('plugin.managesieve-del', function() { rcmail.managesieve_del() }); 
     36    rcmail.register_command('plugin.managesieve-up', function() { rcmail.managesieve_up() }); 
     37    rcmail.register_command('plugin.managesieve-down', function() { rcmail.managesieve_down() }); 
     38    rcmail.register_command('plugin.managesieve-set', function() { rcmail.managesieve_set() }); 
     39    rcmail.register_command('plugin.managesieve-setadd', function() { rcmail.managesieve_setadd() }); 
     40    rcmail.register_command('plugin.managesieve-setdel', function() { rcmail.managesieve_setdel() }); 
     41    rcmail.register_command('plugin.managesieve-setact', function() { rcmail.managesieve_setact() }); 
     42    rcmail.register_command('plugin.managesieve-setget', function() { rcmail.managesieve_setget() }); 
     43 
     44    if (rcmail.env.action == 'plugin.managesieve' || rcmail.env.action == 'plugin.managesieve-save') { 
     45      if (rcmail.gui_objects.sieveform) { 
     46        rcmail.enable_command('plugin.managesieve-save', true); 
     47        // resize dialog window 
     48        if (rcmail.env.action == 'plugin.managesieve' && rcmail.env.task == 'mail') { 
     49          parent.rcmail.managesieve_dialog_resize(rcmail.gui_objects.sieveform); 
     50        } 
     51        $('input[type="text"]:first', rcmail.gui_objects.sieveform).focus(); 
     52      } 
     53      else { 
     54        rcmail.enable_command('plugin.managesieve-add', 'plugin.managesieve-setadd', !rcmail.env.sieveconnerror); 
    3955      } 
    4056 
     
    480496rcube_webmail.prototype.managesieve_tip_register = function(tips) 
    481497{ 
     498  var n, framed = parent.rcmail, 
     499    tip = framed ? parent.rcmail.env.ms_tip_layer : rcmail.env.ms_tip_layer; 
     500 
    482501  for (var n in tips) { 
    483502    $('#'+tips[n][0]) 
     
    485504        function(e) { 
    486505          var offset = $(this).offset(), 
    487             tip = rcmail.env.framed ? parent.rcmail.env.ms_tip_layer : rcmail.env.ms_tip_layer, 
    488506            left = offset.left, 
    489507            top = offset.top - 12; 
    490508 
    491           if (rcmail.env.framed) { 
    492             offset = $(parent.document.getElementById('filter-box')).offset(); 
     509          if (framed) { 
     510            offset = $((rcmail.env.task == 'mail'  ? '#sievefilterform > iframe' : '#filter-box'), parent.document).offset(); 
    493511            top  += offset.top; 
    494512            left += offset.left; 
     
    500518          tip.css({left: left, top: top}).show(); 
    501519        }) 
    502       .bind('mouseleave', 
    503         function(e) { 
    504           var tip = parent.rcmail && parent.rcmail.env.ms_tip_layer ?  
    505             parent.rcmail.env.ms_tip_layer : rcmail.env.ms_tip_layer; 
    506           tip.hide(); 
    507       }); 
     520      .bind('mouseleave', function(e) { tip.hide(); }); 
    508521  } 
    509522}; 
     
    580593  } 
    581594}; 
     595 
     596/*********************************************************/ 
     597/*********           Mail UI methods             *********/ 
     598/*********************************************************/ 
     599 
     600rcube_webmail.prototype.managesieve_create = function() 
     601{ 
     602  if (!rcmail.env.sieve_headers || !rcmail.env.sieve_headers.length) 
     603    return; 
     604 
     605  var i, html, buttons = {}, dialog = $("#sievefilterform"); 
     606 
     607  // create dialog window 
     608  if (!dialog.length) { 
     609    dialog = $('<div id="sievefilterform"></div>'); 
     610    $('body').append(dialog); 
     611  } 
     612 
     613  // build dialog window content 
     614  html = '<fieldset><legend>'+this.gettext('managesieve.usedata')+'</legend><ul>'; 
     615  for (i in rcmail.env.sieve_headers) 
     616    html += '<li><input type="checkbox" name="headers[]" id="sievehdr'+i+'" value="'+i+'" checked="checked" />' 
     617      +'<label for="sievehdr'+i+'">'+rcmail.env.sieve_headers[i][0]+':</label> '+rcmail.env.sieve_headers[i][1]+'</li>'; 
     618  html += '</ul></fieldset>'; 
     619 
     620  dialog.html(html); 
     621 
     622  // [Next Step] button action 
     623  buttons[this.gettext('managesieve.nextstep')] = function () { 
     624    // check if there's at least one checkbox checked 
     625    var hdrs = $('input[name="headers[]"]:checked', dialog); 
     626    if (!hdrs.length) { 
     627      alert(rcmail.gettext('managesieve.nodata')); 
     628      return; 
     629    } 
     630 
     631    // build frame URL 
     632    var url = rcmail.get_task_url('mail'); 
     633    url = rcmail.add_url(url, '_action', 'plugin.managesieve'); 
     634    url = rcmail.add_url(url, '_framed', 1); 
     635 
     636    hdrs.map(function() { 
     637      var val = rcmail.env.sieve_headers[this.value]; 
     638      url = rcmail.add_url(url, 'r['+this.value+']', val[0]+':'+val[1]); 
     639    }); 
     640 
     641    // load form in the iframe 
     642    var frame = $('<iframe>').attr({src: url, frameborder: 0}) 
     643    frame.height(dialog.height()); // temp.  
     644    dialog.empty().append(frame); 
     645    dialog.dialog('dialog').resize(); 
     646 
     647    // Change [Next Step] button with [Save] button 
     648    buttons = {}; 
     649    buttons[rcmail.gettext('save')] = function() {   
     650      var win = $('iframe', dialog).get(0).contentWindow; 
     651      win.rcmail.managesieve_save(); 
     652    }; 
     653    dialog.dialog('option', 'buttons', buttons); 
     654  }; 
     655 
     656  // show dialog window 
     657  dialog.dialog({ 
     658    modal: false, 
     659    resizable: !bw.ie6, 
     660    closeOnEscape: (!bw.ie6 && !bw.ie7),  // disable for performance reasons 
     661    title: this.gettext('managesieve.newfilter'), 
     662    close: function() { rcmail.managesieve_dialog_close(); }, 
     663    buttons: buttons, 
     664    minWidth: 600, 
     665    minHeight: 300 
     666  }).show(); 
     667 
     668  this.env.managesieve_dialog = dialog; 
     669} 
     670 
     671rcube_webmail.prototype.managesieve_dialog_close = function() 
     672{ 
     673  var dialog = this.env.managesieve_dialog; 
     674   
     675  // BUG(?): if we don't remove the iframe first, it will be reloaded 
     676  dialog.html(''); 
     677  dialog.dialog('destroy').hide(); 
     678} 
     679 
     680rcube_webmail.prototype.managesieve_dialog_resize = function(o) 
     681{ 
     682  var dialog = this.env.managesieve_dialog, 
     683    win = $(window), form = $(o); 
     684    width = form.width(), height = form.height(), 
     685    w = win.width(), h = win.height(); 
     686 
     687  dialog.dialog('option', { height: Math.min(h-20, height+120), width: Math.min(w-20, width+65) }) 
     688    .dialog('option', 'position', ['center', 'center']);  // only works in a separate call (!?) 
     689} 
  • trunk/plugins/managesieve/managesieve.php

    r4983 r5155  
    1414 * 
    1515 * Copyright (C) 2008-2011, The Roundcube Dev Team 
     16 * Copyright (C) 2011, Kolab Systems AG 
    1617 * 
    1718 * This program is free software; you can redistribute it and/or modify 
     
    3334class managesieve extends rcube_plugin 
    3435{ 
    35     public $task = 'settings'; 
     36    public $task = 'mail|settings'; 
    3637 
    3738    private $rc; 
     
    5152    function init() 
    5253    { 
    53         // add Tab label/title 
    54         $this->add_texts('localization/', array('filters','managefilters')); 
     54        $this->rc = rcmail::get_instance(); 
    5555 
    5656        // register actions 
     
    5858        $this->register_action('plugin.managesieve-save', array($this, 'managesieve_save')); 
    5959 
     60        if ($this->rc->task == 'settings') { 
     61            // load localization 
     62            $this->add_texts('localization/', array('filters','managefilters')); 
     63 
     64            $this->include_script('managesieve.js'); 
     65        } 
     66        else if ($this->rc->task == 'mail') { 
     67            // register message hook 
     68            $this->add_hook('message_headers_output', array($this, 'mail_headers')); 
     69 
     70            // inject Create Filter popup stuff 
     71            if (empty($this->rc->action) || $this->rc->action == 'show') { 
     72                $this->mail_task_handler(); 
     73            } 
     74        } 
     75    } 
     76 
     77    /** 
     78     * Add UI elements to the 'mailbox view' and 'show message' UI. 
     79     */ 
     80    function mail_task_handler() 
     81    { 
     82        // load localization 
     83        $this->add_texts('localization/'); 
     84 
     85        // use jQuery for popup window 
     86        $this->require_plugin('jqueryui');  
     87 
    6088        // include main js script 
    6189        $this->include_script('managesieve.js'); 
    62     } 
    63  
     90 
     91        // include styles 
     92        $skin = $this->rc->config->get('skin'); 
     93        if (!file_exists($this->home."/skins/$skin/managesieve_mail.css")) 
     94            $skin = 'default'; 
     95        $this->include_stylesheet("skins/$skin/managesieve_mail.css"); 
     96 
     97        // add 'Create filter' item to message menu 
     98        $this->api->add_content(html::tag('li', null,  
     99            $this->api->output->button(array( 
     100                'command'  => 'managesieve-create', 
     101                'label'    => 'managesieve.filtercreate', 
     102                'type'     => 'link', 
     103                'classact' => 'filterlink active', 
     104                'class'    => 'filterlink', 
     105            ))), 'messagemenu'); 
     106 
     107        // register some labels/messages 
     108        $this->rc->output->add_label('managesieve.newfilter', 'managesieve.usedata', 
     109            'managesieve.nodata', 'managesieve.nextstep', 'save'); 
     110    } 
     111 
     112    /** 
     113     * Get message headers for popup window 
     114     */ 
     115    function mail_headers($args) 
     116    { 
     117        $headers = $args['headers']; 
     118        $ret     = array(); 
     119 
     120        if ($headers->subject) 
     121            $ret[] = array('Subject', $headers->subject); 
     122 
     123        // @TODO: List-Id, others? 
     124        foreach (array('From', 'To') as $h) { 
     125            $hl = strtolower($h); 
     126            if ($headers->$hl) { 
     127                $list = $this->rc->imap->decode_address_list($headers->$hl); 
     128                foreach ($list as $item) { 
     129                    if ($item['mailto']) { 
     130                        $ret[] = array($h, $item['mailto']); 
     131                    } 
     132                } 
     133            } 
     134        } 
     135 
     136        if ($this->rc->action == 'preview') 
     137            $this->rc->output->command('parent.set_env', array('sieve_headers' => $ret)); 
     138        else 
     139            $this->rc->output->set_env('sieve_headers', $ret); 
     140 
     141 
     142        return $args; 
     143    } 
     144 
     145    /** 
     146     * Loads configuration, initializes plugin (including sieve connection) 
     147     */ 
    64148    function managesieve_start() 
    65149    { 
    66         $this->rc = rcmail::get_instance(); 
    67150        $this->load_config(); 
    68151 
     
    170253    function managesieve_actions() 
    171254    { 
     255        // load localization 
     256        $this->add_texts('localization/', array('filters','managefilters')); 
     257 
     258        // include main js script 
     259        if ($this->api->output->type == 'html') { 
     260            $this->include_script('managesieve.js'); 
     261        } 
     262 
    172263        // Init plugin and handle managesieve connection 
    173264        $error = $this->managesieve_start(); 
     
    299390            $this->rc->output->send(); 
    300391        } 
     392        else if ($this->rc->task == 'mail') { 
     393            // Initialize the form 
     394            $rules = get_input_value('r', RCUBE_INPUT_GET); 
     395            if (!empty($rules)) { 
     396                $i = 0; 
     397                foreach ($rules as $rule) { 
     398                    list($header, $value) = explode(':', $rule, 2); 
     399                    $tests[$i] = array( 
     400                        'type' => 'contains', 
     401                        'test' => 'header', 
     402                        'arg1' => $header, 
     403                        'arg2' => $value, 
     404                    ); 
     405                    $i++; 
     406                } 
     407 
     408                $this->form = array( 
     409                    'join'  => count($tests) > 1 ? 'allof' : 'anyof', 
     410                    'name'  => '', 
     411                    'tests' => $tests, 
     412                    'actions' => array( 
     413                        0 => array('type' => 'fileinto'), 
     414                        1 => array('type' => 'stop'), 
     415                    ), 
     416                ); 
     417            } 
     418        } 
    301419 
    302420        $this->managesieve_send(); 
     
    305423    function managesieve_save() 
    306424    { 
     425        // load localization 
     426        $this->add_texts('localization/', array('filters','managefilters')); 
     427 
     428        // include main js script 
     429        if ($this->api->output->type == 'html') { 
     430            $this->include_script('managesieve.js'); 
     431        } 
     432 
    307433        // Init plugin and handle managesieve connection 
    308434        $error = $this->managesieve_start(); 
     
    597723                if ($save && $fid !== false) { 
    598724                    $this->rc->output->show_message('managesieve.filtersaved', 'confirmation'); 
    599                     $this->rc->output->add_script( 
    600                         sprintf("rcmail.managesieve_updatelist('%s', '%s', %d, %d);", 
    601                             isset($new) ? 'add' : 'update', Q($this->form['name']), 
    602                             $fid, $this->form['disabled']), 
    603                         'foot'); 
     725                    if ($this->rc->task != 'mail') { 
     726                        $this->rc->output->add_script( 
     727                            sprintf("rcmail.managesieve_updatelist('%s', '%s', %d, %d);", 
     728                                isset($new) ? 'add' : 'update', Q($this->form['name']), 
     729                                $fid, $this->form['disabled']), 
     730                            'foot'); 
     731                    } 
     732                    else { 
     733                        $this->rc->output->command('managesieve_dialog_close'); 
     734                        $this->rc->output->send('iframe'); 
     735                    } 
    604736                } 
    605737                else { 
  • trunk/plugins/managesieve/skins/default/managesieve.css

    r4241 r5155  
    1 /***** Roundcube|Filters styles *****/ 
    2  
    3  
    41#filterslist 
    52{ 
     
    169166  min-width: 740px; 
    170167  width: expression(Math.max(740, document.documentElement.clientWidth)+'px'); 
     168  background-color: #F2F2F2; 
    171169} 
    172170 
     
    295293  width: 200px; 
    296294} 
     295 
     296/* fixes for popup window */ 
     297 
     298body.iframe.mail 
     299{ 
     300  margin: 0; 
     301  padding: 0; 
     302} 
     303 
     304body.iframe.mail #filter-form 
     305{ 
     306  padding: 10px 5px 5px 5px; 
     307} 
  • trunk/plugins/managesieve/skins/default/templates/filteredit.html

    r4525 r5155  
    66<link rel="stylesheet" type="text/css" href="/this/managesieve.css" /> 
    77</head> 
    8 <body class="iframe"> 
     8<body class="iframe<roundcube:exp expression="env:task != 'mail' ? '' : ' mail'" />"> 
    99 
     10<roundcube:if condition="env:task != 'mail'" /> 
    1011<div id="filter-title" class="boxtitle"><roundcube:label name="managesieve.filterdef" /></div> 
     12<roundcube:endif /> 
    1113 
    1214<div id="filter-form" class="boxcontent"> 
    1315<roundcube:object name="filterform" /> 
    1416 
     17<roundcube:if condition="env:task != 'mail'" /> 
    1518<div id="footer"> 
    1619<div class="footerleft"> 
     
    2225</div> 
    2326</div> 
     27<roundcube:endif /> 
    2428 
    2529</form> 
    2630</div> 
    2731 
    28  
    2932</body> 
    3033</html> 
Note: See TracChangeset for help on using the changeset viewer.