procmail
[Top] [All Lists]

Re: if/else question

1999-07-07 23:21:51
On Wed, 7 Jul 1999 19:17:52 -0400, "D. Hammond" 
<deh(_at_)crisp(_dot_)openix(_dot_)com>
wrote:
I've set up a couple recipes to provide pseudo-mail for one of my
children.  If mail comes in with a certain tag in the Subject: line,
and the sender is found in his "white list", it gets delivered to a
file in my home directory at the ISP.  I run a nightly cron job from
home that ftps the file home and appends it to his spool file.  Then,
if there was any mail received for him, a message is sent to trigger
the following recipe.  It's an ugly kludge, but he's not quite old
enough for free reign and this gives me some parental control.

You mean like this?

                          There                 Back

 1. Mail arrives, whenever.

               mail---> procmail
                           !
                           v
                          file

    procmail at ISP saves to file.


 2. Back home, your cron job executes.
    It attempts to fetch file.

                              ,---------------- ftp <----- cron
                         file ! (snatch)
                              `---------------> file (copy)

 3. If ftp was successful, the cron job sends a command by mail
    to remove the file from the ISP. (This is the part I was unsure
    of. "A message is sent" from home to the ISP "to trigger [removal
    of the file]" at the ISP end, yes?)

                       procmail <------------- nuke, please
                          !
                          v
                         8=X (Jolly Roger smiley :-)

 4. Meanwhile, any mail that arrived while this was happening is lost
    forever. (Correct?)

The last point can easily be remedied by renaming the file at some
point before the ftp executes, so you ftp over a datestamped copy, and
any mail which arrived between the time the spool file was renamed and
it was ftp:ed over is simply left until tomorrow (or whenever your
cron job executes next).

(So procmail would still save to "file" and if it's empty, create a
new one. Meanwhile, "file" occasionally gets renamed to "file-990708"
[for today's file] and ftp only attempts to fetch a file named this
way.)

   :0
   * three conditions here that adequately identify
   * any messages that trigger this recipe actually
   * come from me.
   {
      :0
      * ? test -f $HOME/.../his_mbox
      {
         LOG=">>>>>>>>> $RCFILE: suitable message $NL"
         :0 ic
         | rm -f $HOME/.../his_mbox

         :0
         /dev/null
      }
      :0 E
      /dev/null
   }

It's probably unnecessarily anal to check for the file's existence
here, but what the hey.

(Actually, it's a complete waste of resources, because rm -f will not
complain or anything if it's not there.)

If the file exists I want to write the LOG msg, rm the file, and
bit bucket the message which triggered the process.
If the file doesn't exist, which arguably should never
happen, the incoming message should just be zapped.

    :0
    * your
    * three
    * conditions
    {
        :0
        * test -f $HOME/.../his_mbox   # kept this for the logging
        {
            LOG=">>>>>>>>> $RCFILE: suitable message$NL"
            :0i
            | rm -f $HOME/.../his_mbox
        }

        # If it gets this far, the test was not true (or rm failed)
        :0
        /dev/null
    }

So your comments about deliveredness and extra blocks and E flags were
basically correct. (And to clone a copy to /dev/null is basically
always wrong, or at least inelegant.)

Hope this helps,

/* era */

-- 
.obBotBait: It shouldn't even matter whether     <http://www.iki.fi/era/>
I am a resident of the state of Washington. <http://members.xoom.com/procmail/>
 * Sign the European spam petition! <http://www.politik-digital.de/spam/en/> *

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