diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index c02a33eebb4d0ff54c889387cbb64782e51de781..265dd8c58330de8e96ad4c3449820f42c4ac62b5 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -876,8 +876,8 @@ class installer_base {
 			$postfix_service = @($out[0]=='')?false:true;
 		} else { //* fallback - Postfix < 2.9
 			$content = rf($conf['postfix']['config_dir'].'/master.cf');
-			$regex = "/^((?!#)".$service.".*".$type.".*)$/m";
-			$postfix_service = @(preg_match($regex, $content))?true:false;
+			$quoted_regex = "^((?!#)".preg_quote($service, '/').".*".preg_quote($type, '/').".*)$";
+			$postfix_service = @(preg_match("/$quoted_regex/m", $content))?true:false;
 		}
 
 		return $postfix_service;
@@ -915,10 +915,11 @@ class installer_base {
 			while ( !feof( $cf ) ) {
 				$line = fgets( $cf );
 
+				$quoted_regex = '^'.preg_quote($service, '/').'\s+'.preg_quote($type, '/');
 				if ( $reading_service ) {
 					# regex matches a new service or "empty" (whitespace) line
 					if ( preg_match( '/^([^\s#]+.*|\s*)$/', $line ) &&
-					   ! preg_match( '/^'.$service.'\s+'.$type.'/', $line ) ) {
+					   ! preg_match( "/$quoted_regex/", $line ) ) {
 						$out .= $line;
 						$reading_service = false;
 					}
@@ -926,7 +927,7 @@ class installer_base {
 					# $skipped_lines .= $line;
 
 				# regex matches definition matching service to be removed
-				} else if ( preg_match( '/^'.$service.'\s+'.$type.'/', $line ) ) {
+				} else if ( preg_match( "/$quoted_regex/", $line ) ) {
 
 					$reading_service = true;
 					# $skipped_lines .= $line;
@@ -1157,13 +1158,13 @@ class installer_base {
 		if(is_file('/var/run/courier/authdaemon/')) caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
 
 		//* Check maildrop service in posfix master.cf
-		$regex = "/^maildrop   unix.*pipe flags=DRhu user=vmail argv=\\/usr\\/bin\\/maildrop -d ".$cf['vmail_username']." \\$\{extension} \\$\{recipient} \\$\{user} \\$\{nexthop} \\$\{sender}/";
+		$quoted_regex = '^maildrop   unix.*pipe flags=DRhu user=vmail '.preg_quote('argv=/usr/bin/maildrop -d '.$cf['vmail_username'].' ${extension} ${recipient} ${user} ${nexthop} ${sender}', '/');
 		$configfile = $config_dir.'/master.cf';
 		if($this->get_postfix_service('maildrop', 'unix')) {
 			exec ("postconf -M maildrop.unix 2> /dev/null", $out, $ret);
-			$change_maildrop_flags = @(preg_match($regex, $out[0]) && $out[0] !='')?false:true;
+			$change_maildrop_flags = @(preg_match("/$quoted_regex/", $out[0]) && $out[0] !='')?false:true;
 		} else {
-			$change_maildrop_flags = @(preg_match($regex, $configfile))?false:true;
+			$change_maildrop_flags = @(preg_match("/$quoted_regex/", $configfile))?false:true;
 		}
 		if ($change_maildrop_flags) {
 			//* Change maildrop service in posfix master.cf
@@ -1343,6 +1344,7 @@ class installer_base {
 		}
 
 		$config_dir = $conf['postfix']['config_dir'];
+		$quoted_config_dir = preg_quote($config_dir, '/');
 		$postfix_version = `postconf -d mail_version 2>/dev/null`;
 		$postfix_version = preg_replace( '/mail_version\s*=\s*(.*)\s*/', '$1', $postfix_version );
 
@@ -1375,11 +1377,12 @@ class installer_base {
 		// Make a backup copy of the main.cf file
 		copy($config_dir.'/main.cf', $config_dir.'/main.cf~3');
 
-		$options = explode(",", exec("postconf -h smtpd_recipient_restrictions"));
+		$options = preg_split("/,\s*/", exec("postconf -h smtpd_recipient_restrictions"));
 		$new_options = array();
 		foreach ($options as $value) {
-			if (($value = trim($value)) == '') continue;
-			if (preg_match("|check_recipient_access\s+proxy:mysql:${config_dir}/mysql-verify_recipients.cf|", $value)) {
+			$value = trim($value);
+			if ($value == '') continue;
+			if (preg_match("|check_recipient_access\s+proxy:mysql:${quoted_config_dir}/mysql-verify_recipients.cf|", $value)) {
 				continue;
 			}
 			$new_options[] = $value;
@@ -1638,10 +1641,11 @@ class installer_base {
 			exec("postconf -e 'smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf, permit_mynetworks, permit_sasl_authenticated'");
 
 
-			$options = explode(",", exec("postconf -h smtpd_recipient_restrictions"));
+			$options = preg_split("/,\s*/", exec("postconf -h smtpd_recipient_restrictions"));
 			$new_options = array();
 			foreach ($options as $value) {
-				if (($value = trim($value)) == '') continue;
+				$value = trim($value);
+				if ($value == '') continue;
 				if (preg_match('/check_policy_service\s+inet:127.0.0.1:10023/', $value)) {
 					continue;
 				}
diff --git a/server/plugins-available/postfix_server_plugin.inc.php b/server/plugins-available/postfix_server_plugin.inc.php
index 757ee5e72f47630911d1d846d057526efd841f3e..5a0b222a2491bb62125adbaa096d887ed28aee85 100644
--- a/server/plugins-available/postfix_server_plugin.inc.php
+++ b/server/plugins-available/postfix_server_plugin.inc.php
@@ -85,7 +85,7 @@ class postfix_server_plugin {
 
 		if ($mail_config['relayhost'].$mail_config['relayhost_user'].$mail_config['relayhost_password'] != $old_ini_data['mail']['relayhost'].$old_ini_data['mail']['relayhost_user'].$old_ini_data['mail']['relayhost_password']) {
 			$content = file_exists('/etc/postfix/sasl_passwd') ? file_get_contents('/etc/postfix/sasl_passwd') : '';
-			$content = preg_replace('/^'.preg_quote($old_ini_data['email']['relayhost']).'\s+[^\n]*(:?\n|)/m','',$content);
+			$content = preg_replace('/^'.preg_quote($old_ini_data['email']['relayhost'], '/').'\s+[^\n]*(:?\n|)/m','',$content);
 
 			if (!empty($mail_config['relayhost_user']) || !empty($mail_config['relayhost_password'])) {
 				$content .= "\n".$mail_config['relayhost'].'   '.$mail_config['relayhost_user'].':'.$mail_config['relayhost_password'];
@@ -114,10 +114,11 @@ class postfix_server_plugin {
 			if($rbl_hosts != ''){
 				$rbl_hosts = explode(",", $rbl_hosts);
 			}
-			$options = explode(",", exec("postconf -h smtpd_recipient_restrictions"));
+			$options = preg_split("/,\s*/", exec("postconf -h smtpd_recipient_restrictions"));
 			$new_options = array();
 			foreach ($options as $key => $value) {
-				if (($value = trim($value)) == '') continue;
+				$value = trim($value);
+				if ($value == '') continue;
 				if (!preg_match('/reject_rbl_client/', $value)) {
 					$new_options[] = $value;
 				} else {
@@ -142,7 +143,7 @@ class postfix_server_plugin {
 		}
 		
 		if($mail_config['reject_sender_login_mismatch'] != $old_ini_data['mail']['reject_sender_login_mismatch']) {
-			$options = explode(", ", exec("postconf -h smtpd_sender_restrictions"));
+			$options = preg_split("/,\s*/", exec("postconf -h smtpd_sender_restrictions"));
 			$new_options = array();
 			foreach ($options as $key => $value) {
 				if (!preg_match('/reject_authenticated_sender_login_mismatch/', $value)) {
@@ -193,12 +194,13 @@ class postfix_server_plugin {
 			}
 		}
 
-		$postfix_config_dir = $conf['postfix']['config_dir'];
+		$quoted_postfix_config_dir = preg_quote($conf['postfix']['config_dir'], '|');
 		$new_options = array();
-		$options = explode(",", exec("postconf -h smtpd_recipient_restrictions"));
+		$options = preg_split("/,\s*/", exec("postconf -h smtpd_recipient_restrictions"));
 		foreach ($options as $key => $value) {
-			if (($value = trim($value)) == '') continue;
-			if (preg_match("|check_recipient_access\s+proxy:mysql:${postfix_config_dir}/mysql-verify_recipients.cf|", $value)) {
+			$value = trim($value);
+			if ($value == '') continue;
+			if (preg_match("|check_recipient_access\s+proxy:mysql:${quoted_postfix_config_dir}/mysql-verify_recipients.cf|", $value)) {
 				continue;
 			}
 			$new_options[] = $value;
@@ -231,9 +233,10 @@ class postfix_server_plugin {
 				exec("postconf -e 'smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf, permit_mynetworks, permit_sasl_authenticated'");
 				
 				$new_options = array();
-				$options = explode(",", exec("postconf -h smtpd_recipient_restrictions"));
+				$options = preg_split("/,\s*/", exec("postconf -h smtpd_recipient_restrictions"));
 				foreach ($options as $key => $value) {
-					if (($value = trim($value)) == '') continue;
+					$value = trim($value);
+					if ($value == '') continue;
 					if (preg_match('/check_policy_service\s+inet:127.0.0.1:10023/', $value)) {
 						continue;
 					}