[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Some info about vacation?

Since the original Perl version isn't too big, I'm sending it to you
in case you find it useful.  It's 12 years old, but the last I knew
it still worked.  Here's Larry's original newsgroup posting:
Article 1239 of comp.lang.perl:
Path: genrad!mit-eddie!mintaka!think!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall
From: lwall jpl-devvax JPL NASA GOV (Larry Wall)
Newsgroups: comp.unix.wizards,comp.lang.perl
Subject: Re: Piping Mail
Keywords: .forward, mail
Message-ID: <7947 jpl-devvax JPL NASA GOV>
Date: 1 May 90 20:52:40 GMT
References: <1990Mar30 034336 6310 ux1 cso uiuc edu> <723 shuldig Huji Ac IL> <1990Apr25 210749 967 irscscm> <2258 awdprime UUCP>
Reply-To: lwall jpl-devvax JPL NASA GOV (Larry Wall)
Distribution: na
Organization: Jet Propulsion Laboratory, Pasadena, CA
Lines: 204
Xref: genrad comp.unix.wizards:22662 comp.lang.perl:1239

In article <2258 awdprime UUCP> jeffe reed UUCP (Peter Jeffe 512.823.4091/500000) writes:
: I believe vacation is in BSD4.3.  It's a very simple program that dismembers
: the mail header and sends a reply to the sender that you provide (something
: like "I'm on vacation, back in 3 years").  The nice part is it keeps track
: of who it's sent replies to, and only sends one a week to a given sender.
: Naturally, you can do similar things with shell/awk/etc. scripts that are
: invoked by your .forward file.  The following is a simple-minded version
: of vacation, but you get the idea:
: ------------------------------ snip snip ------------------------------
: #!/bin/sh
: # simple vacation(1)-like script
: sender=`awk '$1 ~ /^[Ff]rom:$/ { print $2 }'`
: mail -s "I am on vacation" $sender < $HOME/.vacation.msg
: ------------------------------ snip snip ------------------------------

PLEASE don't do this.  It only takes two people doing this to make a mail
loop.  System administrators hate mail loops.

A minimal vacation program should do the not-more-than-once-a-week trick,
since that's the primary purpose of vacation.

(Also, you shouldn't use the From: line, or you'll have to parse addresses
better.  I'm also not sure if all sendmails will set $HOME correctly.)

The vacation program from Berkeley is probably free.  If you want something
with all the bell's and whistles of Sun's vacation program, here is a
knock-off of it.  Requires Perl 3.0 patchlevel 18.

Season to taste and serve well chilled.


$vacation = $0;
$vacation = '/usr/ucb/vacation' unless $vacation =~ m#^/#;

if (! ARGV) {		# interactive use, ala Sun
    chop($cwd = `pwd`);
    $user = $ENV{'USER'} || $ENV{'LOGNAME'} || getlogin;
    $editor = $ENV{'VISUAL'} || $ENV{'EDITOR'} || 'vi';
    print <<EOF;
This program can be used to answer your mail automatically
when you go away on vacation.

    for (;;) {
	if (-f '.vacation.msg') {
	    print "You have a message file in $cwd/.vacation.msg.\n";
	    $see = &yorn("Would you like to see it? ");
	    system 'more', '.vacation.msg' if $see;
	    $edit = &yorn("Would you like to edit it? ");
	else {
	    print <<EOF;
You need to create a message file in $cwd/.vacation.msg first.
Please use your editor ($editor) to edit this file.
	    $edit = 1;
	    open(MSG, ">.vacation.msg") || die "Can't create .vacation.msg: $!\n";
	    print MSG <<EOF;
From: $user (via the vacation program)
Subject: away from my mail

I will not be reading my mail for a while.
Your mail regarding "\$SUBJECT" will be read when I return.
	    close MSG;

	last unless $edit;
	system $editor, '.vacation.msg';

    if (-f '.forward') {
	$forward = `cat .forward`;
	print "You have a .forward file in your home directory containing:
	if (&yorn(
"Would you like to remove it and disable the vacation feature? ")) {
	    unlink '.forward' || die "Can't unlink .forward: $!\n";
	    print "Back to normal reception of mail.\n";
	else {
	    print "Ok, vacation feature NOT disabled.\n";
    else {
	print "To enable the vacation feature a \".forward\" file is created.\n";
	if (&yorn("Would you like to enable the vacation feature? ")) {
	    open(FOR, ">.forward") || die "Can't create .forward: $!\n";
	    print FOR "\\$user, \"|$vacation $user\"\n";
	    close FOR;
	    print <<EOF;
Vacation feature ENABLED.  Please remember to turn it off when
you get back from vacation.  Bon voyage.
	else {
	    print "Ok, vacation feature NOT enabled.\n";

%scale = (
	's', 1,
	'm', 60,
	'h', 60 * 60,
	'd', 24 * 60 * 60,
	'w', 7 * 24 * 60 * 60,

while ($ARGV[0] =~ /^-/) {
    $_ = shift;
    if (/^-I/) {
    elsif (/^-j/) {
    elsif (/^-a(.*)/) {
    elsif (/^-t([\d.]*)([smhdw])/) {
	$timeout = $1;
	$timeout *= $scale{$2} if $2;
    else {
	die "Unrecognized switch: $_\n";

$user = shift;
push(@aliases, $user);
die "Usage: vacation username\n" if $user eq '' || @ARGV;

$timeout = 7 * 24 * 60 * 60 unless $timeout;

$home = (getpwnam($user))[7];
die "No home directory for user $user\n" unless $home;

chdir $home || die "Can't chdir to $home: $!\n";

dbmopen(VAC, ".vacation", 0666) || die "Can't open vacation dbm files: $!\n";

open(MSG,'.vacation.msg') || die "Can't open .vacation.msg: $!\n";

$/ = '';			# paragraph mode
$header = <>;
$header =~ s/\n\s+/ /g;		# fix continuation lines
$* = 1;

exit if $header =~ /^Precedence:\s*(bulk|junk)/;
exit if $header =~ /^From.*-REQUEST@/;

($from) = ($header =~ /^From\s+(\S+)/);	# that's the Unix-style From line
die "No \"From\" line!!!!\n" if $from eq "";

($subject) = ($header =~ /Subject:\s+(.*)/);
$subject = "(No subject)" unless $subject;

($to) = ($header =~ /To:\s+(.*)/);
($cc) = ($header =~ /Cc:(\s+.*)/);
$to .= $cc;
unless ($opt_j) {
    foreach $name (@aliases) {
	$ok++ if $to =~ /\b$name\b/;
    exit unless $ok;

$lastdate = $VAC{$from};
$now = time;
if ($lastdate ne '') {
    ($lastdate) = unpack("L",$lastdate);
    exit if $now < $lastdate + $timeout;

$VAC{$from} = pack("L", $now);

undef $/;
$msg = <MSG>;
close MSG;

$msg =~ s/\$SUBJECT/$subject/g;		# Sun's vacation does this

open(MAIL, "|/bin/mail $from") || die "Can't run /bin/mail: $!\n";
print MAIL $msg;
close MAIL;

sub yorn {
    for (;;) {
	print $_[0];
	$answer = <STDIN>;
    last if $answer =~ /^[yn]/i;
	print "Please answer \"yes\" or \"no\" ('y' or 'n')\n";
    $answer =~ /^y/i;

Larry Wall
lwall jpl-devvax jpl nasa gov

    pete peterson
    Teradyne, Inc.; 7 Technology Park Drive; Westford, MA 01886-0033
    +1-978-589-7478 (Office); +1-978-589-2088 (FAX);
    pete peterson teradyne com or petersonp genrad com


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]