From: adam Date: Fri, 7 May 2004 11:15:10 +0000 (+0000) Subject: fixups X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=c09dcaa5936eb38ce02957a44df54a6e94a2aae7;p=org.ibex.mail.git fixups darcs-hash:20040507111510-5007d-71ff991b6498f536c87fa952fb4f8fb733638aed.gz --- diff --git a/Makefile b/Makefile index ce6e81f..bf021a7 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ -all: mail.jar +main: run clean: ; rm -rf build dist-clean: rm -rf .configure* .install* build .compile .build* sources := $(shell find src -name \*.java) +sources += upstream/org.ibex.crypto/src/org/ibex/crypto/Base36.java .download_org.ibex.%: @echo -e "\033[1mfetching repository org.ibex.$*\033[0m" @@ -20,5 +21,8 @@ sources := $(shell find src -name \*.java) mail.jar: $(sources) @make .download_org.ibex.crypto .build_org.ibex.core @mkdir -p build/class - @javac -d build/class -sourcepath upstream/org.ibex.crypto/src/ -classpath upstream/org.ibex.core/build/class $^ + @javac -d build/class -classpath upstream/org.ibex.core/build/class $^ + @cd build/class; jar cvf ../../mail.jar . +run: mail.jar + java -cp mail.jar:upstream/org.ibex.core/build/class org.ibex.mail.protocol.SMTP \ No newline at end of file diff --git a/src/org/ibex/mail/Message.java b/src/org/ibex/mail/Message.java index bac2be3..00cdf55 100644 --- a/src/org/ibex/mail/Message.java +++ b/src/org/ibex/mail/Message.java @@ -2,6 +2,7 @@ package org.ibex.mail; import org.ibex.crypto.*; import org.ibex.js.*; import org.ibex.util.*; +import org.ibex.mail.protocol.*; import java.util.*; import java.net.*; import java.io.*; @@ -48,7 +49,7 @@ public class Message extends JSReflection { } public static class StoredMessage extends Message { - public StoredMessage(/*ReadStream rs*/BufferedReader rs, boolean dotTerminatedLikeSMTP) throws IOException { + public StoredMessage(/*ReadStream rs*/SMTP.LineReader rs, boolean dotTerminatedLikeSMTP) throws IOException { super(rs, dotTerminatedLikeSMTP); uid = -1; } public final int uid; public boolean deleted = false; @@ -101,7 +102,7 @@ public class Message extends JSReflection { } // FIXME: support dotTerminatedLikeSMTP - public Message(/*ReadStream rs*/BufferedReader rs, boolean dotTerminatedLikeSMTP) throws IOException { + public Message(/*ReadStream rs*/SMTP.LineReader rs, boolean dotTerminatedLikeSMTP) throws IOException { String key = null; StringBuffer all = new StringBuffer(); String lastKey = null; diff --git a/src/org/ibex/mail/protocol/SMTP.java b/src/org/ibex/mail/protocol/SMTP.java index 85d5390..4f0b6a2 100644 --- a/src/org/ibex/mail/protocol/SMTP.java +++ b/src/org/ibex/mail/protocol/SMTP.java @@ -9,7 +9,15 @@ import java.util.*; public class SMTP extends MessageProtocol { + public static void main(String[] s) throws IOException { + SMTP smtp = new SMTP(); + ServerSocket ss = new ServerSocket(1025); + Socket sock = ss.accept(); + smtp.handle(sock); + } + public SMTP() {/* setProtocolName("SMTP"); */} + public void handle(Socket s) throws IOException { new Listener(s).handleRequest(); } //public ServerRequest createRequest(Connection conn) { return new Listener((TcpConnection)conn); } public static class Outgoing { @@ -38,6 +46,20 @@ public class SMTP extends MessageProtocol { } } + public static class LineReader extends InputStreamReader { + public LineReader(InputStream r) { super(r); } + public String readLine() throws IOException { + StringBuffer ret = new StringBuffer(); + while(true) { + int c = read(); + if (c == -1) throw new EOFException(); + if (c == '\n') return ret.toString(); + //if (c == '\r') return ret.toString(); + ret.append((char)c); + } + } + } + private class Listener extends Incoming /*implements ServerRequest*/ { //TcpConnection conn; Socket conn; @@ -48,13 +70,14 @@ public class SMTP extends MessageProtocol { public boolean handleRequest() throws IOException { //ReadStream rs = conn.getReadStream(); //WriteStream ws = conn.getWriteStream(); - BufferedReader rs = new BufferedReader(new InputStreamReader(conn.getInputStream())); + LineReader rs = new LineReader(conn.getInputStream()); PrintWriter ws = new PrintWriter(new OutputStreamWriter(conn.getOutputStream())); // FIXME //ws.setNewLineString("\r\n"); ws.println("220 " + /*conn.getVirtualHost()*/ "megacz.com" + " ESMTP " + this.getClass().getName()); + ws.flush(); Message.Address from = null; Vector to = new Vector(); @@ -67,6 +90,7 @@ public class SMTP extends MessageProtocol { // (double check against other end of connection? must not reject though) if (command.toUpperCase().startsWith("HELO")) { ws.println("250 HELO " + /*conn.getVirtualHost()*/("megacz.com")); + ws.flush(); from = null; to = new Vector(); @@ -74,6 +98,7 @@ public class SMTP extends MessageProtocol { ws.println("250-" + /*conn.getVirtualHost()*/("megacz.com")); ws.println("250-SIZE"); ws.println("250 PIPELINING"); + ws.flush(); from = null; to = new Vector(); @@ -81,25 +106,33 @@ public class SMTP extends MessageProtocol { from = null; to = new Vector(); ws.println("250 reset ok"); + ws.flush(); } else if (command.toUpperCase().startsWith("MAIL FROM:")) { command = command.substring(10).trim(); if(command.indexOf(' ') != -1) command = command.substring(0, command.indexOf(' ')); from = new Message.Address(command); + ws.println("250 " + from + " is syntactically correct"); + ws.flush(); } else if (command.toUpperCase().startsWith("RCPT TO:")) { if (from == null) { ws.println("503 MAIL FROM must precede RCPT TO"); + ws.flush(); continue; } command = command.substring(10).trim(); if(command.indexOf(' ') != -1) command = command.substring(0, command.indexOf(' ')); - to.addElement(new Message.Address(command)); + Message.Address addr = new Message.Address(command); + to.addElement(addr); + ws.println("250 " + addr + " is syntactically correct"); + ws.flush(); } else if (command.toUpperCase().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; } + if (from == null) { ws.println("503 MAIL FROM command must precede DATA"); ws.flush(); continue; } + if (to == null) { ws.println("503 RCPT TO command must precede DATA"); ws.flush(); continue; } ws.println("354 Enter message, ending with \".\" on a line by itself"); + ws.flush(); StringBuffer data = new StringBuffer(); // move this into the Message class boolean good = false; @@ -109,22 +142,25 @@ public class SMTP extends MessageProtocol { accept(m); } finally { //ws.println("251 user not local; will forward"); - if (good) ws.println("250 OK message accepted for delivery"); + if (good) { ws.println("250 OK message accepted for delivery"); ws.flush(); } else { /* FIXME */ } } } else if (command.toUpperCase().startsWith("HELP")) { ws.println("214 sorry, you are beyond help. please see a trained professional."); + ws.flush(); } else if (command.toUpperCase().startsWith("VRFY")) { // FIXME, see code 252 - } 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("EXPN")) { ws.println("550 EXPN not available"); ws.flush(); + } else if (command.toUpperCase().startsWith("NOOP")) { ws.println("250 OK"); ws.flush(); } else if (command.toUpperCase().startsWith("QUIT")) { ws.println("221 " + /*conn.getVirtualHost()*/("megacz.com") + " closing connection"); + ws.flush(); break; } else { ws.println("500 unrecognized command"); + ws.flush(); } }