#!/opt/bin/perl # ######################################################################### # # # Program for storing e-mail problem reports with automatic receipt # # # ######################################################################### # # # Version 1.0 - Written 01.08.95 by Steffen Beyer # # # ######################################################################### # # # Copyright (C) 1995 by software design & management GmbH & Co. KG # # # ######################################################################### # # Some important default settings: # $version = 'Version 1.0'; # $self = $0; # if ($self =~ m!/([^/]+)$!) { $self = $1; } # # Define here the name of your mailbox (MUST be an ABSOLUTE path!!!): # $mailbox = '/u/sysadm/preport'; # $lockfile = "$mailbox.lock"; # $tempfile = "$mailbox.temp"; # $wait = "true"; # # Wait for semaphore: # while ($wait) { # # Wait for semaphore to be released (if set): # while (-f $lockfile) { sleep(5); } # # When semaphore is gone, create own one: # unless (open(LOCKFILE, ">>$lockfile")) { unlink($lockfile); die "Can't open semaphore for writing: $!\n"; } print LOCKFILE "$$\n"; close(LOCKFILE); # # Check wether semaphore is our's or was created # in the meantime by another copy of this process # unless (open(LOCKFILE, "<$lockfile")) { unlink($lockfile); die "Can't open semaphore for reading: $!\n"; } $_ = ; chop; close(LOCKFILE); # # Loop if semaphore isn't our's: # $wait = ($_ != $$); if ($wait) { warn "Semaphore access conflict detected!\n"; warn "Waiting for other process to terminate.\n"; } } # # Append incoming mail to mailbox and determine the sender's e-mail address: # $subject = ''; $reply_address = ''; $real_address = ''; $logic_address = ''; # unless (open(MAILBOX, ">>$mailbox")) { unlink($lockfile); die "Can't open mailbox for writing: $!\n"; } # while () { chop; print MAILBOX $_, "\n"; if (($reply_address eq '') && (/^Reply-To:\s+(\S+@\S+)/)) { $reply_address = $1; } if (($real_address eq '') && (/^From:\s+(\S+@\S+)/)) { $real_address = $1; } if (($logic_address eq '') && (/^From\s+(\S+@\S+)/)) { $logic_address = $1; } if (($subject eq '') && (/^Subject:\s+(.*)/)) { $subject = $1; } } # close(MAILBOX); # if ($reply_address eq $real_address) { $real_address = ''; } if (($reply_address eq $logic_address) || ($real_address eq $logic_address)) { $logic_address = ''; } # # If address was found and no error abort so far, send acknowledgement mail: # if (($reply_address ne '') || ($real_address ne '') || ($logic_address ne '')) { unless (open(TEMPFILE, ">$tempfile")) { unlink($tempfile); unlink($lockfile); die "Can't open tempfile for writing: $!\n"; } # print TEMPFILE "From: sysadm@bi.sdm.de\n"; if ($reply_address ne '') { print TEMPFILE "To: $reply_address\n"; if ($real_address ne '') { if ($logic_address ne '') { print TEMPFILE "Cc: $real_address, $logic_address\n"; } else { print TEMPFILE "Cc: $real_address\n"; } } else { if ($logic_address ne '') { print TEMPFILE "Cc: $logic_address\n"; } } } elsif ($real_address ne '') { print TEMPFILE "To: $real_address\n"; if ($logic_address ne '') { print TEMPFILE "Cc: $logic_address\n"; } } else { print TEMPFILE "To: $logic_address\n"; } print TEMPFILE <<"VERBATIM"; Subject: Bestaetigung: Problemreport erhalten! Dein Problem-Report wurde registriert. VERBATIM if ($subject ne '') { print TEMPFILE "Dein Subject war: $subject\n"; } print TEMPFILE <<"VERBATIM"; Diese Bestaetigung wird automatisch verschickt. Mit freundlichen Gruessen, Eure System-Administration. VERBATIM # close(TEMPFILE); # system("cat $tempfile | /opt/bin/sendmail -t"); # unlink($tempfile); } # # Release semaphore: # unlink($lockfile); # # Done. #