procmail
[Top] [All Lists]

Re: Need to send e-mail twice to get the result?

2006-12-13 03:35:12
At 11:16 2006-12-13 +0800, DR. Lee - NS3 wrote:
I found something odd about the procmail and hope you can help.
The objective was to check the incoming with a list of recipient/sender 
names in a file 'key_list';
and if the name matches, then the mail is sent to a file called 'body' or 
to be forwarded once the script works.

The test shown that:

a) if no match, the output header file 'hdr" would be 0 byte, the size = 0 
and
the file 'body' would not be written. The repeated test shown this is correct.

b) if there is a match, then the hdr > 0 bytes and the file body written.
Here is the odd thing. The first run, the hdr > 0 and the body will not be 
written;
but run the program again, the body will now be written.
This is a repeatable error.

add W to the FIRST of your two recipe sets.  The header processing copy is 
processing and creating the data file WHILE THE ORIGINAL PROCESS CONTINUES 
ALONG TO THE SECOND RECIPE, which since it executes quicker, doesn't find 
the datafile which is generated when the first recipe completes.


FOUND='/home/dadu/hdr'
BODY='/home/dadu/body'

:0
{

This outer brace level serves no purpose - you're not performing special 
locking, or using conditions.  Lose it.

:0 hc
| grep To | grep -f key_list | cat > $FOUND

Er, you could simply use the grep sequence in a CONDITION line.  Note also 
that your initial grep here is going to catch a *LOT* of cruft.  At a 
minimum, you should qualify it with a trailing colon.

:0
* ^To:[         ]*\/[^  ].*
* $? grep $MATCH -f key_list

The first condition extracts the text of the To: header to the $MATCH 
variable.  The second, greps that against your key list file.  If grep 
doesn't find a match, the return value will not result in a success of that 
condition line, and processing will stop there.

:0 Wic
* ? test -s $FOUND
|  cat > $BODY

you don't use LOCKING on this recipe, which is bad, because two messages 
can arrive at the same time.  You're also OVERWRITING what's in the $BODY 
file, not appending to it, AND it's not just the body - it's the WHOLE 
message, headers too.

The flags, and condition don't need to remain, just add the action as the 
action for the above tweaked recipe.  If you really want to APPEND, then 
change the action to (no pipe):

$BODY


That is to say, for the most part, I believe the following recipe will do 
what you're probably trying to accomplish:

:0:
* ^To:[         ]*\/[^  ].*
* $? grep $MATCH -f key_list
$BODY


You might want to take a look at my sandbox environment, and either adopt 
it entirely for testing, or certainly look to lift a few header extraction 
elements from it.  Note that my sandbox has a companion component which 
deals with circumventing the procmail forward mechanism (a script, plus 
changing the value of $SENDMAIL), so that YOU CAN WRITE YOUR RECIPE AS YOU 
WOULD EXPECT WITH A FORWARD OPERATOR - and while testing in the sandbox, 
the forward messages will actually be deposited into a data file along with 
the arguments passed to $SENDMAIL.


The above is untested, and it's about 2am here, so if something isn't quite 
right, blame me, but I'm going to blame a lack of sleep...

---
  Sean B. Straw / Professional Software Engineering

  Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
  Please DO NOT carbon me on list replies.  I'll get my copy from the list.


____________________________________________________________
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>