procmail
[Top] [All Lists]

Re: Conditional statement problem

2005-05-02 03:22:08
On Mon, May 02, 2005 at 12:43:58PM +0430, Hossein Movahhedian wrote:

   I am trying to write a recipe to check the existence of
of MAILDIR directory. The recipe is:

SHELL   = '/bin/sh'

MAILDIR = /ext3/pkgs2/ztmp/Test/Procmail_1 ### A non-existing directory
DIR_1   = /ext3/pkgs2/ztmp/Test/Procmail_1 ### A non-existing directory
DIR_2   = /ext3/pkgs2/ztmp/Test_1          ### A non-existing directory
TMP_DIR = /ext3/pkgs2/ztmp/Test/Procmail   ### An existing directory
MY_DIR=

[. . . .] 
But the following works fine as expected:

:0
*? ! [[ -d $DIR_1 || -d $DIR_2 ]]
{
  :0 fwi
  | MY_DIR=`mktemp -d $TMP_DIR/procmail.XXXXXX`; \
    echo $MY_DIR >> $TMP_DIR/zzz.txt
}

In this case the LOG messages are:{{{
...

procmail: Assigning "MAILDIR=/ext3/pkgs2/ztmp/Test/Procmail_1"
procmail: Couldn't chdir to "/ext3/pkgs2/ztmp/Test/Procmail_1"
...
procmail: Executing " ! [[ -d $DIR_1 || -d $DIR_2 ]]"
procmail: Match on " ! [[ -d $DIR_1 || -d $DIR_2 ]]"
....
}}}

I cannot figure what am I doing wrong. Any help would be gratefully
appreciated.


In addition to what Ruud said -- that MAILDIR is special and
will always exist, as the current dir (".") even if the attempt
was made to define it badly -- I would add that you don't need
shell stuff to do any of this except create MY_DIR.  When learning
about procmail, it's useful to learn about the capabilities of
native procmail expressions, as opposed to shell expressions.

Also, perhaps you want to add the h-flag to the climactic recipe.
Pipe just the header and give procmail a break. :-)

Put this in a test harness:

  MAILDIR
  LOG="MAILDIR is >$MAILDIR<
  " HOST
  
  (With HOST unset, we don't need to bother with setting DEFAULT=/dev/null
  in your test harness, even.)
  
   11:46am [~/Mail] 290[1]> procmail -m  .mytestrc < /dev/null                 
  procmail: Couldn't chdir to ""
  MAILDIR is >.<
    Folder:                                                                     0
  

You could do something like this:


   :0 hi
   * $! MAILDIR ?? ^^$\SOMEDIR^^
   DUMMY=| mkdir -pm 755 newdir; echo "something" >> newdir/file.txt
  
  HOST

   11:59am [~/Mail] 335[1]> procmail -m VERBOSE=y test.rc < /dev/null
  procmail: [13974] Mon May  2 11:59:12 2005
  procmail: Assigning "MAILDIR=."
  procmail: Rcfile: "test.rc"
  procmail: Match on ! "^^()^^"
  procmail: Assigning "DUMMY="
  procmail: Executing " mkdir -pm 755 newdir; echo "something" >> 
newdir/file.txt"
  procmail: Assigning "HOST"
  procmail: HOST mismatched "panix5.panix.com"
    Folder:                                                                     0

Two things about that: first, set UMASK higher up in the rcfile if you're
going to be creating dirs, or check its compiled-in value.  Second, the
-m switch to POSIX mkdir won't rewrite perms on an existing dir; only
one you create newly.  So either you have to expect the perms to be
okay, or use UMASK in the rcfile, or have the right value compiled in,
or use chmod, or something similar.

Another thing about the above example to think about is, suppose in
procmail we've set MAILDIR relatively to the current dir instead of
absolutely.  Now we could nevertheless be in SOMEDIR, yet the
condition comparing the values of MAILDIR and SOMEDIR could fail.

So you have to think about controlling your environment vis-a-vis
relative and absolute paths, etc.

Dallman

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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