From ecd7f3d7d8b0e77b31b21ce92d6a8f38d8204a7b Mon Sep 17 00:00:00 2001
From: thom <thom@amsterdamtech.nl>
Date: Sat, 18 Jul 2020 14:32:40 +0200
Subject: [PATCH] Allow separator in catchall email adress (#4999)

---
 interface/lib/classes/tform_base.inc.php      | 55 +++++++++++++------
 .../mail/form/mail_domain_catchall.tform.php  |  2 +-
 2 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/interface/lib/classes/tform_base.inc.php b/interface/lib/classes/tform_base.inc.php
index e6174d2da7..a28644e3ef 100644
--- a/interface/lib/classes/tform_base.inc.php
+++ b/interface/lib/classes/tform_base.inc.php
@@ -152,9 +152,9 @@ class tform_base {
 			$wb = $app->functions->array_merge($wb_global, $wb);
 		}
 		if(isset($wb_global)) unset($wb_global);
-		
+
 		$this->wordbook = $wb;
-		
+
 		$app->plugin->raiseEvent($_SESSION['s']['module']['name'].':'.$app->tform->formDef['name'] . ':on_after_formdef', $this);
 
 		$this->dateformat = $app->lng('conf_format_dateshort');
@@ -323,7 +323,7 @@ class tform_base {
 		return $this->getAuthSQL('r', $matches[1]);
 	}
 	*/
-	
+
 	/**
 	 * Get the key => value array of a form filled from a datasource definitiom
 	 *
@@ -339,12 +339,12 @@ class tform_base {
 	function applyValueLimit($limit, $values, $current_value = '') {
 
 		global $app;
-		
+
 		// we mas have multiple limits, therefore we explode by ; first
 		// Example: "system:sites:web_php_options;client:web_php_options"
 		$limits = explode(';',$limit);
-		
-		
+
+
 		foreach($limits as $limit) {
 
 			$limit_parts = explode(':', $limit);
@@ -399,7 +399,7 @@ class tform_base {
 				$tmp_key = $limit_parts[2];
 				$allowed = $allowed = explode(',',$tmp_conf[$tmp_key]);
 			}
-			
+
 			// add the current value to the allowed array
 			$allowed[] = $current_value;
 
@@ -438,7 +438,7 @@ class tform_base {
 		$csrf_token = $app->auth->csrf_token_get($this->formDef['name']);
 		$_csrf_id = $csrf_token['csrf_id'];
 		$_csrf_value = $csrf_token['csrf_key'];
-		
+
 		$this->formDef['tabs'][$tab]['fields']['_csrf_id'] = array(
 			'datatype' => 'VARCHAR',
 			'formtype' => 'TEXT',
@@ -454,7 +454,7 @@ class tform_base {
 		$record['_csrf_id'] = $_csrf_id;
 		$record['_csrf_key'] = $_csrf_value;
 		/* CSRF PROTECTION */
-		
+
 		$new_record = array();
 		if($action == 'EDIT') {
 			$record = $this->decode($record, $tab);
@@ -589,7 +589,7 @@ class tform_base {
 
 						$new_record[$key] = $this->_getDateHTML($key, $dt_value);
 						break;
-					
+
 					default:
 						if(isset($record[$key])) {
 							$new_record[$key] = $app->functions->htmlentities($record[$key]);
@@ -701,7 +701,7 @@ class tform_base {
 
 					$new_record[$key] = $this->_getDateTimeHTML($key, $dt_value, $display_seconds);
 					break;
-				
+
 				case 'DATE':
 					$dt_value = (isset($field['default'])) ? $field['default'] : 0;
 
@@ -750,7 +750,7 @@ class tform_base {
 					unset($_POST);
 					unset($record);
 				}
-				
+
 				if(isset($_SESSION['_csrf_timeout']) && is_array($_SESSION['_csrf_timeout'])) {
 					$to_unset = array();
 					foreach($_SESSION['_csrf_timeout'] as $_csrf_id => $timeout) {
@@ -767,7 +767,7 @@ class tform_base {
 			}
 			/* CSRF PROTECTION */
 		}
-		
+
 		$new_record = array();
 		if(is_array($record)) {
 			foreach($fields as $key => $field) {
@@ -1065,6 +1065,29 @@ class tform_base {
 				}
 				unset($error);
 				break;
+			case 'ISEMAILADRESS':
+				$error = false;
+				if($validator['allowempty'] != 'y') $validator['allowempty'] = 'n';
+				if($validator['allowempty'] == 'y' && $field_value == '') {
+					//* Do nothing
+				} else {
+					if(function_exists('filter_var')) {
+						if(filter_var($field_value, FILTER_VALIDATE_EMAIL) === false) {
+							$error = true;
+						}
+						if ($error) {
+							$errmsg = $validator['errmsg'];
+							if(isset($this->wordbook[$errmsg])) {
+								$this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n";
+							} else {
+								$this->errorMessage .= $errmsg."<br />\r\n";
+							}
+						}
+
+					} else $this->errorMessage .= "function filter_var missing <br />\r\n";
+				}
+				unset($error);
+				break;
 			case 'ISINT':
 				if(function_exists('filter_var') && $field_value < PHP_INT_MAX) {
 					//if($field_value != '' && filter_var($field_value, FILTER_VALIDATE_INT, array("options" => array('min_range'=>0))) === false) {
@@ -1198,7 +1221,7 @@ class tform_base {
 					}
 				}
 				break;
-			
+
 			case 'ISDATETIME':
 				/* Checks a datetime value against the date format of the current language */
 				if($validator['allowempty'] != 'y') $validator['allowempty'] = 'n';
@@ -1216,7 +1239,7 @@ class tform_base {
 					}
 				}
 				break;
-			
+
 			case 'RANGE':
 				//* Checks if the value is within the given range or above / below a value
 				//* Range examples: < 10 = ":10", between 2 and 10 = "2:10", above 5 = "5:".
@@ -1281,7 +1304,7 @@ class tform_base {
 		$sql_update = '';
 
 		$record = $this->encode($record, $tab, true);
-		
+
 		if(($this->primary_id_override > 0)) {
 			$sql_insert_key .= '`'.$this->formDef["db_table_idx"].'`, ';
 			$sql_insert_val .= $this->primary_id_override.", ";
diff --git a/interface/web/mail/form/mail_domain_catchall.tform.php b/interface/web/mail/form/mail_domain_catchall.tform.php
index 72261e05e0..ebc4cebd7c 100644
--- a/interface/web/mail/form/mail_domain_catchall.tform.php
+++ b/interface/web/mail/form/mail_domain_catchall.tform.php
@@ -113,7 +113,7 @@ $form["tabs"]['catchall'] = array (
 										'valuefield'	=> 'email'
 									 ),
 			*/
-			'validators' => array (  0 => array ( 'type' => 'ISEMAIL',
+			'validators' => array (  0 => array ( 'type' => 'ISEMAILADRESS',
 					'errmsg'=> 'destination_error_isemail'),
 			),
 			'value'  => '',
-- 
GitLab