procmail
[Top] [All Lists]

Re: Feature request

1996-08-20 11:30:31
When delivering to directories, procmail can correctly handle delivery
to multiple folders using links.  However, LASTFOLDER only contains
the name of the first file delivered to.  I would prefer that ALL of
the files delivered to be present, allowing further processing
(specifically, adding all of the messages to MH unseen sequences).

To be totally clear, the recipe

:0:
f1/. f2/. f3/.

will deliver to all three directories, but LASTFOLDER will only
contain a reference to f1/x.  (Furthermore, only f1 will get the local
lockfile, but that's another matter....)

Hacking procmail to understand MH idiosyncrasies is not a good solution.
Apply this algorithm for everyone's favorite mailer, and you get a piece
of junk. 

It is better to write recipes to do what you need; this is how procmail
normally gets extended.  In fact, this is fairly easy.  I have already
done something similar to what you are asking for, except for the
maintenance of the 'unseen' sequence.  However, using "rcvstore" is a
very easy way to keep the unseen sequence up to date.

What follows is a modified version of my recipe which saves a mail into
one or more folders.  It is untested, but should be fairly close to
working as it is.

One warning: because "rcvstore" is being called asynchronously (to your
keyboard input), it is possible for one of your terminal sessions to try
updating the unseen sequence while "rcvstore" is doing the same.
Protections from simultaneous updates from procmail-driven deliveries
can be easily accomplished, but these will not protect against updates
to the unseen sequence files from interactive usage of "show", "next",
etc., without additional steps.

Since MH itself doesn't provide any locking methods, it is unreasonable
to expect any locking method applied by procmail or its recipes to
protect your from your interactive usage of any MH commands.

However, there is a way: if you "wrap" your MH commands with shell scripts
which use the same locking convention, then you will avoid any update
conflicts on the unseen sequence file.  An easy way to wrap all your
MH commands is to create a single shell script, called ".mhwrapper", and link
the commands you wish to protect to this wrapper, from a common
directory where executables live, such as "/usr/local/bin":

  /usr/local/bin/scan -> .mhwrapper
  /usr/local/bin/next -> .mhwrapper
  /usr/local/bin/prev -> .mhwrapper

And then place the "real" MH binaries in a directory which is not
normally part of your path, something like: "/usr/local/mh/bin".

  .mhwrapper
    PROG=`basename $0`
    MHBINDIR=/usr/local/mh/bin
    for f in $@ ; do
      case $f in 
      +*) folder=`echo $f | sed -e 's/^+//'` ;;
      esac
    end
    trap 'rm -f $f.lock' 1 2 3 10 11 14 15
    lockfile $f.lock
    $MHBINDIR/$PROG $*
    rm -f $f.lock

This will allow those interactive commands which are wrapped to be
protected by the same locking algorithm as used by the procmail recipes.

Anyway, here is a recipe which can be used to save into multiple
folders, invoking "rcvstore" on each folder:

    # pf-save-mh.rc
    #
    # $Id: pf-save.rc,v 1.1.1.1 1996/08/16 18:27:12 stebbens Exp $
    #
    # Author: Alan K. Stebbens <stebbens(_at_)sgi(_dot_)com>
    #
    # Procmail recipe file to save the current message to 
    # a list of one or more folders set by pf-check.rc.
    #
    # You should set the variable PF_DEST before invoking.
    #
    # INCLUDERC=pf-save.rc
    #
    # If the message is filed into a folder, LOGABSTRACT is
    # set to "off" so a duplicate log is not created.

    :0
    * PF_DEST ?? .
    {

      # Add a new X-Filed if necessary
      :0 fh
      * !^X-Filed:
      | formail -A "X-Filed: $PF_DEST"

      # Else, if there is already a header, possibly append to it
      :0 E
      {
        OLD_PF_DEST=`formail -zxX-Filed:`
        :0 fh
        * $!^X-Filed:.*$PF_DEST
        |formail -I"X-Filed: $OLD_PF_DEST $PF_DEST"
      }

      # to file into multiple folders, use a recusive loop

      # DEST will be the first folders, and PF_DEST will be
      # the remainders
      DEST=`echo $PF_DEST | cut -d' ' -f1`
      PF_DEST=`echo $PF_DEST' ' | cut -d' ' -f2-`

      # Check on procmail style folder syntax, & convert to MY style
      # file/. -> file  # ie: remove trailing "/.".
      :0 
      * DEST ?? \/\.$
      { DEST=`echo $DEST | sed -e 's/\/\.$//'` }

      # File into the first folder now
      :0 c:$DEST.lock
      | /usr/local/mh/lib/rcvstore -create +$DEST

      # Possibly file into the 2nd and other folders with recursion 
      # It must be non-blanks, and not identical to the already filed DEST
      :0 c
      * PF_DEST ?? [^ ]
      * $! DEST ?? $PF_DEST
      |procmail -pm PF_RECURSE=yes pf-save.rc

      # If we were recursing, don't file multiple copies into DEFAULT
      :0
      * PF_RECURSE ?? yes
      { HOST }                  # stop now if recursing
    }

Enjoy..
_____________________________________________________________________
Alan Stebbens <stebbens(_at_)sgi(_dot_)com>      http://reality.sgi.com/stebbens

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