@@ -1002,6 +1002,9 @@ public function configure_postfix($options = '') {
10021002 //* mysql-virtual_uids.cf
10031003 $ this ->process_postfix_config ('mysql-virtual_uids.cf ' );
10041004
1005+ //* mysql-virtual_alias_domains.cf
1006+ $ this ->process_postfix_config ('mysql-verify_recipients.cf ' );
1007+
10051008 // test if lmtp if available
10061009 $ configure_lmtp = $ this ->get_postfix_service ('lmtp ' ,'unix ' );
10071010
@@ -1340,6 +1343,8 @@ public function configure_dovecot() {
13401343 }
13411344
13421345 $ config_dir = $ conf ['postfix ' ]['config_dir ' ];
1346+ $ postfix_version = `postconf -d mail_version 2>/dev/null `;
1347+ $ postfix_version = preg_replace ( '/mail_version\s*=\s*(.*)\s*/ ' , '$1 ' , $ postfix_version );
13431348
13441349 //* Configure master.cf and add a line for deliver
13451350 if (!$ this ->get_postfix_service ('dovecot ' , 'unix ' )) {
@@ -1351,7 +1356,7 @@ public function configure_dovecot() {
13511356 chmod ($ config_dir .'/master.cf~2 ' , 0400 );
13521357 }
13531358 //* Configure master.cf and add a line for deliver
1354- $ content = rf ($ conf [ " postfix " ][ " config_dir " ] .'/master.cf ' );
1359+ $ content = rf ($ config_dir .'/master.cf ' );
13551360 $ deliver_content = 'dovecot unix - n n - - pipe ' ."\n" .' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop} ' ."\n" ;
13561361 af ($ config_dir .'/master.cf ' , $ deliver_content );
13571362 unset($ content );
@@ -1368,7 +1373,31 @@ public function configure_dovecot() {
13681373 );
13691374
13701375 // Make a backup copy of the main.cf file
1371- copy ($ conf ['postfix ' ]['config_dir ' ].'/main.cf ' , $ conf ['postfix ' ]['config_dir ' ].'/main.cf~3 ' );
1376+ copy ($ config_dir .'/main.cf ' , $ config_dir .'/main.cf~3 ' );
1377+
1378+ $ options = explode (", " , exec ("postconf -h smtpd_recipient_restrictions " ));
1379+ $ new_options = array ();
1380+ foreach ($ options as $ value ) {
1381+ if (($ value = trim ($ value )) == '' ) continue ;
1382+ if (preg_match ("|check_recipient_access\s+proxy:mysql: $ {config_dir}/mysql-verify_recipients.cf| " , $ value )) {
1383+ continue ;
1384+ }
1385+ $ new_options [] = $ value ;
1386+ }
1387+ if ($ configure_lmtp ) {
1388+ for ($ i = 0 ; isset ($ new_options [$ i ]); $ i ++) {
1389+ if ($ new_options [$ i ] == 'reject_unlisted_recipient ' ) {
1390+ array_splice ($ new_options , $ i +1 , 0 , array ("check_recipient_access proxy:mysql: $ {config_dir}/mysql-verify_recipients.cf " ));
1391+ break ;
1392+ }
1393+ }
1394+ # postfix < 3.3 needs this when using reject_unverified_recipient:
1395+ if (version_compare ($ postfix_version , 3.3 , '< ' )) {
1396+ $ postconf_commands [] = "enable_original_recipient = yes " ;
1397+ }
1398+ }
1399+ #exec("postconf -e 'smtpd_recipient_restrictions = ".implode(", ", $new_options)."'");
1400+ $ postconf_commands [] = "smtpd_recipient_restrictions = " .implode (", " , $ new_options );
13721401
13731402 // Executing the postconf commands
13741403 foreach ($ postconf_commands as $ cmd ) {
@@ -1608,12 +1637,15 @@ public function configure_rspamd() {
16081637
16091638 exec ("postconf -e 'smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf, permit_mynetworks, permit_sasl_authenticated' " );
16101639
1640+
1641+ $ options = explode (", " , exec ("postconf -h smtpd_recipient_restrictions " ));
16111642 $ new_options = array ();
1612- $ options = preg_split ("/,\s*/ " , exec ("postconf -h smtpd_recipient_restrictions " ));
16131643 foreach ($ options as $ value ) {
1614- if (!preg_match ('/check_policy_service\s+inet:127.0.0.1:10023/ ' , $ value )) {
1615- $ new_options [] = $ value ;
1644+ if (($ value = trim ($ value )) == '' ) continue ;
1645+ if (preg_match ('/check_policy_service\s+inet:127.0.0.1:10023/ ' , $ value )) {
1646+ continue ;
16161647 }
1648+ $ new_options [] = $ value ;
16171649 }
16181650 exec ("postconf -e 'smtpd_recipient_restrictions = " .implode (", " , $ new_options )."' " );
16191651
0 commit comments