From b658fe80a25ec780836e36214e21b57cd635eb95 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Fri, 23 May 2008 15:36:10 +0000
Subject: [PATCH] Fixed: Module > Email > Email Mailbox > Mailfilter
 custom_mailfilter is missing in English Fixed: Several php notices for
 undefined indexes.

---
 interface/web/mail/lib/lang/en_mail_user.lng | 55 ++++++------
 interface/web/mail/mail_user_edit.php        | 89 +++++++++++---------
 2 files changed, 75 insertions(+), 69 deletions(-)

diff --git a/interface/web/mail/lib/lang/en_mail_user.lng b/interface/web/mail/lib/lang/en_mail_user.lng
index 99fab8afcd..0ca2f442a0 100644
--- a/interface/web/mail/lib/lang/en_mail_user.lng
+++ b/interface/web/mail/lib/lang/en_mail_user.lng
@@ -1,29 +1,28 @@
-<?php
-$wb["custom_mailfilter_txt"] = 'custom_mailfilter';
-$wb["btn_save_txt"] = 'Save';
-$wb["btn_cancel_txt"] = 'Cancel';
-$wb["email_txt"] = 'Email';
-$wb["cryptpwd_txt"] = 'Password';
-$wb["active_txt"] = 'Active';
-$wb["email_error_isemail"] = 'Email address is invalid.';
-$wb["email_error_unique"] = 'Duplicate Emailaddress.';
-$wb["autoresponder_text_txt"] = 'Text';
-$wb["autoresponder_txt"] = 'Autoresponder';
-$wb["no_domain_perm"] = 'You have no permission for this domain.';
-$wb["error_no_pwd"] = 'Password is empty.';
-$wb["quota_error_isint"] = 'Mailbox size must be a number.';
-$wb["quota_txt"] = 'quota';
-$wb["server_id_txt"] = 'server_id';
-$wb["password_txt"] = 'password';
-$wb["maildir_txt"] = 'maildir';
-$wb["postfix_txt"] = 'Enable Receiving';
-$wb["access_txt"] = 'Enable Access';
-$wb["policy_txt"] = 'Spamfilter';
-$wb["no_policy"] = '- not enabled -';
-$wb["limit_mailbox_txt"] = 'The max. number of mailboxes for your account is reached.';
-$wb["limit_mailquota_txt"] = 'The max space for mailboxes is reached. The max. available space in MB is';
-$wb["welcome_mail_subject"] = 'Welcome to your new email account.';
-$wb["welcome_mail_message"] = 'Welcome to your new email account.
- 
- Your webmaster.';
+<?php
+$wb["custom_mailfilter_txt"] = 'custom_mailfilter';
+$wb["btn_save_txt"] = 'Save';
+$wb["btn_cancel_txt"] = 'Cancel';
+$wb["email_txt"] = 'Email';
+$wb["cryptpwd_txt"] = 'Password';
+$wb["active_txt"] = 'Active';
+$wb["email_error_isemail"] = 'Email address is invalid.';
+$wb["email_error_unique"] = 'Duplicate Emailaddress.';
+$wb["autoresponder_text_txt"] = 'Text';
+$wb["autoresponder_txt"] = 'Autoresponder';
+$wb["no_domain_perm"] = 'You have no permission for this domain.';
+$wb["error_no_pwd"] = 'Password is empty.';
+$wb["quota_error_isint"] = 'Mailbox size must be a number.';
+$wb["quota_txt"] = 'quota';
+$wb["server_id_txt"] = 'server_id';
+$wb["password_txt"] = 'password';
+$wb["maildir_txt"] = 'maildir';
+$wb["postfix_txt"] = 'Enable Receiving';
+$wb["access_txt"] = 'Enable Access';
+$wb["policy_txt"] = 'Spamfilter';
+$wb["no_policy"] = '- not enabled -';
+$wb["limit_mailbox_txt"] = 'The max. number of mailboxes for your account is reached.';
+$wb["limit_mailquota_txt"] = 'The max space for mailboxes is reached. The max. available space in MB is';
+$wb["welcome_mail_subject"] = 'Welcome to your new email account.';
+$wb["welcome_mail_message"] = 'Welcome to your new email account.\n\nYour webmaster.';
+$wb['custom_mailfilter_txt'] = 'Custom mail filter recipe';
 ?>
\ No newline at end of file
diff --git a/interface/web/mail/mail_user_edit.php b/interface/web/mail/mail_user_edit.php
index e18b390184..9d08bd7a45 100644
--- a/interface/web/mail/mail_user_edit.php
+++ b/interface/web/mail/mail_user_edit.php
@@ -123,8 +123,10 @@ class page_action extends tform_actions {
 		global $app, $conf;
 		
 		// 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'));
-		if($domain["domain"] != $_POST["email_domain"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
+		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'));
+			if($domain["domain"] != $_POST["email_domain"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
+		}
 		
 		
 		// if its an insert, check that the password is not empty
@@ -166,25 +168,28 @@ class page_action extends tform_actions {
 		
 
 		// compose the email field
-		$this->dataRecord["email"] = $_POST["email_local_part"]."@".$_POST["email_domain"];
-		// Set the server id of the mailbox = server ID of mail domain.
-		$this->dataRecord["server_id"] = $domain["server_id"];
+		if(isset($_POST["email_local_part"]) && isset($_POST["email_domain"])) {
+			$this->dataRecord["email"] = $_POST["email_local_part"]."@".$_POST["email_domain"];
+		
+			// Set the server id of the mailbox = server ID of mail domain.
+			$this->dataRecord["server_id"] = $domain["server_id"];
 		
-		unset($this->dataRecord["email_local_part"]);
-		unset($this->dataRecord["email_domain"]);
+			unset($this->dataRecord["email_local_part"]);
+			unset($this->dataRecord["email_domain"]);
 		
-		// Convert quota from MB to Bytes
-		$this->dataRecord["quota"] = $this->dataRecord["quota"] * 1024 * 1024;
+			// Convert quota from MB to Bytes
+			$this->dataRecord["quota"] = $this->dataRecord["quota"] * 1024 * 1024;
 		
-		// setting Maildir, Homedir, UID and GID
-		$app->uses('getconf');
-		$mail_config = $app->getconf->get_server_config($domain["server_id"],'mail');
-		$maildir = str_replace("[domain]",$domain["domain"],$mail_config["maildir_path"]);
-		$maildir = str_replace("[localpart]",$_POST["email_local_part"],$maildir);
-		$this->dataRecord["maildir"] = $maildir;
-		$this->dataRecord["homedir"] = $mail_config["homedir_path"];
-		$this->dataRecord["uid"] = $mail_config["mailuser_uid"];
-		$this->dataRecord["gid"] = $mail_config["mailuser_gid"];
+			// setting Maildir, Homedir, UID and GID
+			$app->uses('getconf');
+			$mail_config = $app->getconf->get_server_config($domain["server_id"],'mail');
+			$maildir = str_replace("[domain]",$domain["domain"],$mail_config["maildir_path"]);
+			$maildir = str_replace("[localpart]",$_POST["email_local_part"],$maildir);
+			$this->dataRecord["maildir"] = $maildir;
+			$this->dataRecord["homedir"] = $mail_config["homedir_path"];
+			$this->dataRecord["uid"] = $mail_config["mailuser_uid"];
+			$this->dataRecord["gid"] = $mail_config["mailuser_gid"];
+		}
 
 		
 		parent::onSubmit();
@@ -222,30 +227,32 @@ class page_action extends tform_actions {
 		global $app, $conf;
 		
 		// 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'));
-		$app->db->query("UPDATE mail_user SET sys_groupid = ".$domain["sys_groupid"]." WHERE mailuser_id = ".$this->id);
+		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'));
+			$app->db->query("UPDATE mail_user SET sys_groupid = ".$domain["sys_groupid"]." WHERE mailuser_id = ".$this->id);
 		
-		// Spamfilter policy
-		$policy_id = intval($this->dataRecord["policy"]);
-		$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '".addslashes($this->dataRecord["email"])."'");
-		if($policy_id > 0) {
-			if($tmp_user["id"] > 0) {
-				// There is already a record that we will update
-				$sql = "UPDATE spamfilter_users SET policy_id = $policy_id WHERE id = ".$tmp_user["id"];
-				$app->db->query($sql);
-			} else {
-				// We create a new record
-				$sql = "INSERT INTO `spamfilter_users` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`) 
-				        VALUES (".$_SESSION["s"]["user"]["userid"].", ".$domain["sys_groupid"].", 'riud', 'riud', '', ".$domain["server_id"].", 1, ".$policy_id.", '".addslashes($this->dataRecord["email"])."', '".addslashes($this->dataRecord["email"])."', 'Y')";
-				$app->db->query($sql);
-			}
-		}else {
-			if($tmp_user["id"] > 0) {
-				// There is already a record but the user shall have no policy, so we delete it
-				$sql = "DELETE FROM spamfilter_users WHERE id = ".$tmp_user["id"];
-				$app->db->query($sql);
-			}
-		} // endif spamfilter policy
+			// Spamfilter policy
+			$policy_id = intval($this->dataRecord["policy"]);
+			$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '".addslashes($this->dataRecord["email"])."'");
+			if($policy_id > 0) {
+				if($tmp_user["id"] > 0) {
+					// There is already a record that we will update
+					$sql = "UPDATE spamfilter_users SET policy_id = $policy_id WHERE id = ".$tmp_user["id"];
+					$app->db->query($sql);
+				} else {
+					// We create a new record
+					$sql = "INSERT INTO `spamfilter_users` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`) 
+				        	VALUES (".$_SESSION["s"]["user"]["userid"].", ".$domain["sys_groupid"].", 'riud', 'riud', '', ".$domain["server_id"].", 1, ".$policy_id.", '".addslashes($this->dataRecord["email"])."', '".addslashes($this->dataRecord["email"])."', 'Y')";
+					$app->db->query($sql);
+				}
+			}else {
+				if($tmp_user["id"] > 0) {
+					// There is already a record but the user shall have no policy, so we delete it
+					$sql = "DELETE FROM spamfilter_users WHERE id = ".$tmp_user["id"];
+					$app->db->query($sql);
+				}
+			} // endif spamfilter policy
+		}
 		
 	}
 	
-- 
GitLab