0006222: Keep a copy from mails forwarded to another emailaddress
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 19 Oct 2016 14:00:51 +0000 (14:00 +0000)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 26 Oct 2016 12:41:05 +0000 (14:41 +0200)
https://forge.tine20.org/view.php?id=6222

Change-Id: I8468b038e2d81ff430a075a1fa604a7c17e579da
Reviewed-on: http://gerrit.tine20.com/customers/3669
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Felamimail/Frontend/JsonTest.php
tine20/Felamimail/Sieve/Backend/Abstract.php
tine20/Felamimail/Sieve/Backend/Sql.php
tine20/Felamimail/Sieve/Rule/Action.php
tine20/Felamimail/js/sieve/RuleEditDialog.js
tine20/Felamimail/js/sieve/RulesGridPanel.js

index 190abac..b491d58 100644 (file)
@@ -1320,7 +1320,57 @@ class Felamimail_Frontend_JsonTest extends TestCase
         $ruleData[0]['enabled'] = 0;
         $this->_sieveTestHelper($ruleData);
     }
-    
+
+    /**
+     * @see 0006222: Keep a copy from mails forwarded to another emailaddress
+     */
+    public function testSetForwardRuleWithCopy()
+    {
+        $ruleData = array(array(
+            'id'            => 1,
+            'action_type'   => Felamimail_Sieve_Rule_Action::REDIRECT,
+            'action_argument' => array(
+                'emails' => 'someaccount@example.org',
+                'copy'   => 1,
+            ),
+            'conjunction'     => 'allof',
+            'conditions'    => array(array(
+                'test'          => Felamimail_Sieve_Rule_Condition::TEST_ADDRESS,
+                'comperator'    => Felamimail_Sieve_Rule_Condition::COMPERATOR_CONTAINS,
+                'header'        => 'From',
+                'key'           => 'info@example.org',
+            )),
+            'enabled'       => 1,
+        ));
+
+        $this->_sieveTestHelper($ruleData);
+    }
+
+    /**
+     * @see 0006222: Keep a copy from mails forwarded to another emailaddress
+     */
+    public function testSetForwardRuleWithoutCopy()
+    {
+        $ruleData = array(array(
+            'id'            => 1,
+            'action_type'   => Felamimail_Sieve_Rule_Action::REDIRECT,
+            'action_argument' => array(
+                'emails' => 'someaccount@example.org',
+                'copy'   => 0,
+            ),
+            'conjunction'     => 'allof',
+            'conditions'    => array(array(
+                'test'          => Felamimail_Sieve_Rule_Condition::TEST_ADDRESS,
+                'comperator'    => Felamimail_Sieve_Rule_Condition::COMPERATOR_CONTAINS,
+                'header'        => 'From',
+                'key'           => 'info@example.org',
+            )),
+            'enabled'       => 1,
+        ));
+
+        $this->_sieveTestHelper($ruleData);
+    }
+
     /**
      * testGetVacationTemplates
      *
index a45ccc9..e1b5ec6 100644 (file)
@@ -127,6 +127,7 @@ abstract class Felamimail_Sieve_Backend_Abstract
         if (! empty($this->_rules)) {
             $require[] = '"fileinto"';
             $require[] = '"reject"';
+            $require[] = '"copy"';
             
             foreach ($this->_rules as $rule) {
                 if ($rule->hasRegexCondition()) {
index be80730..96cb5fe 100644 (file)
@@ -94,6 +94,10 @@ class Felamimail_Sieve_Backend_Sql extends Felamimail_Sieve_Backend_Abstract
         $this->_rules = array();
         foreach ($ruleRecords as $ruleRecord) {
             $ruleRecord->conditions = Zend_Json::decode($ruleRecord->conditions);
+            if (Tinebase_Helper::is_json($ruleRecord->action_argument)) {
+                $ruleRecord->action_argument = Zend_Json::decode($ruleRecord->action_argument);
+            }
+
             $this->_rules[] = $ruleRecord->getFSR();
         }
     }
@@ -159,6 +163,9 @@ class Felamimail_Sieve_Backend_Sql extends Felamimail_Sieve_Backend_Abstract
                 $ruleRecord->setFromFSR($rule);
                 $ruleRecord->account_id = $this->_accountId;
                 $ruleRecord->conditions = Zend_Json::encode($ruleRecord->conditions);
+                if (is_array($ruleRecord->action_argument)) {
+                    $ruleRecord->action_argument = Zend_Json::encode($ruleRecord->action_argument);
+                }
                 $this->_rulesBackend->create($ruleRecord);
             }
             
index 469cd69..4f0a4d4 100644 (file)
@@ -6,7 +6,7 @@
  * @subpackage  Sieve
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
  * @author      Lars Kneschke <l.kneschke@metaways.de>
- * @copyright   Copyright (c) 2010 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2010-2016 Metaways Infosystems GmbH (http://www.metaways.de)
  * 
  */
 
@@ -78,7 +78,20 @@ class Felamimail_Sieve_Rule_Action
             case self::DISCARD:
                 return "    $this->_type;";
                 break;
-                
+
+            case self::REDIRECT:
+                if (is_array($this->_argument)) {
+                    if (isset($this->_argument['copy']) && $this->_argument['copy'] == 1) {
+                        $argument = $this->_quoteString($this->_argument['emails']);
+                        return "    $this->_type :copy $argument;";
+                    } else {
+                        $argument = $this->_quoteString($this->_argument['emails']);
+                        return "    $this->_type $argument;";
+                    }
+
+                    break;
+                }
+
             default:
                 $argument = $this->_quoteString($this->_argument);
                 return "    $this->_type $argument;";
index 4c8bd91..5a6fa96 100644 (file)
@@ -76,7 +76,16 @@ Tine.Felamimail.sieve.RuleEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog
             if (this.record.get('action_type') == type) {
                 var field = this.getForm().findField('action_argument_' + type);
                 if (field !== null) {
-                    field.setValue(this.record.get('action_argument'));
+                    switch (type) {
+                        case 'redirect':
+                           var data = this.record.get('action_argument'),
+                               checkbox = this.getForm().findField('action_argument_redirect_copy');
+                           field.setValue(data.emails);
+                           checkbox.setValue(data.copy);
+                           break;
+                        default:
+                           field.setValue(this.record.get('action_argument'));
+                    }
                 }
             }
         }
@@ -111,9 +120,19 @@ Tine.Felamimail.sieve.RuleEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog
         Tine.Felamimail.sieve.RuleEditDialog.superclass.onRecordUpdate.call(this);
         
         this.record.set('conditions', this.getConditions());
-        
-        var argumentField = this.getForm().findField('action_argument_' + this.actionTypeCombo.getValue()),
+
+        var argumentFieldName = 'action_argument_' + this.actionTypeCombo.getValue();
+            argumentField = this.getForm().findField(argumentFieldName),
             argumentValue = (argumentField !== null) ? argumentField.getValue() : '';
+
+        // add additional action arguments
+        if (argumentFieldName === 'action_argument_redirect') {
+            argumentValue = {
+                emails: argumentValue,
+                copy: this.getForm().findField('action_argument_redirect_copy').getValue()
+            };
+        }
+        
         this.record.set('action_argument', argumentValue);
     },
     
@@ -359,6 +378,10 @@ Tine.Felamimail.sieve.RuleEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog
                             emptyText: 'test@example.org',
                             width: 200,
                             hideLabel: true
+                        }, {
+                            name: 'action_argument_redirect_copy',
+                            xtype: 'checkbox',
+                            fieldLabel: this.app.i18n._('Keep a copy')
                         }]
                     }, {
                         id: this.idPrefix + 'reject',
index 4792930..f2c2b96 100644 (file)
@@ -266,16 +266,19 @@ Tine.Felamimail.sieve.RulesGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
      */
     actionRenderer: function(type, metadata, record) {
         var types = Tine.Felamimail.sieve.RuleEditDialog.getActionTypes(this.app),
-            result = type;
-        
+            result = type,
+            action_argument = record.get('action_argument');
+
         for (i=0; i < types.length; i++) {
             if (types[i][0] == type) {
                 result = types[i][1];
             }
         }
         
-        if (record.get('action_argument') && record.get('action_argument') != '') {
-            result += ' ' + record.get('action_argument');
+        if (action_argument && action_argument != '') {
+            result += Ext.isObject(action_argument)
+                ? ': '  + action_argument.emails + (action_argument.copy ? ' (' + this.app.i18n._('Keep a copy') + ')' : '')
+                : action_argument;
         }
             
         return Ext.util.Format.htmlEncode(result);