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

Re: formail and procmail question



Carlos Sousa wrote:
> Your question prompted me to finally do something I've been thinking on
> and off for some time: set up a mail echo reply on my machine using a
> procmail recipe. You can test it by sending mail to echo@vbc.dyndns.org .

Pretty neat!

> It's a similar problem, so I'm including my recipe here, for you to
> change to your wishes:
> 
> ========== begin .procmailrc extract ==========
> ...
> SENDMAIL=/usr/sbin/sendmail   <--------- check your MTA

You should not have to set SENDMAIL.  When procmail was compiled and
installed it should have a good setting for this variable by default.
I believe it would be better to use the system setting than to supply
your own.  Because if you supply your own you also need to keep track
of this if it is on an old /usr/lib/sendmail or a new /usr/sbin
version or if elsewhere.

> ECHOTMP=/tmp/echo-reply
> ...
>    # ----- echo reply -----
>    :0 Hcw                <--------- ":0 Hbcw" to only include the headers
>    * ^To: echo@.*        <--------- check your specific case (target user)
>    | cat > $ECHOTMP

Since you are using a single file /tmp/echo-reply you should use a
lockfile with this recipe.

:0 Hcw:

Otherwise two messages could collide and the results would not be
guarenteed.  For example, the reply to me might be the mail from you
because by the time the cat $ECHOTMP happens a new message might have
arrived and rewrote that /tmp file.

>       :0 acw
>       * !^FROM_DAEMON
>       * !^X-Loop: my@email.address
>       | (formail -r \
>          -A"X-Loop: my@email.address" \
>          -A"X-EchoReply: vbc.dyndns.org" ; \
>          echo -e "(THE MESSAGE YOU WANT FOR THE REPLY).\n" ; \
>          echo -e "--------------------------------------------------\n" ; \
> 	 cat $ECHOTMP ) | $SENDMAIL -t

Cool stuff.  Still not quite perfect.  If it were me I would probably
try to avoid the lock to allow simutaneous processing by setting up a
{ } subgrouping subshell, using a unique temporary file with $$ and
then set up a procmail TRAP to clean up the temporary file.

Bob

>    # ----------------------
> 
> ========== end .procmailrc extract ==========
> 
> See procmailrc(5) and procmailex(5) for more information.
> 
> -- 
> Carlos Sousa
> http://vbc.dyndns.org/

Attachment: pgpu_wty21cQ4.pgp
Description: PGP signature


Reply to: