[Mimedefang] [patch] make notify_administrator work in non-message context

Dirk Mueller dmuell at gmx.net
Fri Jun 27 20:28:00 EDT 2003


Hi, 

for various reasons I'd like to conveniently notify myself of unexpected 
conditions that happen in filter_relay() or filter_recipient(). 

Unfortunately, I noticed that notify_administrator doesn't work here. Below 
a patch to fix it - can this be included, please?

Thanks,



-- 
Dirk
-------------- next part --------------
--- mimedefang.pl.in	2003-06-03 21:51:36.000000000 +0200
+++ /tmp/mimedefang.pl.in	2003-06-27 22:48:45.000000000 +0200
@@ -1148,7 +1148,10 @@
 #***********************************************************************
 sub action_notify_administrator ($) {
     my($msg) = @_;
-    return 0 if (!in_message_context("action_notify_administrator"));
+    if (!$InMessageContext) {
+	send_admin_mail($NotifyAdministratorSubject, $msg);
+        return 1;
+    }
     if (open(FILE, ">>ADMIN_NOTIFICATION")) {
 	print FILE $msg;
 	close(FILE);
@@ -1374,19 +1375,12 @@
 
     # Send notification to administrator, if required
     if (-r "ADMIN_NOTIFICATION") {
-	my($body);
-	$body = "From: $DaemonName <$DaemonAddress>\n";
-	$body .= "To: \"$AdminName\" <$AdminAddress>\n";
-	$body .= gen_date_msgid_headers();
-	$body .= "MIME-Version: 1.0\nContent-Type: text/plain\n";
-	$body .= "Subject: $NotifyAdministratorSubject\n\n";
+	my $body = "";
 	if (open(FILE, "<ADMIN_NOTIFICATION")) {
-	    while(<FILE>) {
-		$body .= $_;
-	    }
-	    close(FILE);
-	}
-	send_mail($DaemonAddress, $DaemonName, $AdminAddress, $body);
+            $body .= join('', <FILE>);
+            close(FILE);
+	    send_admin_mail($NotifyAdministratorSubject, $body);
+        }
     }
 
     # Syslog some info if any actions were taken
@@ -1559,6 +1553,31 @@
 }
 
 #***********************************************************************
+# %PROCEDURE: send_admin_mail
+# %ARGUMENTS:
+#  subject -- mail subject
+#  body -- mail message (without headers) newline-terminated
+# %RETURNS:
+#  Nothing
+# %DESCRIPTION:
+#  Sends a mail message to the administrator
+#***********************************************************************
+sub send_admin_mail($$) {
+
+    my ($subject, $body) = @_;
+
+    my $mail;
+    $mail = "From: $DaemonName <$DaemonAddress>\n";
+    $mail .= "To: \"$AdminName\" <$AdminAddress>\n";
+    $mail .= gen_date_msgid_headers();
+    $mail .= "MIME-Version: 1.0\nContent-Type: text/plain\n";
+    $mail .= "Subject: $subject\n\n";
+    $mail .= $body;
+
+    send_mail($DaemonAddress, $DaemonName, $AdminAddress, $mail);
+}
+
+#***********************************************************************
 # %PROCEDURE: resend_message_specifying_mode
 # %ARGUMENTS:
 #  deliverymode -- delivery mode


More information about the MIMEDefang mailing list