Option to not forward bounce email, on by default
authorJamie Cameron <jcameron@webmin.com>
Thu, 23 Dec 2010 01:40:08 +0000 (17:40 -0800)
committerJamie Cameron <jcameron@webmin.com>
Thu, 23 Dec 2010 01:40:08 +0000 (17:40 -0800)
filter/CHANGELOG
filter/edit.cgi
filter/filter-lib.pl
filter/lang/en
filter/save.cgi
filter/save_forward.cgi

index dee075a..a64f716 100644 (file)
@@ -30,3 +30,5 @@ Autoreply messages starting with <html> or <body> will now be sent using the tex
 Quick autoreply and forward setup pages now only show un-conditional rules.
 ---- Changes since 1.450 ----
 Added option to select the character set of automatic reply messages.
+---- Changes since 1.460 ----
+Added a checkbox (on by default) to not forward bounce emails, which can cause mail loops.
index 05617c6..41e9f95 100755 (executable)
@@ -8,7 +8,8 @@ require './filter-lib.pl';
 # Show page header and get the filter
 if ($in{'new'}) {
        &ui_print_header(undef, $text{'edit_title1'}, "");
-       $filter = { 'actiondefault' => 1 };
+       $filter = { 'actiondefault' => 1,
+                   'nobounce' => 1 };
        if ($in{'header'}) {
                # Initial filter is based on URL params
                $filter->{'condheader'} = $in{'header'};
@@ -145,7 +146,10 @@ print &ui_table_row(
 print &ui_table_row(
        &ui_oneradio("amode", 1, $text{'edit_amode1'}, $amode == 1),
        &ui_textarea("forward", $amode == 1 ?
-               join("\n", split(/,/, $filter->{'action'})) : "", 3, 70),
+               join("\n", split(/,/, $filter->{'action'})) : "", 3, 70).
+       "<br>\n".
+       &ui_checkbox("nobounce", 1, $text{'edit_nobounce'},
+                    $filter->{'nobounce'}),
        undef, \@tds);
 
 # Save to a folder or file
index 3926162..944d702 100755 (executable)
@@ -65,19 +65,27 @@ local @rv;
 local @pmrc = &procmail::parse_procmail_file($file || $procmail::procmailrc);
 foreach my $r (@pmrc) {
        # Check for un-supported recipes
-       if (@{$r->{'conds'}} > 1 ||
-           $r->{'block'} ||
-           $r->{'name'}) {
+       local @conds = @{$r->{'conds'}};
+       if ($r->{'block'} || $r->{'name'}) {
                next;
                }
 
        # Check for flags
        local %flags = map { $_, 1 } @{$r->{'flags'}};
 
+       # Check for bounce condition
+       local $nobounce;
+       if (@conds && $conds[0]->[0] eq '!' &&
+           $conds[0]->[1] =~ /FROM_MAILER/) {
+               $nobounce = 1;
+               shift(@conds);
+               }
+       next if (@conds > 1);   # Multiple conditions are not supported
+
        # Work out condition type
        local ($condtype, $cond);
-       if (@{$r->{'conds'}}) {
-               ($condtype, $cond) = @{$r->{'conds'}->[0]};
+       if (@conds) {
+               ($condtype, $cond) = @{$conds[0]};
                if ($condtype && $condtype ne "<" && $condtype ne ">") {
                        # Unsupported conditon type
                        next;
@@ -110,6 +118,7 @@ foreach my $r (@pmrc) {
                          'continue' => $flags{'c'},
                          'actiontype' => $r->{'type'},
                          'action' => $r->{'action'},
+                         'nobounce' => $nobounce,
                          'index' => scalar(@rv),
                          'recipe' => $r };
 
@@ -236,7 +245,6 @@ elsif ($filter->{'condtype'} eq '<' || $filter->{'condtype'} eq '>') {
 elsif ($filter->{'cond'}) {
        @conds = ( [ "", $filter->{'cond'} ] );
        }
-$recipe->{'conds'} = \@conds;
 
 # Set action section
 if ($filter->{'actionspam'}) {
@@ -268,7 +276,12 @@ else {
                # Enable locking for file delivery
                $recipe->{'lockfile'} ||= "";
                }
+       if ($filter->{'actiontype'} eq '!' && $filter->{'nobounce'}) {
+               # Add condition to suppress forwarding of bounces
+               unshift(@conds, [ '!', '^FROM_MAILER' ]);
+               }
        }
+$recipe->{'conds'} = \@conds;
 
 # Set flags
 push(@flags, "B") if ($filter->{'body'});
index c54f462..35bdb08 100644 (file)
@@ -65,6 +65,7 @@ edit_file=Other file..
 edit_continue=Continue with other filter rules, even after applying this action
 edit_amode6=Send automatic reply
 edit_amode7=Save to new folder named
+edit_nobounce=Suppress forwarding of bouce messages
 
 save_err=Failed to save filter
 save_econdheader=Missing or invalid email header
index bbdcfc9..bba54c9 100755 (executable)
@@ -106,6 +106,7 @@ else {
                $in{'forward'} =~ s/\s+/,/g;
                $filter->{'action'} = $in{'forward'};
                $filter->{'actiontype'} = '!';
+               $filter->{'nobounce'} = $in{'nobounce'};
                }
        elsif ($in{'amode'} == 0) {
                # Write to a folder or file
index a4828cf..b03d53a 100755 (executable)
@@ -19,7 +19,8 @@ elsif ($in{'enabled'}) {
        # Create or update
        if (!$filter) {
                $filter = { 'actiontype' => '!',
-                           'body' => 0 };
+                           'body' => 0,
+                           'nobounce' => 1 };
                }
        $filter->{'continue'} = $in{'continue'};
        $in{'forward'} =~ /\S/ || &error($text{'save_eforward'});