mailing list improvements
[org.ibex.mail.git] / src / org / ibex / mail / target / Script.java
index b509b86..616d5ac 100644 (file)
@@ -17,7 +17,7 @@ public class Script extends JS.Obj implements Target {
     private static final JS.Method METHOD = new JS.Method();
 
     private static Script root = null;
-    private static final String DEFAULT_CONF = File.separatorChar + "etc" + File.separatorChar + "org.ibex.mail.conf";
+    private static final String DEFAULT_CONF = Mailbox.STORAGE_ROOT + "conf" + File.separatorChar + "inbound.js";
     public static Script root() {
         try {
             if (root == null) root = new Script(System.getProperty("ibex.mail.conf", DEFAULT_CONF));
@@ -129,12 +129,15 @@ public class Script extends JS.Obj implements Target {
             case "mail.bounce": return METHOD;
             case "mail.reject": return METHOD;
             case "mail.my": return getSub("mail.my");
+            case "mail.dir": return METHOD;
+            case "mail.shell": return METHOD;
             case "mail.my.prefs": try {
                     return new org.ibex.js.Directory(new File("/etc/org.ibex.mail.prefs"));
             } catch (IOException e) { throw new JSExn(e.toString()); }
+            case "mail.whitelist": return JSReflection.wrap(org.ibex.mail.protocol.SMTP.whitelist);
             case "mail.my.mailbox":
-                FileBasedMailbox root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT, true);
-                return root.slash("user", true).slash("megacz", true).slash("newmail", true);
+                Mailbox root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT, true);
+                return root.slash("user", true).slash("megacz", true);
             case "mail.list": return METHOD;
             //#end
             return super.get(name);
@@ -148,7 +151,33 @@ public class Script extends JS.Obj implements Target {
             String name = JSU.toString(name0);
             try {
                 if (name.equals("url.encode")) return JSU.S(java.net.URLEncoder.encode(JSU.toString(args[0])));
-                if (name.equals("mail.list")) return JSReflection.wrap(MailingList.getMailingList(JSU.toString(args[0])));
+                if (name.equals("mail.list")) return JSReflection.wrap(FileBasedMailbox.getFileBasedMailbox(JSU.toString(args[0]), false));
+                if (name.equals("mail.dir")) {
+                    return new org.ibex.js.Directory(new File(JSU.toString(args[0])));
+                }
+                if (name.equals("mail.shell")) {
+                    // FIXME: EEEEEVIL!
+                    Log.warn("dbug", args[0].getClass().getName());
+                    Log.warn("dbug", args[1].getClass().getName());
+                    final Process p = Runtime.getRuntime().exec(JSU.toString(args[1]));
+                    Message m = (Message)args[0];
+                    new Thread() {
+                        public void run() {
+                            try {
+                                BufferedReader br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+                                String s = null;
+                                while((s = br.readLine())!=null) 
+                                    Log.warn("shell", s);
+                            } catch (Exception e) { e.printStackTrace(); }
+                        }
+                    }.start();
+                    OutputStream os = p.getOutputStream();
+                    Stream stream = new Stream(os);
+                    m.getStream().transcribe(stream);
+                    stream.close();
+                    p.waitFor();
+                    return null;
+                }
                 if (name.equals("date")) { return new JSDate(args); }
                 if (name.equals("mail.send") || name.equals("send") || name.equals("mail.attempt") || name.equals("attempt")) {
                     boolean attempt = name.equals("mail.attempt") || name.equals("attempt");