it compiles!
[org.ibex.mail.git] / src / org / ibex / mail / protocol / SMTP.java
index 82838a5..85d5390 100644 (file)
@@ -1,8 +1,16 @@
 package org.ibex.mail.protocol;
+import org.ibex.mail.*;
+import org.ibex.mail.store.*;
+import org.ibex.mail.target.*;
+import org.ibex.util.*;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
 public class SMTP extends MessageProtocol {
 
-    public SMTP() { setProtocolName("SMTP"); }
-    public ServerRequest createRequest(Connection conn) { return new Listener((TcpConnection)conn); }
+    public SMTP() {/* setProtocolName("SMTP"); */}
+    //public ServerRequest createRequest(Connection conn) { return new Listener((TcpConnection)conn); }
 
     public static class Outgoing {
         //  recommended retry interval is 30 minutes
@@ -13,34 +21,42 @@ public class SMTP extends MessageProtocol {
         //    only use implicit A-record if there are no MX-records
         //  use null-sender for error messages (don't send errors to the null addr)
         //  to prevent mail loops, drop messages with >100 Recieved headers
-        private final Queue queue = new Queue();
+        private final org.ibex.util.Queue queue = new org.ibex.util.Queue(100);
         public static void send(Message m) { }
         public static void enqueue(Message m) { }
         public static void bounce(Message m, String reason) { }
         private void runq() {
+            /*
             MessageStore store = MessageStore.root.slash("smtp").slash("outgoing");
             int[] outgoing = store.list();
             for(int i=0; i<outgoing.length; i++) queue.append(store.get(outgoing[i]));
             while(true) {
-                Message next = queue.dequeue(true);
+                Message next = queue.remove(true);
                 // FIXME
             }
+            */
         }
     }
 
-    private class Listener extends Incoming implements ServerRequest {
-        TcpConnection conn;
-        public Listener(TcpConnection conn) { this.conn = conn; conn.getSocket().setSoTimeout(5 * 60 * 1000); }
+    private class Listener extends Incoming /*implements ServerRequest*/ {
+        //TcpConnection conn;
+        Socket conn;
+        //public Listener(TcpConnection conn) { this.conn = conn; conn.getSocket().setSoTimeout(5 * 60 * 1000); }
+        public Listener(Socket conn) throws IOException { this.conn = conn; conn.setSoTimeout(5 * 60 * 1000); }
         public void init() { }
 
         public boolean handleRequest() throws IOException {
-            ReadStream rs = conn.getReadStream();
-            WriteStream ws = conn.getWriteStream();
-            ws.setNewLineString("\r\n");
+            //ReadStream rs = conn.getReadStream();
+            //WriteStream ws = conn.getWriteStream();
+            BufferedReader rs = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+            PrintWriter ws = new PrintWriter(new OutputStreamWriter(conn.getOutputStream()));
+
+            // FIXME
+            //ws.setNewLineString("\r\n");
 
-            ws.println("220 " + conn.getVirtualHost() + " ESMTP " + this.getClass().getName());
+            ws.println("220 " + /*conn.getVirtualHost()*/ "megacz.com" + " ESMTP " + this.getClass().getName());
 
-            Address from = null;
+            Message.Address from = null;
             Vector to = new Vector();
             // 551 = no, i won't forward that
             // 452 = mailbox full
@@ -49,13 +65,13 @@ public class SMTP extends MessageProtocol {
                 String command = rs.readLine();
                 // FIXME: validate the HELO domain argument
                 //   (double check against other end of connection? must not reject though)
-                if (hello.toUpperCase().startsWith("HELO")) {
-                    ws.println("250 HELO " + conn.getVirtualHost());
+                if (command.toUpperCase().startsWith("HELO")) {
+                    ws.println("250 HELO " + /*conn.getVirtualHost()*/("megacz.com"));
                     from = null;
                     to = new Vector();
 
-                } else if (hello.toUpperCase().startsWith("EHLO")) {
-                    ws.pritnln("250-" + conn.getVirtualHost());
+                } else if (command.toUpperCase().startsWith("EHLO")) {
+                    ws.println("250-" + /*conn.getVirtualHost()*/("megacz.com"));
                     ws.println("250-SIZE");
                     ws.println("250 PIPELINING");
                     from = null;
@@ -69,7 +85,7 @@ public class SMTP extends MessageProtocol {
                 } else if (command.toUpperCase().startsWith("MAIL FROM:")) {
                     command = command.substring(10).trim();
                     if(command.indexOf(' ') != -1) command = command.substring(0, command.indexOf(' '));
-                    from = RFC2822.Address.parse(command);
+                    from = new Message.Address(command);
 
                 } else if (command.toUpperCase().startsWith("RCPT TO:")) {
                     if (from == null) {
@@ -78,19 +94,19 @@ public class SMTP extends MessageProtocol {
                     }
                     command = command.substring(10).trim();
                     if(command.indexOf(' ') != -1) command = command.substring(0, command.indexOf(' '));
-                    to.addElement(RFC2822.Address.parse(command));
+                    to.addElement(new Message.Address(command));
 
                 } else if (command.toUpperCase().startsWith("DATA")) {
                     if (from == null) { ws.println("503 MAIL FROM command must precede DATA"); continue; }
-                    if (to.size() == null) { ws.println("503 RCPT TO 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 RFC2822 class
+                    // move this into the Message class
                     boolean good = false;
                     try {
                         good = true;
-                        Message m = new Message(line, true);
-                        Target.default.accept(m);
+                        Message m = new Message(rs, true);
+                        accept(m);
                     } finally {
                         //ws.println("251 user not local; will forward");
                         if (good) ws.println("250 OK message accepted for delivery");
@@ -104,16 +120,15 @@ public class SMTP extends MessageProtocol {
                 } else if (command.toUpperCase().startsWith("EXPN")) { ws.println("550 EXPN not available");
                 } else if (command.toUpperCase().startsWith("NOOP")) { ws.println("250 OK");
                 } else if (command.toUpperCase().startsWith("QUIT")) {
-                    ws.println("221 " + conn.getVirtualHost() + " closing connection");
+                    ws.println("221 " + /*conn.getVirtualHost()*/("megacz.com") + " closing connection");
                     break;
 
                 } else {
                     ws.println("500 unrecognized command");
                 }                    
             
-            
-                return false;  // FIXME: what does this mean?
             }
+            return false;  // FIXME: what does this mean?
         }
     }
 }