procmail
[Top] [All Lists]

Re: problem with environment variable which is lost

1997-10-07 09:41:01
`era eriksson' wrote
  
  
  This cannot work, because the shell snippet above is run in a
  subshell. Parents never inherit from their children, remember? 

Ok, this is what I thought.

      # If myfilter cannot read from standard input, rewrite it so it can
  
      :0h:"result.list1$LOCKEXT"
      RESULT=| ( formail -XFrom: -XTo: -XCc: ; echo "Found: $FOUND" ) | \
          myfilter | tee -a result.list1

I will try to rewrite myfilter. It is a C program, for I am not that
knowledgeable in shells.

  
      # If you actually want the exact values of $TO and $FROM, etc, 
      #  by all means use what you had before. I'm guessing formail -X
      #  is good enough for you.

No, formail seems to fit my needs.

  
   > :0:
   > #* RESULT ?? [^  ]
   > |echo $RESULT >> result.list2
   > my-default
  
  (Is this a typo? Or do you actually try to have two actions on one
  recipe?)

My fault. But the echos to the `result.list' files are just for testing.

  
  This could of course be accomplished by another addition to the above
  shell script just as well, and is probably no less efficient. 
  
      ... | grep '[^  ]' >> result.list2
  
  (... but then you end up not locking one or both of the result files.
  Perhaps this is not a problem.)

No, it is not a problem, since these result files will vanish.

  
  Finally, this in fact looks like you could accomplish what you want
  with a few judiciously chosen LOGFILE= and LOG= statements.
  (Incidentally, the log is also never locked, so if you want some kind
  of locking, you'll need a regional lockfile somewhere, too.)
  The sort of data you want to write definitely looks like some sort of
  logging, is this correct?

No, this is not correct. What I am trying to do is to send the From:,
To: and Cc: fields, as well as a variable FOUND (which measures
which rules have matched) to the myfilter program. This program will
then simplify the From:, To: and Cc: fields, removing in particular
my name and everything that has been matched in FOUND, assuming the FOUND
matches are based on simple substrings, no regular expressions. 
If myfilter returns something non empty, it means that some fields
in the From:, To: or Cc: headers had no corresponding rules
and therefore that there is a reason to save the current message
in the default mailbox.

...

  
  (Well, perhaps this is not so elegant, either :-)

...
  
  If my assumptions are correct, this could all, then, be trimmed down
  to the remarkably elegant
  
      :0h
      | myfilter
  
  but of course, I might have assumed the wrong things. 

Yes :-)

  
  (A more likely usage is one whereby you want myfilter to judge whether
  you want to keep a message, in which case you might have
  
      :0
      * ! ? myfilter
      /dev/null
  
  and then, of course, myfilter has to return a suitable exit code in
  all cases.)

Yes, after all, I might use this. Anyway, I will first slightly rewrite
myfilter to read from stdin.

  As has been pointed out before, anything that uses a temp file looks
  like it could be done better. You might want to look at some shell
  programming book, such as the Kernighan/Pike classic or one of the
  O'Reilly tomes. Reading comp.unix.shell is a great waste of time but
  can also be a great way to learn. Just make sure you have a big enough
  kill file :-)

Thanks for the tips!

Denis

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