@@ -876,8 +876,8 @@ public function get_postfix_service($service, $type) {
876876 $ postfix_service = @($ out [0 ]=='' )?false :true ;
877877 } else { //* fallback - Postfix < 2.9
878878 $ content = rf ($ conf ['postfix ' ]['config_dir ' ].'/master.cf ' );
879- $ regex = "/ ^((?!#) " .$ service .".* " .$ type .".*)$/m " ;
880- $ postfix_service = @(preg_match ($ regex , $ content ))?true :false ;
879+ $ quoted_regex = "^((?!#) " .preg_quote ( $ service, ' / ' ) .".* " .preg_quote ( $ type, ' / ' ) .".*)$ " ;
880+ $ postfix_service = @(preg_match (" / $ quoted_regex /m " , $ content ))?true :false ;
881881 }
882882
883883 return $ postfix_service ;
@@ -915,18 +915,19 @@ public function remove_postfix_service( $service, $type ) {
915915 while ( !feof ( $ cf ) ) {
916916 $ line = fgets ( $ cf );
917917
918+ $ quoted_regex = '^ ' .preg_quote ($ service , '/ ' ).'\s+ ' .preg_quote ($ type , '/ ' );
918919 if ( $ reading_service ) {
919920 # regex matches a new service or "empty" (whitespace) line
920921 if ( preg_match ( '/^([^\s#]+.*|\s*)$/ ' , $ line ) &&
921- ! preg_match ( ' /^ ' . $ service . ' \s+ ' . $ type . ' / ' , $ line ) ) {
922+ ! preg_match ( " / $ quoted_regex / " , $ line ) ) {
922923 $ out .= $ line ;
923924 $ reading_service = false ;
924925 }
925926
926927 # $skipped_lines .= $line;
927928
928929 # regex matches definition matching service to be removed
929- } else if ( preg_match ( ' /^ ' . $ service . ' \s+ ' . $ type . ' / ' , $ line ) ) {
930+ } else if ( preg_match ( " / $ quoted_regex / " , $ line ) ) {
930931
931932 $ reading_service = true ;
932933 # $skipped_lines .= $line;
@@ -960,6 +961,9 @@ public function configure_postfix($options = '') {
960961 //* mysql-virtual_forwardings.cf
961962 $ this ->process_postfix_config ('mysql-virtual_forwardings.cf ' );
962963
964+ //* mysql-virtual_alias_domains.cf
965+ $ this ->process_postfix_config ('mysql-virtual_alias_domains.cf ' );
966+
963967 //* mysql-virtual_mailboxes.cf
964968 $ this ->process_postfix_config ('mysql-virtual_mailboxes.cf ' );
965969
@@ -999,6 +1003,9 @@ public function configure_postfix($options = '') {
9991003 //* mysql-virtual_uids.cf
10001004 $ this ->process_postfix_config ('mysql-virtual_uids.cf ' );
10011005
1006+ //* mysql-virtual_alias_domains.cf
1007+ $ this ->process_postfix_config ('mysql-verify_recipients.cf ' );
1008+
10021009 // test if lmtp if available
10031010 $ configure_lmtp = $ this ->get_postfix_service ('lmtp ' ,'unix ' );
10041011
@@ -1151,13 +1158,13 @@ public function configure_postfix($options = '') {
11511158 if (is_file ('/var/run/courier/authdaemon/ ' )) caselog ($ command .' &> /dev/null ' , __FILE__ , __LINE__ , 'EXECUTED: ' .$ command , 'Failed to execute the command ' .$ command );
11521159
11531160 //* Check maildrop service in posfix master.cf
1154- $ regex = " / ^maildrop unix.*pipe flags=DRhu user=vmail argv=\\ /usr \\ /bin \\ /maildrop -d " .$ cf ['vmail_username ' ]." \\ $\ {extension} \\ $\ {recipient} \\ $\ {user} \\ $\ {nexthop} \\ $\ {sender}/ " ;
1161+ $ quoted_regex = ' ^maildrop unix.*pipe flags=DRhu user=vmail ' . preg_quote ( ' argv=/usr/bin/maildrop -d ' .$ cf ['vmail_username ' ].' $ {extension} $ {recipient} $ {user} $ {nexthop} $ {sender}' , ' / ' ) ;
11551162 $ configfile = $ config_dir .'/master.cf ' ;
11561163 if ($ this ->get_postfix_service ('maildrop ' , 'unix ' )) {
11571164 exec ("postconf -M maildrop.unix 2> /dev/null " , $ out , $ ret );
1158- $ change_maildrop_flags = @(preg_match ($ regex , $ out [0 ]) && $ out [0 ] !='' )?false :true ;
1165+ $ change_maildrop_flags = @(preg_match (" / $ quoted_regex / " , $ out [0 ]) && $ out [0 ] !='' )?false :true ;
11591166 } else {
1160- $ change_maildrop_flags = @(preg_match ($ regex , $ configfile ))?false :true ;
1167+ $ change_maildrop_flags = @(preg_match (" / $ quoted_regex / " , $ configfile ))?false :true ;
11611168 }
11621169 if ($ change_maildrop_flags ) {
11631170 //* Change maildrop service in posfix master.cf
@@ -1337,6 +1344,9 @@ public function configure_dovecot() {
13371344 }
13381345
13391346 $ config_dir = $ conf ['postfix ' ]['config_dir ' ];
1347+ $ quoted_config_dir = preg_quote ($ config_dir , '/ ' );
1348+ $ postfix_version = `postconf -d mail_version 2>/dev/null `;
1349+ $ postfix_version = preg_replace ( '/mail_version\s*=\s*(.*)\s*/ ' , '$1 ' , $ postfix_version );
13401350
13411351 //* Configure master.cf and add a line for deliver
13421352 if (!$ this ->get_postfix_service ('dovecot ' , 'unix ' )) {
@@ -1348,7 +1358,7 @@ public function configure_dovecot() {
13481358 chmod ($ config_dir .'/master.cf~2 ' , 0400 );
13491359 }
13501360 //* Configure master.cf and add a line for deliver
1351- $ content = rf ($ conf [ " postfix " ][ " config_dir " ] .'/master.cf ' );
1361+ $ content = rf ($ config_dir .'/master.cf ' );
13521362 $ deliver_content = 'dovecot unix - n n - - pipe ' ."\n" .' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop} ' ."\n" ;
13531363 af ($ config_dir .'/master.cf ' , $ deliver_content );
13541364 unset($ content );
@@ -1365,7 +1375,32 @@ public function configure_dovecot() {
13651375 );
13661376
13671377 // Make a backup copy of the main.cf file
1368- copy ($ conf ['postfix ' ]['config_dir ' ].'/main.cf ' , $ conf ['postfix ' ]['config_dir ' ].'/main.cf~3 ' );
1378+ copy ($ config_dir .'/main.cf ' , $ config_dir .'/main.cf~3 ' );
1379+
1380+ $ options = preg_split ("/,\s*/ " , exec ("postconf -h smtpd_recipient_restrictions " ));
1381+ $ new_options = array ();
1382+ foreach ($ options as $ value ) {
1383+ $ value = trim ($ value );
1384+ if ($ value == '' ) continue ;
1385+ if (preg_match ("|check_recipient_access\s+proxy:mysql: $ {quoted_config_dir}/mysql-verify_recipients.cf| " , $ value )) {
1386+ continue ;
1387+ }
1388+ $ new_options [] = $ value ;
1389+ }
1390+ if ($ configure_lmtp ) {
1391+ for ($ i = 0 ; isset ($ new_options [$ i ]); $ i ++) {
1392+ if ($ new_options [$ i ] == 'reject_unlisted_recipient ' ) {
1393+ array_splice ($ new_options , $ i +1 , 0 , array ("check_recipient_access proxy:mysql: $ {config_dir}/mysql-verify_recipients.cf " ));
1394+ break ;
1395+ }
1396+ }
1397+ # postfix < 3.3 needs this when using reject_unverified_recipient:
1398+ if (version_compare ($ postfix_version , 3.3 , '< ' )) {
1399+ $ postconf_commands [] = "enable_original_recipient = yes " ;
1400+ }
1401+ }
1402+ #exec("postconf -e 'smtpd_recipient_restrictions = ".implode(", ", $new_options)."'");
1403+ $ postconf_commands [] = "smtpd_recipient_restrictions = " .implode (", " , $ new_options );
13691404
13701405 // Executing the postconf commands
13711406 foreach ($ postconf_commands as $ cmd ) {
@@ -1605,12 +1640,16 @@ public function configure_rspamd() {
16051640
16061641 exec ("postconf -e 'smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf, permit_mynetworks, permit_sasl_authenticated' " );
16071642
1608- $ new_options = array ();
1643+
16091644 $ options = preg_split ("/,\s*/ " , exec ("postconf -h smtpd_recipient_restrictions " ));
1645+ $ new_options = array ();
16101646 foreach ($ options as $ value ) {
1611- if (!preg_match ('/check_policy_service\s+inet:127.0.0.1:10023/ ' , $ value )) {
1612- $ new_options [] = $ value ;
1647+ $ value = trim ($ value );
1648+ if ($ value == '' ) continue ;
1649+ if (preg_match ('/check_policy_service\s+inet:127.0.0.1:10023/ ' , $ value )) {
1650+ continue ;
16131651 }
1652+ $ new_options [] = $ value ;
16141653 }
16151654 exec ("postconf -e 'smtpd_recipient_restrictions = " .implode (", " , $ new_options )."' " );
16161655
0 commit comments