procmail
[Top] [All Lists]

Re: proper way to assign return value to a variable

2010-12-30 16:02:20
I changed it around a bit and I think I might be getting closer but it
appears that the line the recipe:
:0
 |ripmime -i -d /home/richard/.pmdir/attachments/ &&\
  /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";
rename_att($ENV{SUBJECT});'

is not executing properly.  Here's what the log says:

procmail: No match on " /usr/bin/perl -e 'require "/home/richard/.pmdir/
test_subject.pl"; test_subject($ENV{SUBJECT});'"
procmail: Executing "ripmime -i -d /home/richard/.pmdir/attachments/ &&\
  /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";
rename_att($ENV{SUBJECT});'"
procmail: Assigning "LASTFOLDER=ripmime -i -d
/home/richard/.pmdir/attachments/ &&\
  /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";
rename_att($ENV{SUBJECT});'"
procmail: Notified comsat: "richard@:/home/richard/mail/.inboxes/ripmime -i
-d /home/richard/.pmdir/attachments/ &&\
  /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";
rename_att($ENV{SUBJECT});'"

Again, thank you very much for the help so far.  Any suggestions on what I
am still doing wrong would be very much appreciated.

Thanks

Richard

Here is the entire recipe:

# I like to keep recipes in a separate file
# Be careful with the regular expressions, read the man page for specifics


#grab the subject
SUBJECT=""
:0
* ^FROM:.*
* ^Subject:[    ]*\/[^  ].*
{
       SUBJECT=$MATCH
}

:0 W # send to test_subject.pl to check for PO no.
* ? /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";
test_subject($ENV{SUBJECT});'
    # failed subject test
|( formail -rI"From: Replys automatically discarded 
<gatorreina(_at_)gmail(_dot_)com>";
\
   echo "Your mail has been returned."; \
   echo "It was NOT received because it does not contain a valid PO in the
subject"; \
   echo "Please resubmit with a valid PO number in the subject line."; \
 ) | /usr/sbin/ssmtp -oi -t

:0  #2nd colon means use locking so we don't get 2 files at once in friens
{ # valid load no
 :0
 |ripmime -i -d /home/richard/.pmdir/attachments/ &&\
  /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";
rename_att($ENV{SUBJECT});'
  :0:
  invoices
}


2010/12/30 Richard Reina <gatorreina(_at_)gmail(_dot_)com>



2010/12/30 Richard Ball <rgball(_at_)ellerbach(_dot_)com>

On 30-12-2010 9:26, Richard Reina wrote:

If anyone could please help me with this I would REALLY, REALLY
appreciate it.  I find procmail very cryptic for me and I am endangering my
job by falling way behind on my other work -- not to mention neglecting my
family.  Any help would be greatly appreciated. Currently I have a recipe
that calls a perl script like this:

:0 w # send to test_subject.pl <http://test_subject.pl> check for order
no.
* ? /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl <
http://test_subject.pl>"; test_subject($ENV{SUBJECT};'


This works fine, but what I need is to capture the return value of the
script so that I can compare it in a conditional and depending on the result
use it in another called script.  Something like the following:

:0
PO=`/usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl <
http://test_subject.pl>"; test_subject($ENV{SUBJECT};'`


:0:
* PO ?? 0  # if PO equals zero. PO is NOT valid
|( formail -rI"From: Responses will be automatically discarded <
gatorreina(_at_)gmail(_dot_)com <mailto:gatorreina(_at_)gmail(_dot_)com>>"; 
\

  echo "Your mail has been administratively rejected."; \
  echo "PO is not valid." \
 ) | /usr/sbin/ssmtp -oi -t
:0
{# else PO is valid strip the attachments and file it
| ( ripmime -i -d /home/richard/.pmdir/attachments/  )
| /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl <
http://test_subject.pl>"; rename_attachments($ENV{PO});'


If anyone could please help me.  I would really, really appreciate it.
I'm in dire straights.

 To do anything complex with procmail will require testing in an
environment where you aren't going to damage real email, so setup something
that will do that within the context of your system. Such a 'sandbox' is
available by taking a look at the information provided by Sean at
http://www.professional.org/procmail/disclaimer.html and I *really*
recommend you take the time to do read and understand it (especially if this
is important for your job performance) the time taken will be worth it in
the end.


I am testing with bogus emails that I send myself so that nothing can get
messed up.


Are the perl scripts you have written performing properly? If you feed
them an example email will they do all that is required or are you just
putting in placeholders that you are hoping will function when you finish
with them?

Yes.  I have tested them independently and the return values that come
back are correct.


Procmail has an E flag which can be used for 'else if' type conditions and
as was mentioned earlier you need to be aware of the difference between
delivering and non-delivering recipes. The f flag for 'filter' is useful to
create a non-delivering recipe if you need to feed the message to a program
outside procmail to get some work done.

Don't append a : to the :0 construct unless you are writing to a file (it
means create a lockfile and that can present problems unless you're familiar
with what is going to happen).


Thanks for clarifying.


I don't understand why you need to call the perl script twice. Can't it
test for a valid PO# and if it is one go ahead and strip attachments and
save the needed information all at once? Then return success or failure to
tell you whether a valid number was there or not.


I initially tried that approach.  However, if the email that ripmime is
supposed to rip the attachment from is not the current email being
processed, ripmime needs to be told what file to strip meaning that the
email ( by itself ) needs to be written to a file 1st so that ripmime can
grab it. However, once I write to a file procmail quits. That approach gave
me this:

:0 W # send to test_subject.pl to check for PO no.
* ? /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";
test_subject($ENV{SUBJECT});'
    # failed subject test
|( formail -rI"From: Replys automatically discarded 
<gatorreina(_at_)gmail(_dot_)com>";
\
   echo "Your mail has been returned."; \
   echo "It was NOT received because it does not contain a valid PO in the
subject"; \
   echo "Please resubmit with a valid PO number in the subject line."; \

 ) | /usr/sbin/ssmtp -oi -t

:0:  #2nd colon means use locking so we don't get 2 files at once in
friends
{ # passed subject tes. It has a valid PO no
  :0 c     # copy to freinds and invoices
  friends

  :0  # write it to invoices so that ripmime knows where to find it
       # and so that rip_attachments knows what email the attachments
#belong to  invoices

  :0 W #rip the attachments rename and save them
  * ? /usr/bin/perl -e 'require "/home/richard/.pmdir/test_subject.pl";
rip_attachments($ENV{SUBJECT})
;'

}



Basically:


:0
* ^Subject: (some test here for a PO# expression)   #is this even a
possible PO# email?
{
  :0fW
  | perl_script_that_does_the_work

  :0a                                      #the a flag will execute this
recipe if the above recipe succeeded
  use_sendmail_to_tell_me_a_valid_PO_was_received
}

# we're here if the email had nothing to do with PO#s, process further or
discard as you wish




____________________________________________________________
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



____________________________________________________________
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