it compiles
authoradam <adam@megacz.com>
Sat, 8 May 2004 01:08:35 +0000 (01:08 +0000)
committeradam <adam@megacz.com>
Sat, 8 May 2004 01:08:35 +0000 (01:08 +0000)
darcs-hash:20040508010835-5007d-b6e174251f3e09dc090ced44681a1ead84322964.gz

24 files changed:
mail.jar
src/org/ibex/mail/Message.java
src/org/ibex/mail/Target.java
src/org/ibex/mail/filter/Anonymizer.java
src/org/ibex/mail/filter/DCC.java
src/org/ibex/mail/filter/HTML2Text.java
src/org/ibex/mail/filter/PGP.java
src/org/ibex/mail/filter/ReturnReciept.java
src/org/ibex/mail/filter/RewriteFilter.java
src/org/ibex/mail/filter/SingleUse.java
src/org/ibex/mail/filter/SpamAssassin.java
src/org/ibex/mail/filter/SpamFilter.java
src/org/ibex/mail/filter/VipulsRazor.java
src/org/ibex/mail/protocol/SMTP.java
src/org/ibex/mail/target/Bounce.java
src/org/ibex/mail/target/Darcs.java
src/org/ibex/mail/target/FileSystem.java
src/org/ibex/mail/target/LMTP.java
src/org/ibex/mail/target/List.java
src/org/ibex/mail/target/Pipe.java
src/org/ibex/mail/target/Procmail.java
src/org/ibex/mail/target/Script.java
src/org/ibex/mail/target/Vacation.java
src/org/ibex/mail/target/XMLRPC.java

index e5ad502..418b89d 100644 (file)
Binary files a/mail.jar and b/mail.jar differ
index c593a8a..85ab516 100644 (file)
@@ -9,7 +9,7 @@ import java.io.*;
 
 // soft line limit (suggested): 78 chars /  hard line limit: 998 chars
 // folded headers: can insert CRLF anywhere that whitespace appears (before the whitespace)
-// date/time parsing: see 3.3
+// date/time parsing: see spec, 3.3
 
 // FEATURE: MIME RFC2045, 2046, 2049
 // FEATURE: PGP-signature-parsing
@@ -37,7 +37,7 @@ public class Message extends JSReflection {
     public final Address envelopeFrom;
     public final Address[] envelopeTo;
 
-    public final Date arrival = null;   // when the message first arrived at this machine
+    public final Date arrival;         // when the message first arrived at this machine
     
     public void dump(OutputStream os) throws IOException {
         Writer w = new OutputStreamWriter(os);
@@ -47,6 +47,7 @@ public class Message extends JSReflection {
         w.flush();
     }
 
+        /*
     public static class StoredMessage extends Message {
         public int uid;
         public boolean deleted = false;
@@ -54,6 +55,7 @@ public class Message extends JSReflection {
         public boolean answered = false;
         public StoredMessage(LineReader rs) throws IOException, MailException.Malformed { super(rs); }
     }
+        */
 
     public class Trace {
         final String returnPath;
@@ -94,7 +96,7 @@ public class Message extends JSReflection {
     }
 
     public static class Malformed extends MailException.Malformed { public Malformed(String s) { super(s); } }
-    public Message(Address envelopeFrom, Address envelopeTo, LineReader rs) throws IOException, Malformed {
+    public Message(Address envelopeFrom, Address[] envelopeTo, LineReader rs) throws IOException, MailException.Malformed {
         this.envelopeFrom = envelopeFrom;
         this.envelopeTo = envelopeTo;
         this.arrival = new Date();
@@ -132,7 +134,7 @@ public class Message extends JSReflection {
             }            
         }
 
-        this.date      = headers.get("Date");
+        this.date      = (Date)headers.get("Date");
         this.to        = new Address((String)headers.get("To"));
         this.from      = new Address((String)headers.get("From"));
         this.replyto   = new Address((String)headers.get("Reply-To"));
@@ -141,14 +143,14 @@ public class Message extends JSReflection {
         if (headers.get("Cc") != null) {
             StringTokenizer st = new StringTokenizer((String)headers.get("Cc"));
             this.cc = new Address[st.countTokens()];
-            for(int i=0; i<cc.length; i++) cc[i] = st.nextToken();
+            for(int i=0; i<this.cc.length; i++) this.cc[i] = new Address(st.nextToken());
         } else {
             this.cc = new Address[0];
         }
         if (headers.get("Bcc") != null) {
             StringTokenizer st = new StringTokenizer((String)headers.get("Bcc"));
             this.bcc = new Address[st.countTokens()];
-            for(int i=0; i<bcc.length; i++) bcc[i] = st.nextToken();
+            for(int i=0; i<this.bcc.length; i++) this.bcc[i] = new Address(st.nextToken());
         } else {
             this.bcc = new Address[0];
         }
@@ -176,10 +178,10 @@ public class Message extends JSReflection {
 
     public String summary() {
         return
-            "          Subject: " + m.subject + "\n" +
-            "     EnvelopeFrom: " + m.envelopeFrom + "\n" +
-            "       EnvelopeTo: " + m.envelopeTo + "\n" +
-            "        MessageId: " + m.messageid;
+            "          Subject: " + subject + "\n" +
+            "     EnvelopeFrom: " + envelopeFrom + "\n" +
+            "       EnvelopeTo: " + envelopeTo + "\n" +
+            "        MessageId: " + messageid;
     }
 
     public Message bounce(String reason) {
index 0fea645..c30d573 100644 (file)
@@ -4,6 +4,6 @@ import org.ibex.js.*;
 
 /** base class for mail message "destinations" */
 public class Target {
-    public static final Target root = Script.root;
+    public static final Target root = Script.root();
     public void accept(Message m) throws IOException, MailException { /* FIXME */ }
 }
index 6544d41..4290059 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.filter;
+import org.ibex.mail.*;
 /** anonymizes mail messages */
 public class Anonymizer extends Filter {
 }
index 6f1eb0f..26a1483 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.filter;
+import org.ibex.mail.*;
 /** implements the Distributed Checksum Clearinghouse spam filtering protocol */
 public class DCC extends SpamFilter {
 }
index d45a468..4a26d06 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.filter;
+import org.ibex.mail.*;
 /** converts text/html parts into nice ASCII text for mutt/gnus/pine/etc */
 public class HTML2Text extends Filter {
 }
index 35a04ce..b013e6c 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.filter;
+import org.ibex.mail.*;
 /** checks PGP signatures on incoming mail */
 public class PGP extends Filter {
 }
index 33603d2..89c4ec6 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.filter;
+import org.ibex.mail.*;
 /** sticks a 1x1 gif in outbound messages so we can tell when the message is read */
 public class ReturnReciept extends Filter {
 }
index 039f5f1..653df4a 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.filter;
+import org.ibex.mail.*;
 /** a flexible, regexp-based email address rewriting engine */
 public class RewriteFilter extends Filter {
 }
index 37f317f..51d5b39 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.filter;
+import org.ibex.mail.*;
 /** tags outgoing messages with a single-use email address */
 public class SingleUse extends Filter {
 }
index 5a427b1..a19ea4b 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.filter;
+import org.ibex.mail.*;
 /** invokes SpamAssassin */
 public class SpamAssassin extends SpamFilter {
 }
index bc075d7..8a1d75c 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.filter;
+import org.ibex.mail.*;
 /** base class for spam filters */
 public class SpamFilter extends Filter {
 }
index f2479d5..d0eb105 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.filter;
+import org.ibex.mail.*;
 /** invokes Vipul's Razor */
 public class VipulsRazor extends SpamFilter {
 }
index f996c09..b764b7e 100644 (file)
@@ -20,7 +20,7 @@ public class SMTP extends MessageProtocol {
         convdir = System.getProperty("ibex.mail.root", File.separatorChar + "var" + File.separatorChar + "org.ibex.mail");
         convdir += File.separatorChar + "conversation";
         new File(convdir).mkdirs();
-        SMTP smtp = new SMTP();
+        final SMTP smtp = new SMTP();
         int port = Integer.parseInt(System.getProperty("ibex.mail.port", "25"));
         Log.info(SMTP.class, "binding to port " + port + "...");
         ServerSocket ss = new ServerSocket(port);
@@ -40,49 +40,53 @@ public class SMTP extends MessageProtocol {
     public static class Outgoing {
         private static final HashSet deadHosts = new HashSet();
         private static final org.ibex.util.Queue queue = new org.ibex.util.Queue(100);
-        private static FileSystem store = FileSystem.root.slash("outgoing");
 
-        public static void send(Message m) {
+        public static void send(Message m) throws IOException {
             if (m.traces.length >= 100) {
-                Log.warn("Message with " + m.traces.length + " trace hops; silently dropping\n" + m.summary());
+                Log.warn(SMTP.Outgoing.class,
+                         "Message with " + m.traces.length + " trace hops; silently dropping\n" + m.summary());
                 return;
             }
             synchronized(Outgoing.class) {
-                store.add(m);
+                FileSystem.root.slash("outgoing").add(m);
                 queue.append(m);
                 Outgoing.class.notify();
             }
         }
 
-        private static boolean attempt(Message m) {
-            InetAddress[] mx = getMailExchangerIPs(m.envelopeTo.host);
+        // FIXME!!! ignores more than one destination envelope!!!!
+        private static boolean attempt(Message m) throws IOException {
+            InetAddress[] mx = getMailExchangerIPs(m.envelopeTo[0].host);
             if (mx.length == 0) {
-                Log.warn("could not resolve " + m.envelopeTo.host + "; bouncing it\n" + m.summary());
-                send(m.bounce("could not resolve " + m.envelopeTo.host));
+                Log.warn(SMTP.Outgoing.class, "could not resolve " + m.envelopeTo[0].host + "; bouncing it\n" + m.summary());
+                send(m.bounce("could not resolve " + m.envelopeTo[0].host));
                 return true;
             }
             if (new Date().getTime() - m.arrival.getTime() > 1000 * 60 * 60 * 24 * 5) {
-                Log.warn("could not send message after 5 days; bouncing it\n" + m.summary());
+                Log.warn(SMTP.Outgoing.class, "could not send message after 5 days; bouncing it\n" + m.summary());
                 send(m.bounce("could not send for 5 days"));
                 return true;
             }
             for(int i=0; i<mx.length; i++) {
                 if (deadHosts.contains(mx[i])) continue;
-                if (attempt(m, mx[i])) { queue.remove(m); return true; }
+                if (attempt(m, mx[i])) { return true; }
             }
             return false;
         }
 
+        private static void check(String s) throws IOException {
+            if (s.startsWith("4") || s.startsWith("5")) throw new IOException("SMTP Error: " + s); }
         private static boolean attempt(Message m, InetAddress mx) {
             try {
-                String conversationId = getConversation();
+                String vhost = InetAddress.getLocalHost().getHostName();
+                String cid = getConversation();
                 PrintWriter logf = new PrintWriter(new OutputStreamWriter(new FileOutputStream(convdir+File.separatorChar+cid)));
                 Log.setThreadAnnotation("[outgoing smtp: " + mx + " / " + cid + "] ");
                 Log.info(SMTP.Outgoing.class, "connecting...");
                 Socket s = new Socket(mx, 25);
                 Log.info(SMTP.Outgoing.class, "connected");
-                LineReader  r = new LoggedLineReader(new InputStreamReader(conn.getInputStream()), logf);
-                PrintWriter w = new LoggedPrintWriter(new OutputStreamWriter(conn.getOutputStream()), logf);
+                LineReader  r = new LoggedLineReader(new InputStreamReader(s.getInputStream()), logf);
+                PrintWriter w = new LoggedPrintWriter(new OutputStreamWriter(s.getOutputStream()), logf);
                                                                   check(r.readLine());  // banner
                 w.print("HELO " + vhost + "\r\n");                check(r.readLine());
                 w.print("MAIL FROM: " + m.envelopeFrom + "\r\n"); check(r.readLine());
@@ -92,7 +96,7 @@ public class SMTP extends MessageProtocol {
                 w.print(".\r\n");
                 check(r.readLine());
                 Log.info(SMTP.Outgoing.class, "message accepted by " + mx);
-                m.delete();
+                FileSystem.root.slash("outgoing").delete(m);
                 s.close();
                 return true;
             } catch (Exception e) {
@@ -105,22 +109,33 @@ public class SMTP extends MessageProtocol {
         }
 
         static void runq() {
-            Log.setThreadAnnotation("[outgoing smtp] ");
-            int[] outgoing = store.list();
-            Log.info("outgoing thread started; " + outgoing.length + " messages to send");
-            for(int i=0; i<outgoing.length; i++) queue.append(store.get(outgoing[i]));
-            while(true) {
-                int num = queue.size();
-                for(int i=0; i<num; i++) {
-                    Message next = queue.remove(true);
-                    if (!attempt(next)) queue.append(next);
-                }
-                synchronized(Outgoing.class) {
-                    Log.info("outgoing thread going to sleep");
-                    Outgoing.class.wait(10 * 60 * 1000);
-                    deadHosts.clear();
-                    Log.info("outgoing thread woke up; " + queue.size() + " messages in queue");
+            try {
+                Log.setThreadAnnotation("[outgoing smtp] ");
+                int[] outgoing = FileSystem.root.slash("outgoing").list();
+                Log.info(SMTP.Outgoing.class, "outgoing thread started; " + outgoing.length + " messages to send");
+                for(int i=0; i<outgoing.length; i++) queue.append(FileSystem.root.slash("outgoing").get(outgoing[i]));
+                while(true) {
+                    int num = queue.size();
+                    for(int i=0; i<num; i++) {
+                        Message next = (Message)queue.remove(true);
+                        boolean good = false;
+                        try {
+                            good = attempt(next);
+                        } catch (IOException e) {
+                            Log.error(SMTP.Outgoing.class, e);
+                        } finally {
+                            if (!good) queue.append(next);
+                        }
+                    }
+                    synchronized(Outgoing.class) {
+                        Log.info(SMTP.Outgoing.class, "outgoing thread going to sleep");
+                        Outgoing.class.wait(10 * 60 * 1000);
+                        deadHosts.clear();
+                        Log.info(SMTP.Outgoing.class, "outgoing thread woke up; " + queue.size() + " messages in queue");
+                    }
                 }
+            } catch (Exception e) {
+                Log.error(SMTP.Outgoing.class, e);
             }
         }
     }
@@ -162,38 +177,6 @@ public class SMTP extends MessageProtocol {
             return false;
         }
         
-        static String getConversation() {
-            String time = new SimpleDateFormat("yy.MMM.dd-hh:mm:ss").format(new Date());
-            synchronized (SMTP.class) {
-                if (lastTime != null && lastTime.equals(time)) {
-                    time += "." + (++lastCounter);
-                } else {
-                    lastTime = time;
-                }
-            }
-            return time;
-        }
-
-        private class LoggedLineReader extends LineReader {
-            PrintWriter log;
-            public LoggedLineReader(Reader r, PrintWriter log) { super(r); this.log = log; }
-            public String readLine() throws IOException {
-                String s = super.readLine();
-                if (s != null) { log.println("C: " + s); log.flush(); }
-                return s;
-            }
-        }
-
-        private class LoggedPrintWriter extends PrintWriter {
-            PrintWriter log;
-            public LoggedPrintWriter(Writer w, PrintWriter log) { super(w); this.log = log; }
-            public void println(String s) {
-                log.println("S: " + s);
-                super.println(s);
-                flush();
-            }
-        }
-
         public boolean handleRequest(LineReader rs, PrintWriter ws) throws IOException, MailException {
             //ReadStream rs = conn.getReadStream();
             //WriteStream ws = conn.getWriteStream();
@@ -234,28 +217,37 @@ public class SMTP extends MessageProtocol {
                     command = command.substring(9).trim();
                     if(command.indexOf(' ') != -1) command = command.substring(0, command.indexOf(' '));
                     Address addr = new Address(command);
-                    // FIXME: 551 = no, i won't forward that
+                    InetAddress[] mx = getMailExchangerIPs(addr.host);
                     to.addElement(addr);
-                    ws.println("250 " + addr + " is syntactically correct");
+                    if (((InetSocketAddress)conn.getRemoteSocketAddress()).getAddress().isLoopbackAddress()) {
+                        ws.println("250 you are connected locally, so I will let you send");
+                    } else {
+                        boolean good = false;
+                        for(int i=0; !good && i<mx.length; i++)
+                            if (NetworkInterface.getByInetAddress(mx[i]) != null)
+                                good = true;
+                        if (!good) {
+                            ws.println("551 sorry, " + addr + " is not on this machine");
+                            return false;
+                        }
+                        ws.println("250 " + addr + " is on this machine; I will deliver it");
+                    }
 
                 } else if (c.startsWith("DATA")) {
                     if (from == null) { ws.println("503 MAIL FROM command must precede DATA"); continue; }
                     if (to == null) { ws.println("503 RCPT TO command must precede DATA"); continue; }
                     ws.println("354 Enter message, ending with \".\" on a line by itself");
-                    StringBuffer data = new StringBuffer();
-                    // move this into the Message class
-                    boolean good = false;
                     try {
-                        accept(new Message(new DotTerminatedLineReader(rs)));
-                    } catch (MailException.Malformed mfe) {
-                        ws.println("501 " + mfe.toString()); break;
-                    } catch (MailException.MailboxFull mbf) {
-                        ws.println("452 " + mbf);
-                    } catch (IOException ioe) {
-                        ws.println("554 " + ioe.toString()); break;
+                        Address[] toArr = new Address[to.size()];
+                        to.copyInto(toArr);
+                        accept(new Message(from, toArr, new DotTerminatedLineReader(rs)));
+                        ws.println("250 message accepted");
+                    } catch (MailException.Malformed mfe) {   ws.println("501 " + mfe.toString());
+                    } catch (MailException.MailboxFull mbf) { ws.println("452 " + mbf);
+                    } catch (IOException ioe) {               ws.println("554 " + ioe.toString());
                     }
-                    ws.println("250 message accepted"); break;
-                    
+                    break;
+
                 } else if (c.startsWith("HELP")) { ws.println("214 you are beyond help.  see a trained professional.");
                 } else if (c.startsWith("VRFY")) { ws.println("252 We don't VRFY; proceed anyway");
                 } else if (c.startsWith("EXPN")) { ws.println("550 EXPN not available");
@@ -282,8 +274,8 @@ public class SMTP extends MessageProtocol {
         }
     }
 
-    public InetAddress[] getMailExchangerIPs(String domainName) {
-        InetAddress ret;
+    public static InetAddress[] getMailExchangerIPs(String hostName) {
+        InetAddress[] ret;
         try {
             Hashtable env = new Hashtable();
             env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
@@ -293,10 +285,10 @@ public class SMTP extends MessageProtocol {
             if (attr == null) {
                 ret = new InetAddress[1];
                 try {
-                    ret[0] = InetAddress.getByName(domainName);
+                    ret[0] = InetAddress.getByName(hostName);
                     return ret;
                 } catch (UnknownHostException uhe) {
-                    Log.warn(SMTP.class, "no MX hosts or A record for " + domainName);
+                    Log.warn(SMTP.class, "no MX hosts or A record for " + hostName);
                     return new InetAddress[0];
                 }
             } else {
@@ -305,12 +297,43 @@ public class SMTP extends MessageProtocol {
                 for(int i=0; ne.hasMore(); i++) ret[i] = (InetAddress)ne.next();
             }
         } catch (Exception e) {
-            Log.warn(SMTP.class, "couldn't find MX host for " + domainName + " due to");
+            Log.warn(SMTP.class, "couldn't find MX host for " + hostName + " due to");
             Log.warn(SMTP.class, e);
             return new InetAddress[0];
         }
         return ret;
     }
 
+    private static class LoggedLineReader extends LineReader {
+        PrintWriter log;
+        public LoggedLineReader(Reader r, PrintWriter log) { super(r); this.log = log; }
+        public String readLine() throws IOException {
+            String s = super.readLine();
+            if (s != null) { log.println("C: " + s); log.flush(); }
+            return s;
+        }
+    }
+
+    private static class LoggedPrintWriter extends PrintWriter {
+        PrintWriter log;
+        public LoggedPrintWriter(Writer w, PrintWriter log) { super(w); this.log = log; }
+        public void println(String s) {
+            log.println("S: " + s);
+            super.println(s);
+            flush();
+        }
+    }
+
+    static String getConversation() {
+        String time = new SimpleDateFormat("yy.MMM.dd-hh:mm:ss").format(new Date());
+        synchronized (SMTP.class) {
+            if (lastTime != null && lastTime.equals(time)) {
+                time += "." + (++lastCounter);
+            } else {
+                lastTime = time;
+            }
+        }
+        return time;
+    }
 
 }
index 37d1090..1455e92 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.target;
+import org.ibex.mail.*;
 /** bounces a message */
 public class Bounce extends Target {
 }
index 3b3c0d8..8c533d4 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.target;
+import org.ibex.mail.*;
 /** simple class to handle darcs patches */
 public class Darcs extends Pipe {
 }
index edfd112..ab277a2 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.target;
+import org.ibex.mail.*;
 import org.ibex.util.*;
 import org.ibex.mail.*;
 import java.io.*;
@@ -11,11 +12,11 @@ public class FileSystem {
 
     private static final String STORAGE_ROOT =
         System.getProperty("ibex.mail.root", File.separatorChar + "var" + File.separatorChar + "org.ibex.mail");
-
-    //public final FileBased root = new FileBased(STORAGE_ROOT + File.separatorChar);
+    public static FileBased root = null;
     public static Transcript transcript = null;
     static {
         try {
+            root = new FileBased(STORAGE_ROOT + File.separatorChar);
             transcript = new Transcript(STORAGE_ROOT + File.separatorChar + "transcript");
         } catch (Exception e) {
             e.printStackTrace();
@@ -27,9 +28,11 @@ public class FileSystem {
     public int[] list() { throw new Error(this.getClass().getName() + " does not support the list() method"); }
     public int add(Message message) throws IOException {
         throw new Error(this.getClass().getName() + " does not support the add() method"); }
-    public Message.StoredMessage get(int messagenum) throws IOException {
+    public int delete(Message message) throws IOException {
+        throw new Error(this.getClass().getName() + " does not support the delete() method"); }
+    public Message get(int messagenum) throws IOException {
         throw new Error(this.getClass().getName() + " does not support the get() method"); }
-    public Message.StoredMessage[] query(int maxResults) {
+    public Message[] query(int maxResults) {
         throw new Error(this.getClass().getName() + " does not support the query() method"); }
 
     /** a fast-write, slow-read place to stash all messages we touch -- in case of a major f*ckup */
@@ -97,23 +100,26 @@ public class FileSystem {
             return target;
         }
 
-        public Message.StoredMessage get(int messagenum) throws IOException {
+        public Message get(int messagenum) throws IOException {
             File f = new File(path + File.separatorChar + messagenum + ".");        
             if (!f.exists()) throw new FileNotFoundException(f.toString());
-            try {
-                Message.StoredMessage ret =
-                    new Message.StoredMessage(new LineReader(new InputStreamReader(new FileInputStream(f))));
+            //try {
+                // FIXME: need to store envelope from/to
+                //Message ret = new Message(new LineReader(new InputStreamReader(new FileInputStream(f))));
                 // FIXME: set answered/read/etc here
-                return ret;
+                //return ret;
+                return null;
+                /*
             } catch (MailException.Malformed malf) {
                 Log.error(this, "This should never happen");
                 Log.error(this, malf);
                 return null;
             }
+                */
         }
 
         // query types: stringmatch (headers, body), header element, deletion status, date range, message size
-        public Message.StoredMessage[] query(int maxResults) {
+        public Message[] query(int maxResults) {
             throw new RuntimeException("FileBased.query() not implemented yet");
         }
 
index 3f230d2..a88a801 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.target;
+import org.ibex.mail.*;
 /** implementation of the Local Mail Transport Protocol */
 public class LMTP extends Target {
 }
index b8860fd..e919643 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.target;
+import org.ibex.mail.*;
 /** A full-featured mailing list manager */
 public class List extends Target {
 }
index 5ac2f1c..fb26b88 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.target;
+import org.ibex.mail.*;
 /** generic pipe-the-message-to-a-file target */
 public class Pipe extends Target {
 }
index ab16ecc..bbdf6e1 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.target;
+import org.ibex.mail.*;
 /** callout to support legacy .procmailrc files */
 public class Procmail extends Pipe {
 }
index ff16b57..65746b3 100644 (file)
@@ -2,6 +2,7 @@
 package org.ibex.mail;
 import org.ibex.js.*;
 import org.ibex.util.*;
+import org.ibex.mail.*;
 import org.ibex.mail.filter.*;
 import org.ibex.mail.target.*;
 import java.io.*;
@@ -11,15 +12,21 @@ public class Script extends Target {
 
     private static Script root = null;
     private static final String DEFAULT_CONF = File.separatorChar + "etc" + File.separatorChar + "org.ibex.mail.conf";
-    public static Script root() throws JSExn, IOException {
-        if (root == null) root = new Script(System.getProperty("ibex.mail.conf", DEFAULT_CONF));
-        return root;
+    public static Script root() {
+        try {
+            if (root == null) root = new Script(System.getProperty("ibex.mail.conf", DEFAULT_CONF));
+            return root;
+        } catch (Exception e) {
+            Log.error(Script.class, e);
+            return null;
+        }
     }
 
     final JS js;
+    private Message m = null;
     public Script(String filePath) throws JSExn, IOException {
         js = JS.cloneWithNewParentScope(JS.fromReader(filePath, 0, new InputStreamReader(new FileInputStream(filePath))),
-                                        new ScriptScope(null)); }
+                                        new ScriptScope()); }
 
     private class ScriptScope extends JSScope {
         ScriptEnv env = new ScriptEnv();
@@ -31,7 +38,7 @@ public class Script extends Target {
         }
     }
 
-    public synchronized void accept(Message m) throws IOException {
+    public synchronized void accept(Message m) throws IOException, MailException {
         this.m = m;
         try {
             Object ret = js.call(m, null, null, null, 1);
index f8e71d9..5f6ec63 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.target;
+import org.ibex.mail.*;
 /** functionality similar to the UNIX vacation command */
 public class Vacation extends Target {
 }
index ec6ca7c..d67417e 100644 (file)
@@ -1,4 +1,5 @@
 package org.ibex.mail.target;
+import org.ibex.mail.*;
 /** an XML-RPC <i>server</i> which accepts requests sent via SMTP */
 public class XMLRPC extends Target {
 }