Skip to content

Commit 89623de

Browse files
committed
Fixed: FS#778 - mailalias has priority over mailbox if they both exist. Added a error message that prevents it to add a alias or forward when a mailbox with the same email address exists.
1 parent 2eff06f commit 89623de

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ $wb["email_error_unique"] = 'Duplicate Emailaddress.';
77
$wb["no_domain_perm"] = "You have no permission for this domain.";
88
$wb["destination_error_isemail"] = 'Destination Emailaddress is invalid.';
99
$wb["limit_mailalias_txt"] = 'The max. number of email aliases for your account is reached.';
10+
$wb["duplicate_mailbox_txt"] = 'There is already a mailbox with this email address';
1011
?>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ $wb["email_txt"] = 'Email';
33
$wb["destination_txt"] = 'Destination Email';
44
$wb["active_txt"] = 'Active';
55
$wb["limit_mailforward_txt"] = 'The max. number of email forwarders for your account is reached.';
6+
$wb["duplicate_mailbox_txt"] = 'There is already a mailbox with this email address';
67
?>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ $wb["welcome_mail_subject"] = 'Welcome to your new email account.';
2727
$wb["welcome_mail_message"] = "Welcome to your new email account. Your webmaster.";
2828
$wb["disableimap_txt"] = 'Disable IMAP';
2929
$wb["disablepop3_txt"] = 'Disable POP3';
30+
$wb["duplicate_alias_or_forward_txt"] = 'There is already an alias or forwrd with this email address.';
3031
?>

interface/web/mail/mail_alias_edit.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
Copyright (c) 2005, Till Brehm, projektfarm Gmbh
3+
Copyright (c) 2005 - 2009, Till Brehm, projektfarm Gmbh
44
All rights reserved.
55
66
Redistribution and use in source and binary forms, with or without modification,
@@ -126,6 +126,11 @@ function onSubmit() {
126126
unset($this->dataRecord["email_local_part"]);
127127
unset($this->dataRecord["email_domain"]);
128128

129+
//* Check if there is no mailbox with this address
130+
$tmp = $app->db->queryOneRecord("SELECT count(mailuser_id) as number FROM mail_user WHERE email = '".$app->db->quote($this->dataRecord["source"])."'");
131+
if($tmp['number'] > 0) $app->tform->errorMessage .= $app->tform->lng("duplicate_mailbox_txt")."<br>";
132+
unset($tmp);
133+
129134
parent::onSubmit();
130135
}
131136

interface/web/mail/mail_forward_edit.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
Copyright (c) 2005, Till Brehm, projektfarm Gmbh
3+
Copyright (c) 2005 - 2009, Till Brehm, projektfarm Gmbh
44
All rights reserved.
55
66
Redistribution and use in source and binary forms, with or without modification,
@@ -123,6 +123,11 @@ function onSubmit() {
123123
unset($this->dataRecord["email_local_part"]);
124124
unset($this->dataRecord["email_domain"]);
125125

126+
//* Check if there is no mailbox with this address
127+
$tmp = $app->db->queryOneRecord("SELECT count(mailuser_id) as number FROM mail_user WHERE email = '".$app->db->quote($this->dataRecord["source"])."'");
128+
if($tmp['number'] > 0) $app->tform->errorMessage .= $app->tform->lng("duplicate_mailbox_txt")."<br>";
129+
unset($tmp);
130+
126131
parent::onSubmit();
127132
}
128133

interface/web/mail/mail_user_edit.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
Copyright (c) 2005, Till Brehm, projektfarm Gmbh
3+
Copyright (c) 2005 - 2009, Till Brehm, projektfarm Gmbh
44
All rights reserved.
55
66
Redistribution and use in source and binary forms, with or without modification,
@@ -98,7 +98,7 @@ function onShowEnd() {
9898
$tmp_user = $app->db->queryOneRecord("SELECT policy_id FROM spamfilter_users WHERE email = '".$this->dataRecord["email"]."'");
9999
$sql = "SELECT id, policy_name FROM spamfilter_policy WHERE ".$app->tform->getAuthSQL('r');
100100
$policys = $app->db->queryAllRecords($sql);
101-
$policy_select = "<option value='0'>".$app->tform->wordbook["no_policy"]."</option>";
101+
$policy_select = "<option value='0'>".$app->tform->lng("no_policy")."</option>";
102102
if(is_array($policys)) {
103103
foreach( $policys as $p) {
104104
$selected = ($p["id"] == $tmp_user["policy_id"])?'SELECTED':'';
@@ -119,19 +119,19 @@ function onShowEnd() {
119119
function onSubmit() {
120120
global $app, $conf;
121121

122-
// Check if Domain belongs to user
122+
//* Check if Domain belongs to user
123123
if(isset($_POST["email_domain"])) {
124124
$domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r'));
125-
if($domain["domain"] != $_POST["email_domain"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
125+
if($domain["domain"] != $_POST["email_domain"]) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
126126
}
127127

128128

129-
// if its an insert, check that the password is not empty
129+
//* if its an insert, check that the password is not empty
130130
if($this->id == 0 && $_POST["password"] == '') {
131-
$app->tform->errorMessage .= $app->tform->wordbook["error_no_pwd"]."<br>";
131+
$app->tform->errorMessage .= $app->tform->lng("error_no_pwd")."<br>";
132132
}
133133

134-
// Check the client limits, if user is not the admin
134+
//* Check the client limits, if user is not the admin
135135
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
136136
// Get the limits of the client
137137
$client_group_id = $_SESSION["s"]["user"]["default_group"];
@@ -142,7 +142,7 @@ function onSubmit() {
142142
if($this->id == 0 && $client["limit_mailbox"] >= 0) {
143143
$tmp = $app->db->queryOneRecord("SELECT count(mailuser_id) as number FROM mail_user WHERE sys_groupid = $client_group_id");
144144
if($tmp["number"] >= $client["limit_mailbox"]) {
145-
$app->tform->errorMessage .= $app->tform->wordbook["limit_mailbox_txt"]."<br>";
145+
$app->tform->errorMessage .= $app->tform->lng("limit_mailbox_txt")."<br>";
146146
}
147147
unset($tmp);
148148
}
@@ -154,7 +154,7 @@ function onSubmit() {
154154
$new_mailbox_quota = intval($this->dataRecord["quota"]);
155155
if($mailquota + $new_mailbox_quota > $client["limit_mailquota"]) {
156156
$max_free_quota = $client["limit_mailquota"] - $mailquota;
157-
$app->tform->errorMessage .= $app->tform->wordbook["limit_mailquota_txt"].": ".$max_free_quota."<br>";
157+
$app->tform->errorMessage .= $app->tform->lng("limit_mailquota_txt").": ".$max_free_quota."<br>";
158158
// Set the quota field to the max free space
159159
$this->dataRecord["quota"] = $max_free_quota;
160160
}
@@ -164,7 +164,7 @@ function onSubmit() {
164164
} // end if user is not admin
165165

166166

167-
// compose the email field
167+
//* compose the email field
168168
if(isset($_POST["email_local_part"]) && isset($_POST["email_domain"])) {
169169
$this->dataRecord["email"] = $_POST["email_local_part"]."@".$_POST["email_domain"];
170170

@@ -186,8 +186,13 @@ function onSubmit() {
186186
$this->dataRecord["homedir"] = $mail_config["homedir_path"];
187187
$this->dataRecord["uid"] = $mail_config["mailuser_uid"];
188188
$this->dataRecord["gid"] = $mail_config["mailuser_gid"];
189+
190+
//* Check if there is no alias or forward with this address
191+
$tmp = $app->db->queryOneRecord("SELECT count(forwarding_id) as number FROM mail_forwarding WHERE source = '".$app->db->quote($this->dataRecord["email"])."'");
192+
if($tmp['number'] > 0) $app->tform->errorMessage .= $app->tform->lng("duplicate_alias_or_forward_txt")."<br>";
193+
unset($tmp);
194+
189195
}
190-
191196

192197
parent::onSubmit();
193198
}
@@ -203,23 +208,23 @@ function onAfterInsert() {
203208
// mail($this->dataRecord["email"],$app->tform->wordbook["welcome_mail_subject"],$app->tform->wordbook["welcome_mail_message"]);
204209

205210
// tries to detect current charset, and encode subject-header and body from it to ISO-8859-1.
206-
$fromCharset = mb_detect_encoding($app->tform->wordbook["welcome_mail_subject"]);
211+
$fromCharset = mb_detect_encoding($app->tform->lng("welcome_mail_subject"));
207212
$iconvPreferences = array("input-charset" => $fromCharset,
208213
"output-charset" => "ISO-8859-1",
209214
"line-length" => 76,
210215
"line-break-chars" => "\n",
211216
"scheme" => "Q");
212217

213-
$welcomeFromName = $app->tform->wordbook["welcome_mail_fromname_txt"];
214-
$welcomeFromEmail = $app->tform->wordbook["welcome_mail_fromemail_txt"];
218+
$welcomeFromName = $app->tform->lng("welcome_mail_fromname_txt");
219+
$welcomeFromEmail = $app->tform->lng("welcome_mail_fromemail_txt");
215220
$mailHeaders = "MIME-Version: 1.0" . "\n";
216221
$mailHeaders .= "Content-type: text/plain; charset=iso-8859-1" . "\n";
217222
$mailHeaders .= "From: $welcomeFromName <$welcomeFromEmail>" . "\n";
218223
$mailHeaders .= "Reply-To: <$welcomeFromEmail>" . "\n";
219224
$mailTarget = $this->dataRecord["email"];
220-
$mailSubject = iconv_mime_encode("trimoff", $app->tform->wordbook["welcome_mail_subject"], $iconvPreferences);
225+
$mailSubject = iconv_mime_encode("trimoff", $app->tform->lng("welcome_mail_subject"), $iconvPreferences);
221226
$mailSubject = str_replace("trimoff: ", "", $mailSubject);
222-
$mailBody = iconv ($fromCharset, "ISO-8859-1", $app->tform->wordbook["welcome_mail_message"]);
227+
$mailBody = iconv ($fromCharset, "ISO-8859-1", $app->tform->lng("welcome_mail_message"));
223228

224229
mail($mailTarget, $mailSubject, $mailBody, $mailHeaders);
225230

0 commit comments

Comments
 (0)