Skip to content

Commit c343a15

Browse files
author
Demian
committed
Refactored Mail Transport and Domain Validator (#6791)
* Added validation to prevent conflicts between mail domains and mail transports: * When adding a new mail domain, the system now checks for existing mail transports with the same domain. * When adding a new mail transport (routing), the system verifies that no mail domain with the same domain exists. * Cleaned up non-functional code in the mail transport validator.
1 parent c910fa2 commit c343a15

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

interface/lib/classes/validate_mail_transport.inc.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,40 @@ function get_error($errmsg) {
4141
}
4242
}
4343

44+
/* Validator function for checking that the 'domain' is not already set as mail_domain */
45+
function validate_isnot_maildomain($field_name, $field_value, $validator) {
46+
global $app, $conf;
47+
48+
if(isset($app->remoting_lib->primary_id)) {
49+
$id = $app->remoting_lib->primary_id;
50+
} else {
51+
$id = $app->tform->primary_id;
52+
}
53+
54+
$sql = "SELECT domain_id, domain FROM mail_domain WHERE domain = ? AND domain_id != ?";
55+
$domain_check = $app->db->queryOneRecord($sql, $field_value, $id);
56+
57+
if($domain_check) return $this->get_error('domain_is_maildomain');
58+
59+
}
60+
61+
/* Validator function for checking that the 'domain' is not already set as mail_transport */
62+
function validate_isnot_mailtransport($field_name, $field_value, $validator) {
63+
global $app, $conf;
64+
65+
if(isset($app->remoting_lib->primary_id)) {
66+
$id = $app->remoting_lib->primary_id;
67+
} else {
68+
$id = $app->tform->primary_id;
69+
}
70+
71+
$sql = "SELECT transport_id, domain FROM mail_transport WHERE domain = ? AND transport_id != ?";
72+
$domain_check = $app->db->queryOneRecord($sql, $field_value, $id);
73+
74+
if($domain_check) return $this->get_error('domain_is_transport');
75+
76+
}
77+
4478
/* Validator function for checking the 'domain' of a mail transport */
4579
function validate_domain($field_name, $field_value, $validator) {
4680
global $app, $conf;
@@ -52,8 +86,8 @@ function validate_domain($field_name, $field_value, $validator) {
5286
}
5387

5488
// mail_transport.domain (could also be an email address) must be unique per server
55-
$sql = "SELECT transport_id, domain FROM mail_transport WHERE domain = ? AND server_id = ? AND transport_id != ?";
56-
$domain_check = $app->db->queryOneRecord($sql, $field_value, $app->tform_actions->dataRecord['server_id'], $id);
89+
$sql = "SELECT transport_id, domain FROM mail_transport WHERE domain = ? AND transport_id != ?";
90+
$domain_check = $app->db->queryOneRecord($sql, $field_value, $id);
5791

5892
if($domain_check) return $this->get_error('domain_error_unique');
5993
}

interface/web/mail/form/mail_domain.tform.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191
'errmsg'=> 'domain_error_unique'),
9292
2 => array ( 'type' => 'ISDOMAIN',
9393
'errmsg'=> 'domain_error_regex'),
94+
3 => array(
95+
'type' => 'CUSTOM',
96+
'class' => 'validate_mail_transport',
97+
'function' => 'validate_isnot_mailtransport',
98+
'errmsg'=> 'domain_is_transport',
99+
),
94100
),
95101
'default' => '',
96102
'value' => '',

interface/web/mail/form/mail_transport.tform.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@
9494
'class' => 'validate_mail_transport',
9595
'function' => 'validate_domain',
9696
'errmsg'=> 'domain_error_unique',
97+
),
98+
1 => array(
99+
'type' => 'CUSTOM',
100+
'class' => 'validate_mail_transport',
101+
'function' => 'validate_isnot_maildomain',
102+
'errmsg' => 'domain_is_maildomain',
97103
)
98104
),
99105
'default' => '',

interface/web/mail/lib/lang/en_mail_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ $wb['dkim_auto_dns_txt'] = 'Managed zone, dns updated automatically';
2424
$wb['relayhost_txt'] = 'Relayhost';
2525
$wb['relayhost_user_txt'] = 'Relayhost User';
2626
$wb['relayhost_password_txt'] = 'Relayhost Password';
27+
$wb['domain_is_transport'] = 'The Domain is already set as E-Mail Transport.';

interface/web/mail/lib/lang/en_mail_transport.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ $wb['active_txt'] = 'Active';
99
$wb['limit_mailrouting_txt'] = 'The max. number of routes for your account is reached.';
1010
$wb['transport_txt'] = 'Transport';
1111
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';
12+
$wb['domain_is_maildomain'] = 'The Domain is already set as a E-Mail Domain.';

0 commit comments

Comments
 (0)