Re: Getting xfilter AND delivery to working
Philip Rhoades <[email protected]> Fri, 05 Feb 2016 08:06:16 +1100
| Newsgroups | gmane.mail.maildrop |
|---|---|
| Message-ID | <dd95ef662fcf49c8dec4ce3348d30141@localhost> |
Milan, On 2016-02-05 01:03, Milan Obuch wrote: > On Fri, 05 Feb 2016 00:34:36 +1100 > Philip Rhoades <[email protected]> wrote: > >> Milan, >> >> On 2016-02-04 20:39, Milan Obuch wrote: >> > On Thu, 04 Feb 2016 19:14:24 +1100 >> > Philip Rhoades <[email protected]> wrote: >> > >> >> People, >> >> >> >> I have this filter: >> >> >> >> if( /^[TC][[co]:.*tst/ ) >> >> { >> >> xfilter "/home/phil/bin/bash_internal_variables.sh >> >> > /home/phil/t" to $DEFAULT/.tst/ >> >> } >> >> >> >> and the xfilter is working but the delivery is not - if I reverse >> >> the lines, the delivery works but the xfilter does not - how can I >> >> get BOTH lines to work? >> >> >> > >> > Hi, >> > >> > did zou examine your mailogs? Maybe there is a clue... >> >> No errors or anything unusual . . >> >> > Also, could you >> > show us what's there in /home/phil/bin/bash_internal_variables.sh >> > file? >> >> #!/bin/bash >> >> echo -n "! | " ; echo $! > > [ snip ] > >> echo -n "time | " ; echo $time >> >> but why should anything in there matter? Even if an error code was >> returned, maildrop should still execute the "to" command? >> > > [ snip ] > > I did some tests and now I can confirm your observation. Here is my > explanation. > > First, quote from 'man maildropfilter': > > xfilter - filter message through another program > xfilter expression > > > expression specifies an external program that maildrop runs > to filter the current message. The current message will be > piped to the filter program as standard input. The output of > the filter program replaces the current message being > delivered. The external program must terminate with an exit > code of 0. If the external program does not terminate with > an exit code of 0, or if it does not read the message from > the standard input, maildrop terminates with an exit code of > EX_TEMPFAIL. > > Applied to your example, simplified, line > > xfilter "/home/phil/bin/bash_internal_variables.sh > /home/phil/t" > > makes output of command "/home/phil/bin/bash_internal_variables.sh >> /home/phil/t" new message content. As your redirected stdout to file, > there is no output, which means effectively you deleted the whole > message content. Courier sees that and does nothing, as there is > nothing to deliver. > > I think your misused xfilter command. It looks like what you want to do > is some environment logging for testing. Actually I thought that bash script would just be a convenient test - what I eventually want to do is run a Ruby script that extracts an CVS attachment from the mail, processes it and writes a the output to a file - but of course I do not want to lose the original email . . > Try to use backticks, excerpt > from the same 'man maildropfilter': > > Command substitution > Text enclosed in back-tick characters is interpreted as a shell > command. The shell command is executed as a child process by > maildrop. Its output is used in place of the command. For > example: > > DIR=`ls` > > places the names of the files in the current directory into the > DIR variable. > > The output of the command will have all newline characters > replaced by spaces, and leading and trailing spaces will be > stripped (multiple spaces are not removed, though). Also, the > contents of the message being delivered is made available to the > command on standard input. > > Here the message is not overwritten, so line next is executed normally. > So, your test code would be > > `/home/phil/bin/bash_internal_variables.sh > /home/phil/t` > > instead of > > xfilter "/home/phil/bin/bash_internal_variables.sh > /home/phil/t" That also works but the email is still not delivered as well . . an example I found in the docs is for reversing characters in lines of text: xfilter "$HOME/reverse.sh" with reverse.sh: #!/bin/sh exec 6<&0 while read -u 6 line ; do echo $line | rev done exec 6<&- exit 0 (the syntax of which I don't fully understand yet but I am guessing it is returning the text of the original email?). I used: xfilter "/home/phil/bin/reverse.sh > /home/phil/t" which, like my script worked in creating the appropriate file "t", but still does not deliver the email for the "to" line . . Thanks, Phil. -- Philip Rhoades PO Box 896 Cowra NSW 2794 Australia E-mail: [email protected] ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140