Commit d6363ba9 authored by mcramer's avatar mcramer

Fixed: Added missing idn converts to mail functions

Added: Changed idn function to support multi-line fields (like mail forward)
parent 8c1761c6
...@@ -315,7 +315,7 @@ class functions { ...@@ -315,7 +315,7 @@ class functions {
/** IDN converter wrapper. /** IDN converter wrapper.
* all converter classes should be placed in ISPC_CLASS_PATH.'/idn/' * all converter classes should be placed in ISPC_CLASS_PATH.'/idn/'
*/ */
public function idn_encode($domain) { private function _idn_encode_decode($domain, $encode = true) {
if($domain == '') return ''; if($domain == '') return '';
if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee encoded if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee encoded
...@@ -326,56 +326,60 @@ class functions { ...@@ -326,56 +326,60 @@ class functions {
$domain = substr($domain, strrpos($domain, '@') + 1); $domain = substr($domain, strrpos($domain, '@') + 1);
} }
if(function_exists('idn_to_ascii')) { if($encode == true) {
$domain = idn_to_ascii($domain); if(function_exists('idn_to_ascii')) {
} elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) { $domain = idn_to_ascii($domain);
/* use idna class: } elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) {
* @author Matthias Sommerfeld <mso@phlylabs.de> /* use idna class:
* @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de * @author Matthias Sommerfeld <mso@phlylabs.de>
* @version 0.8.0 2011-03-11 * @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de
*/ * @version 0.8.0 2011-03-11
*/
if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php'); if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
$this->idn_converter = new idna_convert(array('idn_version' => 2008)); include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php');
$this->idn_converter_name = 'idna_convert.class'; $this->idn_converter = new idna_convert(array('idn_version' => 2008));
$this->idn_converter_name = 'idna_convert.class';
}
$domain = $this->idn_converter->encode($domain);
}
} else {
if(function_exists('idn_to_utf8')) {
$domain = idn_to_utf8($domain);
} elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) {
/* use idna class:
* @author Matthias Sommerfeld <mso@phlylabs.de>
* @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de
* @version 0.8.0 2011-03-11
*/
if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php');
$this->idn_converter = new idna_convert(array('idn_version' => 2008));
$this->idn_converter_name = 'idna_convert.class';
}
$domain = $this->idn_converter->decode($domain);
} }
$domain = $this->idn_converter->encode($domain);
} }
if($user_part !== false) return $user_part . '@' . $domain; if($user_part !== false) return $user_part . '@' . $domain;
else return $domain; else return $domain;
} }
public function idn_encode($domain) {
$domains = explode("\n", $domain);
for($d = 0; $d < count($domains); $d++) {
$domains[$d] = $this->_idn_encode_decode($domains[$d], true);
}
return implode("\n", $domains);
}
public function idn_decode($domain) { public function idn_decode($domain) {
if($domain == '') return ''; $domains = explode("\n", $domain);
if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee decoded for($d = 0; $d < count($domains); $d++) {
$domains[$d] = $this->_idn_encode_decode($domains[$d], false);
// get domain and user part if it is an email
$user_part = false;
if(strpos($domain, '@') !== false) {
$user_part = substr($domain, 0, strrpos($domain, '@'));
$domain = substr($domain, strrpos($domain, '@') + 1);
} }
if(function_exists('idn_to_utf8')) { return implode("\n", $domains);
$domain = idn_to_utf8($domain);
} elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) {
/* use idna class:
* @author Matthias Sommerfeld <mso@phlylabs.de>
* @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de
* @version 0.8.0 2011-03-11
*/
if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php');
$this->idn_converter = new idna_convert(array('idn_version' => 2008));
$this->idn_converter_name = 'idna_convert.class';
}
$domain = $this->idn_converter->decode($domain);
}
if($user_part !== false) return $user_part . '@' . $domain;
else return $domain;
} }
} }
......
...@@ -276,6 +276,17 @@ class tform { ...@@ -276,6 +276,17 @@ class tform {
$this->errorMessage .= "Custom datasource class or function is empty<br />\r\n"; $this->errorMessage .= "Custom datasource class or function is empty<br />\r\n";
} }
} }
if(isset($field['filters']) && is_array($field['filters'])) {
$new_values = array();
foreach($values as $index => $value) {
$new_index = $this->filterField($index, $index, $field['filters'], 'SHOW');
$new_values[$new_index] = $this->filterField($index, (isset($values[$index]))?$values[$index]:'', $field['filters'], 'SHOW');
}
$values = $new_values;
unset($new_values);
unset($new_index);
}
return $values; return $values;
......
...@@ -96,6 +96,13 @@ $form["tabs"]['mailuser'] = array ( ...@@ -96,6 +96,13 @@ $form["tabs"]['mailuser'] = array (
'login' => array ( 'login' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 'validators' => array (
0 => array ( 'type' => 'UNIQUE', 0 => array ( 'type' => 'UNIQUE',
'errmsg'=> 'login_error_unique'), 'errmsg'=> 'login_error_unique'),
......
...@@ -61,6 +61,9 @@ $liste["item"][] = array( 'field' => "email", ...@@ -61,6 +61,9 @@ $liste["item"][] = array( 'field' => "email",
$liste["item"][] = array( 'field' => "login", $liste["item"][] = array( 'field' => "login",
'datatype' => "VARCHAR", 'datatype' => "VARCHAR",
'filters' => array( 0 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8')
),
'formtype' => "TEXT", 'formtype' => "TEXT",
'op' => "like", 'op' => "like",
'prefix' => "%", 'prefix' => "%",
......
...@@ -72,6 +72,7 @@ class page_action extends tform_actions { ...@@ -72,6 +72,7 @@ class page_action extends tform_actions {
$email = $this->dataRecord["source"]; $email = $this->dataRecord["source"];
$email_parts = explode("@",$email); $email_parts = explode("@",$email);
$app->tpl->setVar("email_local_part",$email_parts[0]); $app->tpl->setVar("email_local_part",$email_parts[0]);
$email_parts[1] = $app->functions->idn_decode($email_parts[1]);
// Getting Domains of the user // Getting Domains of the user
// $sql = "SELECT domain FROM mail_domain WHERE ".$app->tform->getAuthSQL('r').' ORDER BY domain'; // $sql = "SELECT domain FROM mail_domain WHERE ".$app->tform->getAuthSQL('r').' ORDER BY domain';
...@@ -80,6 +81,7 @@ class page_action extends tform_actions { ...@@ -80,6 +81,7 @@ class page_action extends tform_actions {
$domain_select = ''; $domain_select = '';
if(is_array($domains)) { if(is_array($domains)) {
foreach( $domains as $domain) { foreach( $domains as $domain) {
$domain['domain'] = $app->functions->idn_decode($domain['domain']);
$selected = ($domain["domain"] == @$email_parts[1])?'SELECTED':''; $selected = ($domain["domain"] == @$email_parts[1])?'SELECTED':'';
$domain_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n"; $domain_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n";
} }
...@@ -93,8 +95,8 @@ class page_action extends tform_actions { ...@@ -93,8 +95,8 @@ class page_action extends tform_actions {
global $app, $conf; global $app, $conf;
// Check if Domain belongs to user // Check if Domain belongs to user
$domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["email_domain"]))."' AND ".$app->tform->getAuthSQL('r'));
if($domain["domain"] != $_POST["email_domain"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"]; if($domain["domain"] != $app->functions->idn_encode($_POST["email_domain"])) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
// Check the client limits, if user is not the admin // Check the client limits, if user is not the admin
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
...@@ -114,7 +116,7 @@ class page_action extends tform_actions { ...@@ -114,7 +116,7 @@ class page_action extends tform_actions {
// compose the email field // compose the email field
$this->dataRecord["source"] = $_POST["email_local_part"]."@".$_POST["email_domain"]; $this->dataRecord["source"] = $_POST["email_local_part"]."@".$app->functions->idn_encode($_POST["email_domain"]);
// Set the server id of the mailbox = server ID of mail domain. // Set the server id of the mailbox = server ID of mail domain.
$this->dataRecord["server_id"] = $domain["server_id"]; $this->dataRecord["server_id"] = $domain["server_id"];
...@@ -141,7 +143,7 @@ class page_action extends tform_actions { ...@@ -141,7 +143,7 @@ class page_action extends tform_actions {
function onAfterInsert() { function onAfterInsert() {
global $app; global $app;
$domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["email_domain"]))."' AND ".$app->tform->getAuthSQL('r'));
$app->db->query("update mail_forwarding SET sys_groupid = ".$domain['sys_groupid']." WHERE forwarding_id = ".$this->id); $app->db->query("update mail_forwarding SET sys_groupid = ".$domain['sys_groupid']." WHERE forwarding_id = ".$this->id);
} }
......
...@@ -69,8 +69,8 @@ class page_action extends tform_actions { ...@@ -69,8 +69,8 @@ class page_action extends tform_actions {
function onShowEnd() { function onShowEnd() {
global $app, $conf; global $app, $conf;
$source_domain = substr($this->dataRecord["source"],1); $source_domain = $app->functions->idn_decode(substr($this->dataRecord["source"],1));
$destination_domain = substr($this->dataRecord["destination"],1); $destination_domain = $app->functions->idn_decode(substr($this->dataRecord["destination"],1));
// Getting Domains of the user // Getting Domains of the user
$sql = "SELECT domain FROM mail_domain WHERE ".$app->tform->getAuthSQL('r').' ORDER BY domain'; $sql = "SELECT domain FROM mail_domain WHERE ".$app->tform->getAuthSQL('r').' ORDER BY domain';
...@@ -80,6 +80,7 @@ class page_action extends tform_actions { ...@@ -80,6 +80,7 @@ class page_action extends tform_actions {
$destination_select = ''; $destination_select = '';
if(is_array($domains)) { if(is_array($domains)) {
foreach( $domains as $domain) { foreach( $domains as $domain) {
$domain['domain'] = $app->functions->idn_decode($domain['domain']);
$selected = ($domain["domain"] == @$source_domain)?'SELECTED':''; $selected = ($domain["domain"] == @$source_domain)?'SELECTED':'';
$source_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n"; $source_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n";
$selected = ($domain["domain"] == @$destination_domain)?'SELECTED':''; $selected = ($domain["domain"] == @$destination_domain)?'SELECTED':'';
...@@ -96,12 +97,12 @@ class page_action extends tform_actions { ...@@ -96,12 +97,12 @@ class page_action extends tform_actions {
global $app, $conf; global $app, $conf;
// Check if source Domain belongs to user // Check if source Domain belongs to user
$domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($_POST["source"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["source"]))."' AND ".$app->tform->getAuthSQL('r'));
if($domain["domain"] != $_POST["source"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"]; if($domain["domain"] != $app->functions->idn_encode($_POST["source"])) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
// Check if the destination domain belongs to the user // Check if the destination domain belongs to the user
$domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($_POST["destination"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["destination"]))."' AND ".$app->tform->getAuthSQL('r'));
if($domain["domain"] != $_POST["destination"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"]; if($domain["domain"] != $app->functions->idn_encode($_POST["destination"])) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
// Check the client limits, if user is not the admin // Check the client limits, if user is not the admin
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
...@@ -127,7 +128,7 @@ class page_action extends tform_actions { ...@@ -127,7 +128,7 @@ class page_action extends tform_actions {
function onAfterInsert() { function onAfterInsert() {
global $app; global $app;
$domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($_POST["destination"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["destination"]))."' AND ".$app->tform->getAuthSQL('r'));
$app->db->query("update mail_forwarding SET sys_groupid = ".$domain['sys_groupid']." WHERE forwarding_id = ".$this->id); $app->db->query("update mail_forwarding SET sys_groupid = ".$domain['sys_groupid']." WHERE forwarding_id = ".$this->id);
} }
......
...@@ -72,13 +72,15 @@ class page_action extends tform_actions { ...@@ -72,13 +72,15 @@ class page_action extends tform_actions {
$email = $this->dataRecord["source"]; $email = $this->dataRecord["source"];
$email_parts = explode("@",$email); $email_parts = explode("@",$email);
$app->tpl->setVar("email_local_part",$email_parts[0]); $app->tpl->setVar("email_local_part",$email_parts[0]);
$email_parts[1] = $app->functions->idn_decode($email_parts[1]);
// Getting Domains of the user // Getting Domains of the user
$sql = "SELECT domain FROM mail_domain WHERE ".$app->tform->getAuthSQL('r'); $sql = "SELECT domain FROM mail_domain WHERE ".$app->tform->getAuthSQL('r');
$domains = $app->db->queryAllRecords($sql); $domains = $app->db->queryAllRecords($sql);
$domain_select = ''; $domain_select = '';
if(is_array($domains)) { if(is_array($domains)) {
foreach( $domains as $domain) { foreach( $domains as $domain) {
$domain['domain'] = $app->functions->idn_decode($domain['domain']);
$selected = (isset($email_parts[1]) && $domain["domain"] == $email_parts[1])?'SELECTED':''; $selected = (isset($email_parts[1]) && $domain["domain"] == $email_parts[1])?'SELECTED':'';
$domain_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n"; $domain_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n";
} }
...@@ -92,8 +94,8 @@ class page_action extends tform_actions { ...@@ -92,8 +94,8 @@ class page_action extends tform_actions {
global $app, $conf; global $app, $conf;
// Check if Domain belongs to user // Check if Domain belongs to user
$domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["email_domain"]))."' AND ".$app->tform->getAuthSQL('r'));
if($domain["domain"] != $_POST["email_domain"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"]; if($domain["domain"] != $app->functions->idn_encode($_POST["email_domain"])) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
// Check the client limits, if user is not the admin // Check the client limits, if user is not the admin
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
...@@ -112,7 +114,7 @@ class page_action extends tform_actions { ...@@ -112,7 +114,7 @@ class page_action extends tform_actions {
} // end if user is not admin } // end if user is not admin
// compose the email field // compose the email field
$this->dataRecord["source"] = "@".$_POST["email_domain"]; $this->dataRecord["source"] = "@".$app->functions->idn_encode($_POST["email_domain"]);
// Set the server id of the mailbox = server ID of mail domain. // Set the server id of the mailbox = server ID of mail domain.
$this->dataRecord["server_id"] = $domain["server_id"]; $this->dataRecord["server_id"] = $domain["server_id"];
...@@ -125,7 +127,7 @@ class page_action extends tform_actions { ...@@ -125,7 +127,7 @@ class page_action extends tform_actions {
function onAfterInsert() { function onAfterInsert() {
global $app; global $app;
$domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["email_domain"]))."' AND ".$app->tform->getAuthSQL('r'));
$app->db->query("update mail_forwarding SET sys_groupid = ".$domain['sys_groupid']." WHERE forwarding_id = ".$this->id); $app->db->query("update mail_forwarding SET sys_groupid = ".$domain['sys_groupid']." WHERE forwarding_id = ".$this->id);
} }
......
...@@ -72,13 +72,15 @@ class page_action extends tform_actions { ...@@ -72,13 +72,15 @@ class page_action extends tform_actions {
$email = $this->dataRecord["source"]; $email = $this->dataRecord["source"];
$email_parts = explode("@",$email); $email_parts = explode("@",$email);
$app->tpl->setVar("email_local_part",$email_parts[0]); $app->tpl->setVar("email_local_part",$email_parts[0]);
$email_parts[1] = $app->functions->idn_decode($email_parts[1]);
// Getting Domains of the user // Getting Domains of the user
//$sql = "SELECT domain FROM mail_domain WHERE ".$app->tform->getAuthSQL('r').' ORDER BY domain'; //$sql = "SELECT domain FROM mail_domain WHERE ".$app->tform->getAuthSQL('r').' ORDER BY domain';
$sql = "SELECT domain FROM mail_domain WHERE domain NOT IN (SELECT SUBSTR(source,2) FROM mail_forwarding WHERE type = 'aliasdomain') AND ".$app->tform->getAuthSQL('r')." ORDER BY domain"; $sql = "SELECT domain FROM mail_domain WHERE domain NOT IN (SELECT SUBSTR(source,2) FROM mail_forwarding WHERE type = 'aliasdomain') AND ".$app->tform->getAuthSQL('r')." ORDER BY domain";
$domains = $app->db->queryAllRecords($sql); $domains = $app->db->queryAllRecords($sql);
$domain_select = ''; $domain_select = '';
foreach( $domains as $domain) { foreach( $domains as $domain) {
$domain['domain'] = $app->functions->idn_decode($domain['domain']);
$selected = (isset($email_parts[1]) && $domain["domain"] == $email_parts[1])?'SELECTED':''; $selected = (isset($email_parts[1]) && $domain["domain"] == $email_parts[1])?'SELECTED':'';
$domain_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n"; $domain_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n";
} }
...@@ -91,8 +93,8 @@ class page_action extends tform_actions { ...@@ -91,8 +93,8 @@ class page_action extends tform_actions {
global $app, $conf; global $app, $conf;
// Check if Domain belongs to user // Check if Domain belongs to user
$domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["email_domain"]))."' AND ".$app->tform->getAuthSQL('r'));
if($domain["domain"] != $_POST["email_domain"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"]; if($domain["domain"] != $app->functions->idn_encode($_POST["email_domain"])) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
// Check the client limits, if user is not the admin // Check the client limits, if user is not the admin
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
...@@ -111,7 +113,7 @@ class page_action extends tform_actions { ...@@ -111,7 +113,7 @@ class page_action extends tform_actions {
} // end if user is not admin } // end if user is not admin
// compose the email field // compose the email field
$this->dataRecord["source"] = $_POST["email_local_part"]."@".$_POST["email_domain"]; $this->dataRecord["source"] = $_POST["email_local_part"]."@".$app->functions->idn_encode($_POST["email_domain"]);
// Set the server id of the mailbox = server ID of mail domain. // Set the server id of the mailbox = server ID of mail domain.
$this->dataRecord["server_id"] = $domain["server_id"]; $this->dataRecord["server_id"] = $domain["server_id"];
...@@ -129,7 +131,7 @@ class page_action extends tform_actions { ...@@ -129,7 +131,7 @@ class page_action extends tform_actions {
function onAfterInsert() { function onAfterInsert() {
global $app; global $app;
$domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["email_domain"]))."' AND ".$app->tform->getAuthSQL('r'));
$app->db->query("update mail_forwarding SET sys_groupid = ".$domain['sys_groupid']." WHERE forwarding_id = ".$this->id); $app->db->query("update mail_forwarding SET sys_groupid = ".$domain['sys_groupid']." WHERE forwarding_id = ".$this->id);
} }
......
...@@ -73,7 +73,8 @@ class page_action extends tform_actions { ...@@ -73,7 +73,8 @@ class page_action extends tform_actions {
$email = $this->dataRecord["email"]; $email = $this->dataRecord["email"];
$email_parts = explode("@",$email); $email_parts = explode("@",$email);
$app->tpl->setVar("email_local_part",$email_parts[0]); $app->tpl->setVar("email_local_part",$email_parts[0]);
$email_parts[1] = $app->functions->idn_decode($email_parts[1]);
// Getting Domains of the user // Getting Domains of the user
// $sql = "SELECT domain, server_id FROM mail_domain WHERE ".$app->tform->getAuthSQL('r').' ORDER BY domain'; // $sql = "SELECT domain, server_id FROM mail_domain WHERE ".$app->tform->getAuthSQL('r').' ORDER BY domain';
$sql = "SELECT domain, server_id FROM mail_domain WHERE domain NOT IN (SELECT SUBSTR(source,2) FROM mail_forwarding WHERE type = 'aliasdomain') AND ".$app->tform->getAuthSQL('r')." ORDER BY domain"; $sql = "SELECT domain, server_id FROM mail_domain WHERE domain NOT IN (SELECT SUBSTR(source,2) FROM mail_forwarding WHERE type = 'aliasdomain') AND ".$app->tform->getAuthSQL('r')." ORDER BY domain";
...@@ -81,6 +82,7 @@ class page_action extends tform_actions { ...@@ -81,6 +82,7 @@ class page_action extends tform_actions {
$domain_select = ''; $domain_select = '';
if(is_array($domains)) { if(is_array($domains)) {
foreach( $domains as $domain) { foreach( $domains as $domain) {
$domain['domain'] = $app->functions->idn_decode($domain['domain']);
$selected = ($domain["domain"] == @$email_parts[1])?'SELECTED':''; $selected = ($domain["domain"] == @$email_parts[1])?'SELECTED':'';
$domain_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n"; $domain_select .= "<option value='$domain[domain]' $selected>$domain[domain]</option>\r\n";
} }
...@@ -131,8 +133,8 @@ class page_action extends tform_actions { ...@@ -131,8 +133,8 @@ class page_action extends tform_actions {
//* Check if Domain belongs to user //* Check if Domain belongs to user
if(isset($_POST["email_domain"])) { if(isset($_POST["email_domain"])) {
$domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["email_domain"]))."' AND ".$app->tform->getAuthSQL('r'));
if($domain["domain"] != $_POST["email_domain"]) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm"); if($domain["domain"] != $app->functions->idn_encode($_POST["email_domain"])) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
} }
...@@ -179,7 +181,7 @@ class page_action extends tform_actions { ...@@ -179,7 +181,7 @@ class page_action extends tform_actions {
//* compose the email field //* compose the email field
if(isset($_POST["email_local_part"]) && isset($_POST["email_domain"])) { if(isset($_POST["email_local_part"]) && isset($_POST["email_domain"])) {
$this->dataRecord["email"] = strtolower($_POST["email_local_part"]."@".$_POST["email_domain"]); $this->dataRecord["email"] = strtolower($_POST["email_local_part"]."@".$app->functions->idn_encode($_POST["email_domain"]));
// Set the server id of the mailbox = server ID of mail domain. // Set the server id of the mailbox = server ID of mail domain.
$this->dataRecord["server_id"] = $domain["server_id"]; $this->dataRecord["server_id"] = $domain["server_id"];
...@@ -225,7 +227,7 @@ class page_action extends tform_actions { ...@@ -225,7 +227,7 @@ class page_action extends tform_actions {
global $app, $conf; global $app, $conf;
// Set the domain owner as mailbox owner // Set the domain owner as mailbox owner
$domain = $app->db->queryOneRecord("SELECT sys_groupid, server_id FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT sys_groupid, server_id FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["email_domain"]))."' AND ".$app->tform->getAuthSQL('r'));
$app->db->query("UPDATE mail_user SET sys_groupid = ".$domain["sys_groupid"]." WHERE mailuser_id = ".$this->id); $app->db->query("UPDATE mail_user SET sys_groupid = ".$domain["sys_groupid"]." WHERE mailuser_id = ".$this->id);
// Spamfilter policy // Spamfilter policy
...@@ -261,7 +263,7 @@ class page_action extends tform_actions { ...@@ -261,7 +263,7 @@ class page_action extends tform_actions {
// Set the domain owner as mailbox owner // Set the domain owner as mailbox owner
if(isset($_POST["email_domain"])) { if(isset($_POST["email_domain"])) {
$domain = $app->db->queryOneRecord("SELECT sys_groupid, server_id FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r')); $domain = $app->db->queryOneRecord("SELECT sys_groupid, server_id FROM mail_domain WHERE domain = '".$app->db->quote($app->functions->idn_encode($_POST["email_domain"]))."' AND ".$app->tform->getAuthSQL('r'));
$app->db->query("UPDATE mail_user SET sys_groupid = ".$domain["sys_groupid"]." WHERE mailuser_id = ".$this->id); $app->db->query("UPDATE mail_user SET sys_groupid = ".$domain["sys_groupid"]." WHERE mailuser_id = ".$this->id);
// Spamfilter policy // Spamfilter policy
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment