0

I'm trying to run some custom parsing on incoming mail using procmail, and would like to call a java program to read in the headers and body of the message using the |pipe to stdin. There are plenty of examples of having your mail filtered using perl, and python, but none using java. As a starting example, my procmail recipe:

:0 hbfW
|"/usr/bin/java -cp /root/parser HelloWorldApp"

And my java app just echo's stdin:

import java.io.*;
public class HelloWorldApp {
 public static void main(String[] args) {
 InputStreamReader isReader = new InputStreamReader(System.in);
BufferedReader bufReader = new BufferedReader(isReader);
while(true){
    try {
        String inputStr = null;
        if((inputStr=bufReader.readLine()) != null) {
            System.out.println(inputStr);
        }
        else {
            break;
        }
    }
    catch (Exception e) {
       break;
    }
  }
 }
}

procmail log:

procmail: Executing "/usr/bin/java -cp /root/parser HelloWorldApp"
/bin/sh: /usr/bin/java HelloWorldApp: No such file or directory
procmail: Error while writing to "/usr/bin/java HelloWorldApp"
procmail: Rescue of unfiltered data succeeded

1) Am I creating the right recipie to pipe the data to java? 2) Since I still want procmail to handle delivery, my recipe using the (f) flag. But how to I have the result created from my java program sent back to procmail? stdout?

2 Answers2

1

remove the quotation marks around "/usr/bin/java -cp /root/parser HelloWorldApp".

source: http://www.linfo.org/pipe.html

Jakob Weisblat
  • 7,450
  • 9
  • 37
  • 65
  • That is what I had originally, but the log makes it seem like it's executing multiple commands instead of one. Here what I got back without the quotes, so I think there is something larger I'm missing here. `procmail: Assigning "INCLUDERC=/home/vmail/perimetric.com/script/Procmail/rc.java" procmail: Executing "/usr/bin/java,-cp,/root/parser,HelloWorldApp" Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp` – Greg Dreisen Sep 11 '11 at 02:07
  • No problem with your Procmail syntax there, the commas are just to show you how the command line was parsed into individual arguments. Can't help you interpret the error message from Java, though. I guess you need something like a Java classpath. – tripleee Sep 12 '11 at 11:52
0

The "filter" flag on your recipe specifies that the pipeline will read a message on standard input and write back a (possibly not altered) message on standard output, which will replace the original message.

As Jake223 already replied, the quotation marks around the command are incorrect, and should be removed. The error message doesn't really look like it corresponds to that particular error, though.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Thanks for in help guys. I hunted it down today. It looks like procmail was having trouble accessing the classpath. I moved the files inside the home directory and it ran without complaint. I'm guessing procmail runs with some sort of limited permissions? And you were right, no quotes. :-P – Greg Dreisen Sep 13 '11 at 16:48
  • Not limited permissions, but certainly a pared-down environment, unless you read the manual page to see how to change that. You can also change the environment from within your .procmailrc. – tripleee Sep 13 '11 at 19:08