procmail
[Top] [All Lists]

Re: help with if else conditional

2011-01-26 22:13:04
On Wed, Jan 26, 2011 at 3:57 PM, Richard Reina 
<gatorreina(_at_)gmail(_dot_)com> wrote:
 Can anyone tell me what I am doing wrong?

If what you posted is a literal cut-and-paste, then you're confused
about the basic procmail syntax.

EVERY condition line (a line beginning with a "*") must be preceded
(with no intervening blank lines) by either another condition (with
which it is logically AND-ed) or by a line beginning with ":0".  You
can't just plunk a condition down all by itself.  Only variable
assignments are allowed to stand alone.

So I'm going to guess that you just forgot to copy the ":0" line at
the start of your snippet, but please note that any flag letters
appended to that line might be affecting what happens next.

I thought this would work:

* ? /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";
test_if_billed($ENV{SUBJECT},$ENV{FROM});'
work #already billed test_if_billed() notified sender. just dump in work 
folder

The "?" condition tests the exit status of the program.  There's no
way to tell (from what you've shown) what exit status perl is going to
have.  Most likely it's always going to implicitly exit(0), causing
the "?" condition to always be true, and therefore storing everything
in the "work" mailbox.  Does the test_if_billed sub call exit(1) on
false, or does it just return something?  My guess would be you want
exit(test_if_billed(...) ? 0 : 1) there, but I can't be sure.

:0E  # has not been billed rip & save attachements
{

At this point (after a "{" on a line by itself) the procmail recipe
parser is back in the same state as if you were starting a brand-new
file.  Everything inside the braces has to obey the full syntax rules
-- start with ":0", follow with condition lines, end in action line.
You appear to be attempting to just throw a stack of actions in here,
which won't work.

|ripmime -i - -d /home/richard/.pmdir/attachments/ &&\
  /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";
rename_att($ENV{SUBJECT});'
 invoices

Also you seem to be confused about filtering through a pipeline as
opposed to delivery into a program.  To filter and then be able to
continue processing the result in procmail, you need the "f" flag
after the ":0".  Otherwise procmail assumes that the program has done
its own delivery, and ignores the output.

So what you want here is probably something like

:0 ifw  # Filter the message to remove attachments
| ripmime -i - -d /home/richard/.pmdir/attachments/  &&\
  /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";\
    rename_att($ENV{SUBJECT}); exit(0)'

:0 A  # and finally store in the invoices mailbox
invoices

}

If I'm wrong about how ripmime works and it does not produce a
modified copy of the message on standard output, then the above
probably needs to be changed.

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