#!/opt/bin/perl # ######################################################################### # # # Program for receiving e-mails and storing or forwarding them # # # ######################################################################### # # # Version 1.0 - Written 24.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 = '/var/spool/mail/wolfgang'; # $lockfile = "$mailbox.lock"; # $tempfile = "$mailbox.temp"; # # To disable the creation of the mailbiffer flag file, comment out this line: # $mailflag = "$mailbox.bif"; # # Define here the forwarding (e-mail) address: # $address = "sb@sdm.de"; # $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"; } } # # Write incoming mail to temporary file and determine wether to forward it: # unless (open(TEMPFILE, ">$tempfile")) { unlink($lockfile); unlink($tempfile); die "Can't open tempfile for writing: $!\n"; } # while () { chop; print TEMPFILE $_, "\n"; if (($subject eq "") && (/^Subject:\s*(.*)$/)) { $subject = $1; } # # Define here the forwarding condition(s): # if (/Lotus.*Notes/i) { $forward = true; } elsif (/\bNotes\b/i) { $forward = true; } elsif (/\bMIS\b/) { $forward = true; } else { } } # close(TEMPFILE); # if ($subject eq "") { $subject = "Betreff: Lotus Notes"; } # if ($forward ne "") { system("cat $tempfile | /opt/bin/elm -s \'$subject\' $address"); $rc = ($? >> 8); } else { system("cat $tempfile >> $mailbox"); $rc = ($? >> 8); if ($mailflag ne "") { system("touch $mailflag"); } } # unlink($tempfile); # # Release semaphore: # unlink($lockfile); # # Done: # exit $rc