#!/usr/bin/perl # # a simple vacation script # use strict; use Time::localtime; # ----- some global vars - set up to fit your needs my $message = $ENV{'HOME'} . "/" . ".vacation.msg"; my $dbfile = $ENV{'HOME'} . "/" . ".vacation.db"; my $check_sig = 1; # check for signature in $HOME? my $version = "vacation.pl (c) 2001 by lf, v. 160801-1815"; my $reply_interval = 60; # max reply interval (minutes) my $sendmail = "/usr/sbin/sendmail"; # path to sendmail prog/wrapper my $hostname_file = "/etc/hostname"; # file containing hostname my @weekdays = qw (Sun Mon Tue Wed Thu Fri Sat); my @months = qw (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); # ----- set host's name, if needed if ( (-e $hostname_file) and (!$ENV{'HOSTNAME'}) ) { open (HN, "<$hostname_file"); $ENV{'HOSTNAME'} = ; chomp $ENV{'HOSTNAME'}; close (HN); } # ----- check for existing message file if (!-e $message) { print "Die Datei $message existiert noch nicht!\n"; exit (1); } # ----- read the mail header from std input local $/ = ""; my $header = ; undef $/; # ----- preformatting of header my @header = split /\n(?!\s)/, $header; foreach (@header) { if (/.*\n.*/) { $_ =~ s/\n\s+/ /g; } } # ----- read headers into hash my %hash = (); foreach (@header) { my ($label, $value) = split /:\s*/, $_, 2; $hash{$label} = $value; } # ----- check if auto-reply was already sent within interval open (STATUS, "<$dbfile"); my @status = split /\n/, ; close (STATUS); @status = reverse @status; foreach (@status) { my ($rdate, $rrecip) = split /;/, $_; if ($rrecip =~ /$hash{'From'}/) { my $diff = abs ( time() - $rdate ); exit (1) if ($diff < ($reply_interval * 60)); last; } } # ----- prevent bogus and useless replies exit (1) if ( ($hash{'X-Loop'}) or ($hash{'Precedence'} =~ /(bulk|junk|list)/) ); exit (1) if ( (!$hash{'From'}) or ($hash{'From'} =~ /(daemon|postmaster|mailer-daemon|mailer)/i) ); # ----- Reply-To overrides To address $hash{'From'} = $hash{'Reply-To'} if $hash{'Reply-To'}; # ----- get some date and Message ID for replying my $message_id = time () . "\%vacation\@" . $ENV{'HOSTNAME'}; #my $date = localtime ( time() ); my $tm = localtime ( time() ); my $date = sprintf ("%s, %02d %s %04d %02d:%02d:%02d +0100", $weekdays[$tm->wday], $tm->mday, $months[$tm->mon + 1], $tm->year + 1900, $tm->hour, $tm->min, $tm->sec); # ----- read the message file open (MSGFILE, "<$message"); my @message = ; close (MSGFILE); # ----- open sendmail pipe $ENV{'PATH'} = ""; open (SMPIPE, "| $sendmail -t"); # ----- evaluate message my $eval = "print SMPIPE <<\"...\";\n"; $eval .= $_ foreach (@message); $eval .= "..."; eval ($eval); # ----- append signature, if requested and sig file set up if ( ($check_sig) and (-e "$ENV{'HOME'}/.signature") ) { print SMPIPE "\n\n-- \n"; open (SIG, "<$ENV{'HOME'}/.signature"); print SMPIPE ; close (SIG); } close (SMPIPE); # ----- write to vacation status file open (STATUS, ">>$dbfile"); print STATUS time () . ";" . $hash{'From'} . "\n"; close (STATUS);