#!/usr/local/bin/perl
# bouncer.pl
#
# Part of the ArsDigita MTA Monitor
#
# This script should be installed on the monitored system.  Its role is
# to reply to any incoming message.  It uses the system command
# mailx (1) to send email.  The Proper Perl Way would be to use
# Mail::Mailer module, but the task is so trivial that it really
# doesn't pay to install Mail::Mailer on every monitored server.

# CUSTOMIZATION

# You may have to rename "mailx" to "mail" below and set a
# path to the perl executable below.

## Grab the emailet_id from the subject line:
while (<>) {
    chop;
    if (/^$/) {last};         # Blank line means end of headers.
    s/^Subject: .*emailet_id=(.*)$/$1/ && ($emailet_id=$_);
    s/^From: .*<(.*)>.*$/$1/ && ($from=$_);  # The email address is either in angle brackets...
    s/^From: (.*)$/$1/ && ($from=$_);        # ... or alone
}

$to = $from;
$subject = '-sRe:\ ' . "emailet_id=$emailet_id";
system "mailx $subject $to";
