Patrick Rogers wrote,
R> I'm a new procmail user and I have a unique problem. I use procmail to
R> filter mail from certain users and forward it to my pager. When I am
R> reading my mail with another application I would rather not have procmail
R> process my pagerNames.rc file, since my local mail reader will beeb.
R> Usually I read my mail with pine, so essentially I want a procmail recipe
R> that will detect wether or not pine is running, and if not process my
R> pagerNames recipes. Is this possible? I realize it is out of the scope
R> of what a mail filter should do, but it would be very useful.
Era Eriksson has posted a reply, and mine is similar. The question, though,
is this: if an incoming message normally should go through pagerNames.rc,
but you have Pine running, should procmail
(a) wait until you exit Pine, or
(b) skip pagerNames.rc and move on?
So, first I agree with Era about a semaphore file (is that the right term?),
but rather than test && touch, I'd recommend lockfile for it, partly because
you could get a race condition where a beep could be on the way while you're
entering Pine, and because in case (a) it integrates very easily into your
main rcfile. Here's my modification of Era's script:
#!/bin/sh
pinelock=$HOME/.pine-running
if lockfile -! -r0 $pinelock; then
echo 'Oops, there already seems to be a copy of Pine running' >&2
echo "Issue the command rm -rf $pinelock if this is not true." >&2
exit 1
fi
trap 'rm -f $pinelock' 1 2 3 15
/usr/local/bin/pine "$@"
rm -f $pinelock
And as he said,
E> You may have to change your PATH in your login files to make your
E> personal $HOME/bin version take precedence over the real pine.
E> Now you can change your .procmailrc where it says
E> INCLUDERC=pagerNames.rc
E> to instead say
E> :0
E> * ! ?? test -f $HOME/.pine-running
E> { INCLUDERC=pagerNames.rc }
Just one question mark there, Era.
OK ... but since we're using lockfile, it goes like this:
To make procmail wait until you exit Pine before beeping,
:0
* conditions for determing if you try to page at all
{
LOCKFILE=$HOME/.pine-running
INCLUDERC=pagerNames.rc
LOCKFILE # in case of fall-through
}
To make procmail skip the INCLUDERC if you're running Pine,
:0
* conditions for determining if you try to page at all
* ! ? lockfile -r0 $HOME/.pine-running
{ INCLUDERC=pagerNames.rc }