File: /usr/sbin/autoresponder
#!/usr/bin/perl
# mailbot.pl -- a simple mailbot program
# By Chris Candreva <chris@westnet.com>
# Stardate 0709.95
#
# This program is now public domain, copy it, change it, do whatever you
# want with it. If you add features, I would like to know about them.
#
# usage: autoresponder mailfile
#
# This is usually placed in a sendmail aliases file, such as the following:
#
# support: chris, "|/usr/local/bin/autoresponder /home/chris/techmail.txt"
#
# Put any real people who should also receive the mail in front.
# The mailfile should start as follows:
#
# From: Ihr Name <username@domainname.de>
# Subject: Die Betreffzeile der Antwortemail
# <EINE LEERE ZEILE>
# Hier beginnt der Inhalt der eMail - bis zum Ende der Datei.
#
#
# Modifications: catch and discard anything coming from the
# MAILER-DAEMON. Tobias Kreidl, Computing Tech. Servicess,
# Northern Arizona University (Tobias.Kreidl@nau.edu) 97-Apr-02
#
# Modifications: junk|bulk|list checking, renaming and l10n for germany
# Jimmy @ hostNET Medien GmbH www.hostnet.de 01-Apr-18
#
# Modifications: Path modifications for freeBSD
# Jimmy @ hostNET Medien GmbH www.hostnet.de 12-Dec-20
#
unless ($ARGV[0]) {
open (OUT,"|/usr/bin/mail -s 'Fehler!' postmaster");
print OUT "Sie haben einen falsch konfigurierten Autoresponder. Bitte korrigieren.\n\n\n";
close OUT;
exit 1;
}
$mailfile = $ARGV[0];
$md="";
$bulk="";
my $autoreply = '';
while(<STDIN>) {
if (s/^From: //) {
s/[\012\015]|^ *//g; #Remove all CR and LF
# check for MAILER-DAEMON
/(.*)MAILER-DAEMON?/ && ($md=$1) || /(.*)mailer-daemon?/ && ($md=$1);
if ($md ne ""){
# print "Received from MAILER-DAEMON\n"; # debug
close STDIN; # force I/O to terminate nicely
exit 0;
}
$to = $_;
open (IN, $mailfile );
#Read and display FROM line.
$_ = <IN>;
$autoreply .= $_;
$autoreply .= "Precedence: bulk\n";
$autoreply .= "To: $to\n";
$autoreply .= qq~Content-Transfer-Encoding: 8bit\n~;
$autoreply .= qq~Content-Type: text/plain; charset="utf-8\n~;
while (<IN>) { $autoreply .= $_; }
close IN;
}
if (s/^Precedence: //) {
s/[\012\015]|^ *//g; #Remove all CR and LF
# check for Bulk types
$bulk=1 if /(junk|bulk|list)/i;
if ($bulk){
# print "Received as Bulk,Junk or List\n"; # debug
close STDIN; # force I/O to terminate nicely
`/bin/rm -rf $$`;
exit 0;
}
}
}
open (OUT, "|/usr/sbin/sendmail -oi -t");
print OUT $autoreply;
close OUT;
exit 0;