]> xenbits.xensource.com Git - people/aperard/emesinae.git/commitdiff
control.pl: do not reply to the list if the message contained no valid commands
authorIan Campbell <ian.campbell@citrix.com>
Fri, 4 Apr 2014 15:26:14 +0000 (16:26 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 4 Apr 2014 15:26:14 +0000 (16:26 +0100)
This suppresses a certain amount of SPAM.

scripts/control.pl

index 42f20e0b972fa33365d928f9c527c0ab3ca96df0..31bfe07caef6ccf4b202a4b054050bb7f4aea803 100755 (executable)
@@ -58,7 +58,7 @@ our $dbh = opendb();
 
 sub genreply ($$@) {
     my $head    = shift;
-    my $success = shift;
+    my $nrvalid = shift; # number of valid commands.
 
     my @content = @_;
 
@@ -89,11 +89,11 @@ sub genreply ($$@) {
 
     # Send reply to:
     #   - Requester (optionally)
-    #   - The list (only if successfully processed)
+    #   - The list (only if successfully processed at least one command)
     #   - Dist list (optionally)
     push @to_field, $request_from
       if $c{ControlReplyToRequestor} and $request_from;
-    push @to_field, $c{ListAddress} if $c{ControlReplyToList} and $success;
+    push @to_field, $c{ListAddress} if $c{ControlReplyToList} and $nrvalid > 0;
     push @bcc_field, $c{ControlDistAddress} if $c{ControlDistAddress};
 
     my $msubject = "Processed: " . $head->get('subject');
@@ -119,9 +119,10 @@ sub genreply ($$@) {
 
         'X-Emesinae-Message:'      => "control",
         'X-Emesinae-Control-From:' => $request_from,
+        'X-Emesinae-Control-Number-Commands:' => $nrvalid,
     );
 
-    if ($success) {
+    if ($nrvalid > 0) {
 
         # Insert both control and reply messages into DB with the correct type.
         my $mcontrol =
@@ -441,6 +442,7 @@ if (@errors) {
 push @reply, "Processing commands for " . $c{ControlAddressFull} . ":";
 push @reply, "";
 
+my $nrcommands = 0;
 while (<$body>) {
     chomp();
     push @reply, "> $_";
@@ -455,6 +457,7 @@ while (<$body>) {
         $cmds{$1} or die "Unknown command `$1'.";
         validate_from($1) if $cmds{$1}{Priv};
         $cmds{$1}{Cmd}($2) or $done = 1;
+        $nrcommands++;
     };
     if ($@) {
         chomp($@);
@@ -486,7 +489,7 @@ push @reply,
     "Contact " . $c{OwnerAddressFull} . " with any infrastructure issues",
   );
 
-spool_reply( genreply( $head, 1, @reply ) );
+spool_reply( genreply( $head, $nrcommands, @reply ) );
 
 exit(0);