Hi Laurent,
take a look on this code
Code
- sub _modifyPostfixMainConfig($$)
- {
- my ($self, $action) = @_;
- my ($rs, $stdout, $stderr);
- $rs = execute('postconf smtpd_milters', \$stdout, \$stderr);
- debug($stdout) if $stdout;
- error($stderr) if $stderr && $rs;
- return $rs if $rs;
- my $smtpdMiltersOutput = $stdout;
- $rs = execute('postconf non_smtpd_milters', \$stdout, \$stderr);
- debug($stdout) if $stdout;
- error($stderr) if $stderr && $rs;
- return $rs if $rs;
- my $nonSmtpdMiltersOutput = $stdout;
- if($action eq 'add') {
- #Set milter_default_action to accept
- $rs = execute('postconf -e "milter_default_action = accept"', \$stdout, \$stderr);
- debug($stdout) if $stdout;
- error($stderr) if $stderr && $rs;
- return $rs if $rs;
- # Check the port is numeric and has min. 4 and max. 5 digits
- if($self->{'config'}->{'opendkim_port'} =~ /\d{4,5}/ && $self->{'config'}->{'opendkim_port'} <= 65535) {
- $rs = execute('postconf -e "' . $smtpdMiltersOutput . ' inet:localhost:' . $self->{'config'}->{'opendkim_port'} . '"', \$stdout, \$stderr);
- debug($stdout) if $stdout;
- error($stderr) if $stderr && $rs;
- return $rs if $rs;
- } else {
- $rs = execute('postconf -e "' . $smtpdMiltersOutput . ' inet:localhost:12345"', \$stdout, \$stderr);
- debug($stdout) if $stdout;
- error($stderr) if $stderr && $rs;
- return $rs if $rs;
- }
- if($nonSmtpdMiltersOutput !~ /\$smtpd_milters/) {
- $rs = execute('postconf -e "non_smtpd_milters = \$smtpd_milters"'), \$stdout, \$stderr);
- debug($stdout) if $stdout;
- error($stderr) if $stderr && $rs;
- return $rs if $rs;
- }
- }
- elsif($action eq 'remove') {
- # Check the port is numeric and has min. 4 and max. 5 digits
- if($self->{'config'}->{'opendkim_port'} =~ /\d{4,5}/ && $self->{'config'}->{'opendkim_port'} <= 65535) {
- $smtpdMiltersOutput =~ s/\s?inet:localhost:$self->{'config'}->{'opendkim_port'}//g;
- $rs = execute('postconf -e "' . $smtpdMiltersOutput . '"', \$stdout, \$stderr);
- debug($stdout) if $stdout;
- error($stderr) if $stderr && $rs;
- return $rs if $rs;
- } else {
- $smtpdMiltersOutput =~ s/\s?inet:localhost:12345//g;
- $rs = execute('postconf -e "' . $smtpdMiltersOutput . '"', \$stdout, \$stderr);
- debug($stdout) if $stdout;
- error($stderr) if $stderr && $rs;
- return $rs if $rs;
- }
- }
- }