add org.ibex.mail.VERP
[org.ibex.mail.git] / src / org / ibex / mail / Script.java
index f7b259d..9459c1f 100644 (file)
@@ -13,6 +13,8 @@ import java.io.*;
 import java.util.*;
 import java.text.*;
 
+// FIXME: check for binaries (razor, clamassassin, etc) and complain if not present
+
 //
 //  - better matching syntax:
 //  - src-ip
@@ -133,8 +135,12 @@ public class Script extends JS.Obj implements Target {
            case "mail.drop": return METHOD;
            case "mail.razor": return getSub("mail.razor");
             case "mail.razor.check": return METHOD;
+           case "mail.clamav": return getSub("mail.clamav");
+            case "mail.clamav.check": return METHOD;
            case "mail.procmail": /* FEATURE */ return null;
            case "mail.vacation": /* FEATURE */ return null;
+           case "mail.verp": return getSub("mail.verp");
+           case "mail.verp.check": return METHOD;
            case "mail.dcc": return getSub("mail.dcc");
             case "mail.dcc.check": return METHOD;
             case "mail.bounce": return METHOD;
@@ -237,6 +243,21 @@ public class Script extends JS.Obj implements Target {
                    ((Message)args[0]).getStream().transcribe(new Stream(p.getOutputStream()), true);
                    return JSU.N(p.waitFor());
                }
+                if (name.equals("mail.clamav.check")) {
+                    // FIXME: this is returning "is-virus-laden" when clamdscan is unhappy -- BAD!
+                    // should use error code: 0=clean, 1=virus, 2=malfunction
+                   Process p = Runtime.getRuntime().exec("clamdscan - --stdout --quiet");
+                   ((Message)args[0]).getStream().transcribe(new Stream(p.getOutputStream()), true);
+                   int result = p.waitFor();
+                    if (result==0) return JSU.N(0);
+                    StringBuffer ret = new StringBuffer();
+                    new Stream(p.getInputStream()).transcribe(ret);
+                    return JSU.S(ret.toString());
+               }
+                if (name.equals("mail.verp.check")) {
+                    String ret = VERP.verpVerify(Address.parse(JSU.toString(a)), "SECRET".getBytes(), 0);
+                    return ret==null ? null : JSU.S(ret);
+                }
                 if (name.equals("mail.dcc.check")) {
                    Process p = Runtime.getRuntime().exec(new String[] { "dccproc", "-H" });
                    ((Message)args[0]).getStream().transcribe(new Stream(p.getOutputStream()), true);
@@ -255,19 +276,19 @@ public class Script extends JS.Obj implements Target {
                         String s = result.substring(i_body+5);
                         if (s.indexOf(' ') != -1) s = s.substring(0, s.indexOf(' '));
                         if (s.indexOf('\n') != -1) s = s.substring(0, s.indexOf('\n'));
-                        body = s.equals("many") ? 999 : Integer.parseInt(s.trim());
+                        body = s.trim().equals("many") ? 999 : Integer.parseInt(s.trim());
                     } catch (Exception e) { Log.error("", e); }
                     if (i_fuz1 != -1) try {
                         String s = result.substring(i_fuz1+5);
                         if (s.indexOf(' ') != -1) s = s.substring(0, s.indexOf(' '));
                         if (s.indexOf('\n') != -1) s = s.substring(0, s.indexOf('\n'));
-                        fuz1 = s.equals("many") ? 999 : Integer.parseInt(s.trim());
+                        fuz1 = s.trim().equals("many") ? 999 : Integer.parseInt(s.trim());
                     } catch (Exception e) { Log.error("", e); }
                     if (i_fuz2 != -1) try {
                         String s = result.substring(i_fuz2+5);
                         if (s.indexOf(' ') != -1) s = s.substring(0, s.indexOf(' '));
                         if (s.indexOf('\n') != -1) s = s.substring(0, s.indexOf('\n'));
-                        fuz2 = s.equals("many") ? 999 : Integer.parseInt(s.trim());
+                        fuz2 = s.trim().equals("many") ? 999 : Integer.parseInt(s.trim());
                     } catch (Exception e) { Log.error("", e); }
                     JSArray jsa = new JSArray();
                     jsa.put(JSU.N(0), JSU.N(body));