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
// 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
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;
} 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) {
}
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");
} 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?
}
}
}