procmail
[Top] [All Lists]

Re: conditional (on output of another program) forwarding

2000-09-14 12:56:04
Cory asked,

| What I'd like to do is forward all mail provided I'm not currently
| logged in.  Something like:
| 
| :0 w
| * [ if `finger | grep cory` != null ]
| ! user(_at_)here(_dot_)com

First, I don't see a use for `w' there.  Second, "?" conditions go by exit
code, so there's no need to compare the output to null, just see whether grep
reports success (it found a match to the search expression) or failure (it
found no match).

Also, I see that Matt recommended throwing awk in to reduce the output to
just the first field before grepping.  I disagree.  Just left-anchor ^cory
for grep; that will not only rule out a false positive if someone whose last
name is Secoryn is logged in but also if username secoryn is on.  We should,
ideally, include [      ] on the right, to make sure username coryphene
doesn't give us a false positive.

Fourth, the way you have it there, Cory, you'd get forwarding while you ARE
logged in.

Fifth, I'd never forward anything without loop detection.

So maybe

  :0 # brackets enclose space and tab
  * ! ^X-Loop: cory(_at_)olga\(_dot_)net
  * ! ? finger | grep '^cory[   ]'
  | formail -A "X-Loop: cory(_at_)olga(_dot_)net" | \
    "$SENDMAIL" $SENDMAILFLAGS user(_at_)here(_dot_)com

Sixth, er, what if you're logged onto a different machine from the mail de-
livery box, Cory?  Will finger see you there?  Maybe it will: I just want
to be sure.

I might take a different approach.  Cory, in your shell sessions, do you use
csh or a derivative, such that you have a .logout, or do you use sh or a
derivative, such that you could TRAP the login shell's exit signal?  If you
can do that, I think there's a better way than fingering and grepping with
every incoming message.

In your .profile or .login, put

 touch $HOME/.coryisinthehouse

and in .logout or in a TRAP in .profile, put

 rm -f $HOME/.coryisinthehouse

Then the recipe could look like this:

  :0
  * ! ^X-Loop: cory(_at_)olga\(_dot_)net
  * ! ? test -f $HOME/.coryisinthehouse
  | formail -A "X-Loop: cory(_at_)olga(_dot_)net" | \
    "$SENDMAIL" $SENDMAILFLAGS user(_at_)here(_dot_)com

Alternatively, you could reverse the logic: have no file when you're logged
in but a $HOME/.coryhasleftthebuilding when you're off, and test for its ex-
istence instead of its nonexistence.


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail