procmail
[Top] [All Lists]

Re: A recipe for handling a location move

1996-03-06 02:15:02
On Wednesday 6 March 96, at 9 h 42, the keyboard of John T Ellis 
<ellis(_at_)cig(_dot_)mcel(_dot_)mot(_dot_)com> wrote:

I will be moving from Beijing, China to Cork, Ireland within the next few
months.  

I changed of job six monts ago and I did that:

At the old job, I leave a .procmailrc which drops stupid messages, 
replies if I'm a primary recipient and forward.

--------- .procmailrc --------

# Drop stupid messages
:2
^From:(_dot_)*news(_at_)cnam(_dot_)fr
^Subject:.*Message from Swatch
/dev/null

# Etc

# Warn them I changed my job., Notice the 'c' for 'continue' processing 
# or the mail would be lost
:1c
^To:.*(bortzmeyer|Stephane\.Bortzmeyer|bortz)@.*cnam\.fr
|/users/labinf/bortz/vacation.bortz -a bortzmeyer -a Stephane.Bortzmeyer 
bortz 

# Forward everything
:0
! bortzmeyer(_at_)pasteur(_dot_)fr

------------------------

The "vacation" program is a hacked version which checks I didn't sent 
such a message to the same user, less than a week ago (you could probably 
do it with formail). Put your message in ~/.vacation.msg.

------------------ vacation.bortz ---------------

#!/usr/local/bin/perl
#
# Vacation program
# Larry Wall <lwall(_at_)jpl-devvax(_dot_)jpl(_dot_)nasa(_dot_)gov>
#
# updates by Tom Christiansen <tchrist(_at_)convex(_dot_)com>
# This version is personal Stephane Bortzmeyer 
<bortzmeyer(_at_)pasteur(_dot_)fr>

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

#print STDERR "vacation is up\n";

$user = $ENV{'USER'} || $ENV{'LOGNAME'} || getlogin || (getpwuid($>))[0];

$default_msg = <<'EOF';
I will not be reading my mail for a while.
Your mail regarding "$SUBJECT" will be read when I return.
EOF


if (!(_at_)ARGV) {
    die "not interactive";
}

@ignores = ( 
         'daemon', 
         'postmaster', 
         'mailer-daemon', 
         'mailer',
         'root',
         'http',
         'news',
         'usenet'
     );
# set-up time scale suffix ratios
%scale = (
        's', 1,
        'm', 60,
        'h', 60 * 60,
        'd', 24 * 60 * 60,
        'w', 7 * 24 * 60 * 60,
    );


while ($ARGV[0] =~ /^-/) {
    $_ = shift;
    if (/^-I/i) {  # eric allman's source has both cases
        chdir;
        &initialize;
        exit;
    } elsif (/^-j/) {
        $opt_j++;
    } elsif (/^-f(.*)/) {
        &save_file($1 ? $1 : shift);
    } elsif (/^-a(.*)/) {
        &save_alias($1 ? $1 : shift);
    } elsif (/^-t([\d.]*)([smhdw])/) {
        $timeout = $1;
        $timeout *= $scale{$2} if $2;
    } else {
        die "Unrecognized switch: $_\n";
    }
}

if (!(_at_)ARGV) {
    die "not interactive";
}
$user = shift;
push(@ignores, $user);
push(@aliases, $user);
die "Usage: vacation username\n" if $user eq '' || @ARGV;

$home = (getpwnam($user))[7];
die "No home directory for user $user\n" unless $home;
chdir $home || die "Can't chdir to $home: $!\n";

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

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


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

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

for (@ignores) {
    exit if $header =~ /^From.*\b$_\b/i;
} 

# Following order is in RFC 822. The last one is the preferred one.
($from) = ($header =~ /^Reply-To:\s*(.+)$/i);
if ($from eq "") {
        ($from) = ($header =~ /^From:\s*(.+)$/i);
}
if ($from eq "") {
        ($from) = ($header =~ /^Sender:\s*(.+)$/i);
}
die "No address to reply to!!!!\n" if $from eq "";

#print STDERR "I will reply to $from\n";
($subject) = ($header =~ /Subject:\s+(.*)/i);
$subject = "(No subject)" unless $subject;
$subject =~ s/\s+$//;

($to) = ($header =~ /^To:\s*(.*)/i);
#($cc) = ($header =~ /Cc:(\s+.*)/i);
$to .= ', '.$cc if $cc;

if (open(MSG,'.vacation.msg')) {
    undef $/;
    $msg = <MSG>;
    close MSG;
} else {
    $msg = $default_msg;
} 
$msg =~ s/\$SUBJECT/$subject/g;         # Sun's vacation does this

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 unless $lastdate;
    exit if $now < $lastdate + $timeout;
}

$VAC{$from} = pack("L", $now);
dbmclose(%VAC);
#print STDERR "Launching sendmail\n";

open(MAIL, "|/usr/lib/sendmail -oi -t") || die "Can't run sendmail: $!\n";
#open(MAIL, "| /bin/cat") || die "Can't run cat: $!\n";

#print MAIL "Replying to \"$from\"\n";

print MAIL <<EOF;
To: $from
Subject: This is a recording... [Re: $subject]
Precedence: junk

EOF
print MAIL $msg;
close MAIL;
exit;


sub save_file {
    local($FILE) = @_;
    local($_);

    open (FILE) || die "can't open $FILE: $!";

    while (<FILE>) {
        push(@ignores, split);
    } 
    close FILE;
} 

sub save_alias {
      push (@aliases, @_);
      # If sendmail rewrites addresses, it's better to assume that aliases
      # can be used in From field too:
      push (@ignores, @_);
}


sub make_default {
    #return if $edit;
    open(MSG, ">.vacation.msg") || die "Can't create .vacation.msg: $!\n";
    print MSG $default_msg;
    close MSG;
} 


-----------


Stephane Bortzmeyer           Institut Pasteur
bortzmeyer(_at_)pasteur(_dot_)fr         Service d'Informatique Scientifique
                              Paris, France
+33 1 40 61 34 62

http://web.cnam.fr/personnes/bortzmeyer/home_page.dom

<Prev in Thread] Current Thread [Next in Thread>