procmail
[Top] [All Lists]

substituting for dirname

1998-02-08 12:48:19
Timothy Luoma had an answer for Chris Mason, which included this:

|       DIR=`dirname ${MBOX}`

Procmail can do that without forking dirname.

 :0
 * MBOX ?? ^^\/.+/
 {
  DIR=$MAILDIR/$MATCH

  :0ic
  * ? test ! -d "$DIR"
  | mkdir -p "$DIR"
 }

 :0:
 $MBOX

As to avoiding tr, I have no easy solution.  A recursive INCLUDERC will do
the job, but that's worse IMO than forking tr:

  ARG1=$1
  :0
  * ARG1 ?? .
  { MBOX=$1 }
  :0E
  * $ ^TO_$LOGNAME\+\/[^ ]+
  { MBOX=$MATCH }
  
  :0
  * MBOX ?? ()\+
  { INCLUDERC=$HOME/.plustoslashrc }

and $HOME/.plustoslashrc contains this:

  :0
  * MBOX ?? ^^\/[^+]*
  { LEFT=$MATCH } # $LEFT may be null; that's ok.

  :0
  * MBOX ?? ^^[^+]*\+\/.*
  { RIGHT=$MATCH } # $RIGHT may be null; that's ok.

  MBOX=$LEFT/$RIGHT

  :0 # Are there any plus signs remaining?
  * MBOX ?? ()\+
  { INCLUDERC=$_ }