From ebb204793b976482ce7d729b3c7e9e1069b9e56e Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 23 Jul 2012 04:24:16 -0400
Subject: [PATCH] Added GUI for variables setting - RFC5229 (patch from Paweł Słowik)

---
 plugins/managesieve/localization/pl_PL.inc |    4 ++
 plugins/managesieve/localization/en_GB.inc |    4 ++
 plugins/managesieve/Changelog              |    2 +
 plugins/managesieve/localization/en_US.inc |    4 ++
 plugins/managesieve/managesieve.js         |    6 ++
 plugins/managesieve/managesieve.php        |   47 +++++++++++++++++++++++
 6 files changed, 66 insertions(+), 1 deletions(-)

diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog
index 64542c6..91c36cf 100644
--- a/plugins/managesieve/Changelog
+++ b/plugins/managesieve/Changelog
@@ -1,3 +1,5 @@
+- Added GUI for variables setting - RFC5229 (patch from Paweł Słowik)
+
 * version 5.1 [2012-06-21]
 -----------------------------------------------------------
 - Fixed filter popup width (for non-english localizations)
diff --git a/plugins/managesieve/localization/en_GB.inc b/plugins/managesieve/localization/en_GB.inc
index 5e1c83a..6859f5f 100644
--- a/plugins/managesieve/localization/en_GB.inc
+++ b/plugins/managesieve/localization/en_GB.inc
@@ -93,6 +93,10 @@
 $labels['flaganswered'] = 'Answered';
 $labels['flagflagged'] = 'Flagged';
 $labels['flagdraft'] = 'Draft';
+$labels['setvariable'] = 'Set variable';
+$labels['setvarname'] = 'Variable name:';
+$labels['setvarvalue'] = 'Variable value:';
+$labels['setvarmodifiers'] = 'Modifiers:';
 $labels['filtercreate'] = 'Create filter';
 $labels['usedata'] = 'Use following data in the filter:';
 $labels['nextstep'] = 'Next Step';
diff --git a/plugins/managesieve/localization/en_US.inc b/plugins/managesieve/localization/en_US.inc
index 5aea5dc..80d04e6 100644
--- a/plugins/managesieve/localization/en_US.inc
+++ b/plugins/managesieve/localization/en_US.inc
@@ -78,6 +78,10 @@
 $labels['flaganswered'] = 'Answered';
 $labels['flagflagged'] = 'Flagged';
 $labels['flagdraft'] = 'Draft';
+$labels['setvariable'] = 'Set variable';
+$labels['setvarname'] = 'Variable name:';
+$labels['setvarvalue'] = 'Variable value:';
+$labels['setvarmodifiers'] = 'Modifiers:';
 $labels['filtercreate'] = 'Create filter';
 $labels['usedata'] = 'Use following data in the filter:';
 $labels['nextstep'] = 'Next Step';
diff --git a/plugins/managesieve/localization/pl_PL.inc b/plugins/managesieve/localization/pl_PL.inc
index a4a1aea..06d4d11 100644
--- a/plugins/managesieve/localization/pl_PL.inc
+++ b/plugins/managesieve/localization/pl_PL.inc
@@ -93,6 +93,10 @@
 $labels['flaganswered'] = 'Z odpowiedzią';
 $labels['flagflagged'] = 'Oflagowana';
 $labels['flagdraft'] = 'Szkic';
+$labels['setvariable'] = 'Ustaw zmienną';
+$labels['setvarname'] = 'Nazwa zmiennej:';
+$labels['setvarvalue'] = 'Wartość zmiennej:';
+$labels['setvarmodifiers'] = 'Modyfikatory:';
 $labels['filtercreate'] = 'Utwórz filtr';
 $labels['usedata'] = 'Użyj następujących danych do utworzenia filtra:';
 $labels['nextstep'] = 'Następny krok';
diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js
index 61883f6..f447719 100644
--- a/plugins/managesieve/managesieve.js
+++ b/plugins/managesieve/managesieve.js
@@ -638,7 +638,8 @@
       target: document.getElementById('action_target' + id),
       target_area: document.getElementById('action_target_area' + id),
       flags: document.getElementById('action_flags' + id),
-      vacation: document.getElementById('action_vacation' + id)
+      vacation: document.getElementById('action_vacation' + id),
+      set: document.getElementById('action_set' + id)
     };
 
   if (obj.value == 'fileinto' || obj.value == 'fileinto_copy') {
@@ -656,6 +657,9 @@
   else if (obj.value == 'vacation') {
     enabled.vacation = 1;
   }
+  else if (obj.value == 'set') {
+    enabled.set = 1;
+  }
 
   for (var x in elems) {
     elems[x].style.display = !enabled[x] ? 'none' : 'inline';
diff --git a/plugins/managesieve/managesieve.php b/plugins/managesieve/managesieve.php
index 70ef5f5..7f591f5 100644
--- a/plugins/managesieve/managesieve.php
+++ b/plugins/managesieve/managesieve.php
@@ -615,6 +615,9 @@
             $days           = get_input_value('_action_days', RCUBE_INPUT_POST);
             $subject        = get_input_value('_action_subject', RCUBE_INPUT_POST, true);
             $flags          = get_input_value('_action_flags', RCUBE_INPUT_POST);
+            $varnames       = get_input_value('_action_varname', RCUBE_INPUT_POST);
+            $varvalues      = get_input_value('_action_varvalue', RCUBE_INPUT_POST);
+            $varmods        = get_input_value('_action_varmods', RCUBE_INPUT_POST);
 
             // we need a "hack" for radiobuttons
             foreach ($sizeitems as $item)
@@ -848,6 +851,20 @@
                         $this->errors['actions'][$i]['reason'] = $this->gettext('cannotbeempty');
                     if ($this->form['actions'][$i]['days'] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i]['days']))
                         $this->errors['actions'][$i]['days'] = $this->gettext('forbiddenchars');
+                    break;
+
+                case 'set':
+                    if (empty($varnames[$idx])) {
+                        $this->errors['actions'][$i]['name'] = $this->gettext('cannotbeempty');
+                    }
+                    if (empty($varvalues[$idx])) {
+                        $this->errors['actions'][$i]['value'] = $this->gettext('cannotbeempty');
+                    }
+                    foreach ($varmods[$idx] as $v_m) {
+                        $this->form['actions'][$i][$v_m] = true;
+                    }
+                    $this->form['actions'][$i]['name'] = $varnames[$idx];
+                    $this->form['actions'][$i]['value'] = $varvalues[$idx];
                     break;
                 }
 
@@ -1447,6 +1464,9 @@
             $select_action->add(Q($this->gettext('addflags')), 'addflag');
             $select_action->add(Q($this->gettext('removeflags')), 'removeflag');
         }
+        if (in_array('variables', $this->exts)) {
+            $select_action->add(Q($this->gettext('setvariable')), 'set');
+        }
         $select_action->add(Q($this->gettext('rulestop')), 'stop');
 
         $select_type = $action['type'];
@@ -1510,6 +1530,33 @@
         }
         $out .= '</div>';
 
+        // set variable
+        $set_modifiers = array(
+            'lower',
+            'upper',
+            'lowerfirst',
+            'upperfirst',
+            'quotewildcard',
+            'length'
+        );
+
+        $out .= '<div id="action_set' .$id.'" style="display:' .($action['type']=='set' ? 'inline' : 'none') .'">';
+        $out .= '<span class="label">' .Q($this->gettext('setvarname')) . '</span><br />'
+            .'<input type="text" name="_action_varname['.$id.']" id="action_varname'.$id.'" '
+            .'value="' . Q($action['name']) . '" size="35" '
+            . $this->error_class($id, 'action', 'name', 'action_varname') .' />';
+        $out .= '<br /><span class="label">' .Q($this->gettext('setvarvalue')) . '</span><br />'
+            .'<input type="text" name="_action_varvalue['.$id.']" id="action_varvalue'.$id.'" '
+            .'value="' . Q($action['value']) . '" size="35" '
+            . $this->error_class($id, 'action', 'value', 'action_varvalue') .' />';
+        $out .= '<br /><span class="label">' .Q($this->gettext('setvarmodifiers')) . '</span><br />';
+        foreach ($set_modifiers as $j => $s_m) {
+            $s_m_id = 'action_varmods' . $id . $s_m;
+            $out .= sprintf('<input type="checkbox" name="_action_varmods[%s][]" value="%s" id="%s"%s />%s<br>',
+                $id, $s_m, $s_m_id, (array_key_exists($s_m, (array)$action) && $action[$s_m] ? ' checked="checked"' : ''), $s_m);
+        }
+        $out .= '</div>';
+
         // mailbox select
         if ($action['type'] == 'fileinto')
             $mailbox = $this->mod_mailbox($action['target'], 'out');

--
Gitblit v1.9.1