@@ -864,7 +864,7 @@ public function get_postfix_service($service, $type) {
864864 exec ("postconf -M $ service. $ type 2> /dev/null " , $ out , $ ret );
865865 }
866866 $ postfix_service = @($ out [0 ]=='' )?false :true ;
867- } else { //* fallback - Postfix < 2.9
867+ } else { //* fallback - Postfix < 2.9
868868 $ content = rf ($ conf ['postfix ' ]['config_dir ' ].'/master.cf ' );
869869 $ regex = "/^((?!#) " .$ service .".* " .$ type .".*)$/m " ;
870870 $ postfix_service = @(preg_match ($ regex , $ content ))?true :false ;
@@ -873,6 +873,68 @@ public function get_postfix_service($service, $type) {
873873 return $ postfix_service ;
874874 }
875875
876+ public function remove_postfix_service ( $ service , $ type ) {
877+ global $ conf ;
878+
879+ // nothing to do if the service isn't even defined.
880+ if (! $ this ->get_postfix_service ( $ service , $ type ) ) {
881+ return true ;
882+ }
883+
884+ $ postfix_version = `postconf -d mail_version 2>/dev/null `;
885+ $ postfix_version = preg_replace ( '/mail_version\s*=\s*(.*)\s*/ ' , '$1 ' , $ postfix_version );
886+
887+ if ( version_compare ( $ postfix_version , '2.11 ' , '>= ' ) ) {
888+
889+ exec ("postconf -X -M $ service/ $ type 2> /dev/null " , $ out , $ ret );
890+
891+ # reduce 3 or more newlines to 2
892+ $ content = rf ($ conf ['postfix ' ]['config_dir ' ].'/master.cf ' );
893+ $ content = preg_replace ( '/(\r?\n){3,}/ ' , '$1$1 ' , $ content );
894+ wf ( $ conf ['postfix ' ]['config_dir ' ].'/master.cf ' , $ content );
895+
896+ } else { //* fallback - Postfix < 2.11
897+
898+ if ( ! $ cf = fopen ( $ conf ['postfix ' ]['config_dir ' ].'/master.cf ' , 'r ' ) ) {
899+ return false ;
900+ }
901+
902+ $ out = "" ;
903+ $ reading_service = false ;
904+
905+ while ( !feof ( $ cf ) ) {
906+ $ line = fgets ( $ cf );
907+
908+ if ( $ reading_service ) {
909+ # regex matches a new service or "empty" (whitespace) line
910+ if ( preg_match ( '/^([^\s#]+.*|\s*)$/ ' , $ line ) &&
911+ ! preg_match ( '/^ ' .$ service .'\s+ ' .$ type .'/ ' , $ line ) ) {
912+ $ out .= $ line ;
913+ $ reading_service = false ;
914+ }
915+
916+ # $skipped_lines .= $line;
917+
918+ # regex matches definition matching service to be removed
919+ } else if ( preg_match ( '/^ ' .$ service .'\s+ ' .$ type .'/ ' , $ line ) ) {
920+
921+ $ reading_service = true ;
922+ # $skipped_lines .= $line;
923+
924+ } else {
925+ $ out .= $ line ;
926+ }
927+ }
928+ fclose ( $ cf );
929+
930+ $ out = preg_replace ( '/(\r?\n){3,}/ ' , '$1$1 ' , $ out ); # reduce 3 or more newlines to 2
931+
932+ return wf ( $ conf ['postfix ' ]['config_dir ' ].'/master.cf ' , $ out );
933+ }
934+
935+ return true ;
936+ }
937+
876938 public function configure_postfix ($ options = '' ) {
877939 global $ conf ,$ autoinstall ;
878940 $ cf = $ conf ['postfix ' ];
@@ -927,17 +989,26 @@ public function configure_postfix($options = '') {
927989 //* mysql-virtual_uids.cf
928990 $ this ->process_postfix_config ('mysql-virtual_uids.cf ' );
929991
992+ // test if lmtp if available
993+ $ configure_lmtp = $ this ->get_postfix_service ('lmtp ' ,'unix ' );
994+
930995 //* postfix-dkim
931996 $ filename ='tag_as_originating.re ' ;
932997 $ full_file_name =$ config_dir .'/ ' .$ filename ;
933998 if (is_file ($ full_file_name )) copy ($ full_file_name , $ full_file_name .'~ ' );
934999 $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/postfix- ' .$ filename .'.master ' , 'tpl/postfix- ' .$ filename .'.master ' );
1000+ if ($ configure_lmtp ) {
1001+ $ content = preg_replace ('/amavis:/ ' , 'lmtp: ' , $ content );
1002+ }
9351003 wf ($ full_file_name , $ content );
9361004
9371005 $ filename ='tag_as_foreign.re ' ;
9381006 $ full_file_name =$ config_dir .'/ ' .$ filename ;
9391007 if (is_file ($ full_file_name )) copy ($ full_file_name , $ full_file_name .'~ ' );
9401008 $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/postfix- ' .$ filename .'.master ' , 'tpl/postfix- ' .$ filename .'.master ' );
1009+ if ($ configure_lmtp ) {
1010+ $ content = preg_replace ('/amavis:/ ' , 'lmtp: ' , $ content );
1011+ }
9411012 wf ($ full_file_name , $ content );
9421013
9431014 //* Changing mode and group of the new created config files.
@@ -1233,11 +1304,16 @@ public function configure_courier() {
12331304
12341305 public function configure_dovecot () {
12351306 global $ conf ;
1236-
1307+
12371308 $ virtual_transport = 'dovecot ' ;
12381309
12391310 $ configure_lmtp = false ;
1240-
1311+
1312+ // use lmtp if installed
1313+ if ($ configure_lmtp = is_file ('/usr/lib/dovecot/lmtp ' )) {
1314+ $ virtual_transport = 'lmtp:unix:private/dovecot-lmtp ' ;
1315+ }
1316+
12411317 // check if virtual_transport must be changed
12421318 if ($ this ->is_update ) {
12431319 $ tmp = $ this ->db ->queryOneRecord ("SELECT * FROM ?? WHERE server_id = ? " , $ conf ["mysql " ]["database " ] . ".server " , $ conf ['server_id ' ]);
@@ -1347,7 +1423,7 @@ public function configure_dovecot() {
13471423 }
13481424 //remove #2.3+ comment
13491425 $ content = file_get_contents ($ config_dir .'/ ' .$ configfile );
1350- $ content = str_replace ('#2.3+ ' ,'' ,$ content );
1426+ $ content = str_replace ('#2.3+ ' ,'' ,$ content );
13511427 file_put_contents ($ config_dir .'/ ' .$ configfile ,$ content );
13521428 unset($ content );
13531429
@@ -1358,11 +1434,20 @@ public function configure_dovecot() {
13581434 }
13591435 }
13601436
1437+ $ dovecot_protocols = 'imap pop3 ' ;
1438+
13611439 //* dovecot-lmtpd
13621440 if ($ configure_lmtp ) {
1363- replaceLine ($ config_dir .'/ ' .$ configfile , 'protocols = imap pop3 ' , 'protocols = imap pop3 lmtp ' , 1 , 0 );
1441+ $ dovecot_protocols .= ' lmtp ' ;
1442+ }
1443+
1444+ //* dovecot-managesieved
1445+ if (is_file ('/usr/lib/dovecot/managesieve ' )) {
1446+ $ dovecot_protocols .= ' sieve ' ;
13641447 }
13651448
1449+ replaceLine ($ config_dir .'/ ' .$ configfile , 'protocols = imap pop3 ' , "protocols = $ dovecot_protocols " , 1 , 0 );
1450+
13661451 //* dovecot-sql.conf
13671452 $ configfile = 'dovecot-sql.conf ' ;
13681453 if (is_file ($ config_dir .'/ ' .$ configfile )) {
@@ -1409,14 +1494,17 @@ public function configure_amavis() {
14091494
14101495 // TODO: chmod and chown on the config file
14111496
1497+ // test if lmtp if available
1498+ $ configure_lmtp = $ this ->get_postfix_service ('lmtp ' ,'unix ' );
14121499
14131500 // Adding the amavisd commands to the postfix configuration
14141501 // Add array for no error in foreach and maybe future options
14151502 $ postconf_commands = array ();
14161503
14171504 // Check for amavisd -> pure webserver with postfix for mailing without antispam
14181505 if ($ conf ['amavis ' ]['installed ' ]) {
1419- $ postconf_commands [] = 'content_filter = amavis:[127.0.0.1]:10024 ' ;
1506+ $ content_filter_service = ($ configure_lmtp ) ? 'lmtp ' : 'amavis ' ;
1507+ $ postconf_commands [] = "content_filter = $ {content_filter_service}:[127.0.0.1]:10024 " ;
14201508 $ postconf_commands [] = 'receive_override_options = no_address_mappings ' ;
14211509 }
14221510
@@ -1432,11 +1520,16 @@ public function configure_amavis() {
14321520 $ config_dir = $ conf ['postfix ' ]['config_dir ' ];
14331521
14341522 // Adding amavis-services to the master.cf file if the service does not already exists
1435- $ add_amavis = !$ this ->get_postfix_service ('amavis ' ,'unix ' );
1436- $ add_amavis_10025 = !$ this ->get_postfix_service ('127.0.0.1:10025 ' ,'inet ' );
1437- $ add_amavis_10027 = !$ this ->get_postfix_service ('127.0.0.1:10027 ' ,'inet ' );
1523+ // $add_amavis = !$this->get_postfix_service('amavis','unix');
1524+ // $add_amavis_10025 = !$this->get_postfix_service('127.0.0.1:10025','inet');
1525+ // $add_amavis_10027 = !$this->get_postfix_service('127.0.0.1:10027','inet');
14381526 //*TODO: check templates against existing postfix-services to make sure we use the template
14391527
1528+ // Or just remove the old service definitions and add them again?
1529+ $ add_amavis = $ this ->remove_postfix_service ('amavis ' ,'unix ' );
1530+ $ add_amavis_10025 = $ this ->remove_postfix_service ('127.0.0.1:10025 ' ,'inet ' );
1531+ $ add_amavis_10027 = $ this ->remove_postfix_service ('127.0.0.1:10027 ' ,'inet ' );
1532+
14401533 if ($ add_amavis || $ add_amavis_10025 || $ add_amavis_10027 ) {
14411534 //* backup master.cf
14421535 if (is_file ($ config_dir .'/master.cf ' )) copy ($ config_dir .'/master.cf ' , $ config_dir .'/master.cf~ ' );
0 commit comments