procmail
[Top] [All Lists]

Re: Newbie Problem with Nesting Actions

2002-12-17 12:47:38
On 17 Dec, tallison(_at_)tacocat(_dot_)net wrote:
| > Hello,
| >
| > I'm trying to write a procmail recipe that will allow users to send a
| > message to themselves to either enable or disable mail forwarding.
| >
| > My conditions work ok, but it skips my actions. I've added comments for
| > this post.
| 
| >     * ! NEWADDR ?? ^^^^
| >             {
| >             MESSAGE="Your mail is now being forwarded to your $NEWADDR 
account."
| >             ;\ | echo $NEWADDR > ~/.forward ;\
| 
| TRY THIS:  (?)
|                 echo $NEWADDR > ~/.forward && mail -s "Mail Forwarding
|                 Request" $MUSERADDR < $MESSAGE
| (remove the 'pipe')
| >             }
| >     :0E

Close. Those are bare action lines inside the braces, so the log file
should've told Jeff that those action lines were being skipped. Also, I
don't think you can redirect $MESSAGE as input to the mail command.  The
shell will be expecting $MESSAGE to expand to a file name. This is a
case where it is not a UUOC to do:

echo $NEWADDR > ~/.forward && \
  echo "$MESSAGE" |mail -s "Mail Forwarding Request" $MUSERADDR

(Although the first echo could be done with LOG=, that's probably
overkill here.)
 
I tend to keep things like $MESSAGE in an external file.  It's just
personal preference, and might be less efficient since an extra file is
opened.  In this case, with a simple one line message body, it's even
less necessary.  I do this when $MESSAGE is longer to keep the rcfile a
little neater.  If it's in an external file, then that can be
redirected as indicated above.  Since the "Forwarding On" $MESSAGE is
intended to report the new address, it takes a slightly different tack.
Changing just the relevant part of Jeff's orginal recipe (and untested):


  :0
  * ! NEWADDR ?? ^^^^
  {
     INCLUDERC=/path/to/fwd.on.msg
     :0 i
     | echo $NEWADDR > ~/.forward && \
       echo "$MESSAGE" |mailto -s "Mail Forwarding Request" $MUSERADDR
  }
  :0 Ei
  | rm -f ~/.forward && \
    mailto -s "Mail Forwarding Request" $MUSERADDR </path/to/fwd.off.msg
  

Where /path/to/fwd.off.msg is:

---(cut here)---
Your mail is no longer being forwarded.
---(cut here)---


and /path/to/fwd.on.msg is:

---(cut here)---
MESSAGE="Your mail is now being forwarded to your $NEWADDR account."
---(cut here)---

I'm assuming that Jeff has a mailto command in his PATH that acts like
mail or mailx, since that's the way he wrote it.  I'm also assuming
that ~ is ok because it's expanded by the shell, though I haven't
tested to see if that's correct.  Procmail does not grok ~.  I'm also
assuming this is always running as the user $LOGNAME (e.g. from
~/.procmailrc) and not as root, otherwise ~ is no good at all.

Lastly, I do something along these lines for users to update their
whitelists.  Instead of generating a new message, I filter the body of
the one they sent, replacing it with info confirming what they've done,
and deliver it to them.  When all is said and done, it's probably no
better or worse than this, so I stuck with the way Jeff was doing it.
But it's something he might want to consider, to avoid firing up the
MTA twice for one simple message.

-- 
Email address in From: header is valid  * but only for a couple of days *
This is my reluctant response to spammers' unrelenting address harvesting



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

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