From 03ba920b245d6395b5139000ea5461d9eee0116a Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 2 May 2004 09:14:38 +0000 Subject: [PATCH] it compiles! darcs-hash:20040502091438-5007d-35330f6d9d248a67a1745654f442c609e6b43771.gz --- Makefile | 24 +++++ src/org/ibex/mail/MailException.java | 5 +- src/org/ibex/mail/Message.java | 51 +++++++-- src/org/ibex/mail/filter/Filter.java | 2 + src/org/ibex/mail/protocol/Incoming.java | 10 +- src/org/ibex/mail/protocol/MessageProtocol.java | 6 +- src/org/ibex/mail/protocol/SMTP.java | 65 ++++++----- src/org/ibex/mail/store/MessageStore.java | 50 +++++---- src/org/ibex/mail/target/Script.java | 131 ++++++++++++----------- src/org/ibex/mail/target/Target.java | 7 +- 10 files changed, 222 insertions(+), 129 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ce6e81f --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +all: mail.jar + +clean: ; rm -rf build +dist-clean: + rm -rf .configure* .install* build .compile .build* + +sources := $(shell find src -name \*.java) + +.download_org.ibex.%: + @echo -e "\033[1mfetching repository org.ibex.$*\033[0m" + @mkdir -p upstream; cd upstream; rm -rf org.ibex.$*; rm -rf org.ibex.$*_* + @cd upstream; darcs get --verbose --partial --repo-name=org.ibex.$* http://$*.ibex.org + @touch $@ + +.build_org.ibex.%: + @echo -e "\033[1mbuilding repository org.ibex.$*\033[0m" + @cd upstream/org.ibex.$*; make compile + @touch $@ + +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 $^ + diff --git a/src/org/ibex/mail/MailException.java b/src/org/ibex/mail/MailException.java index b869042..6bb7ef9 100644 --- a/src/org/ibex/mail/MailException.java +++ b/src/org/ibex/mail/MailException.java @@ -1,3 +1,6 @@ +package org.ibex.mail; +import java.net.*; +import java.io.*; public class MailException extends Exception { @@ -5,7 +8,7 @@ public class MailException extends Exception { public static class RelayingDenied extends MailException { } public static class IOException extends MailException { // FIXME: fill in stack trace - final IOException ioe; + final java.io.IOException ioe; public IOException(java.io.IOException ioe) { this.ioe = ioe; } } diff --git a/src/org/ibex/mail/Message.java b/src/org/ibex/mail/Message.java index 3effcfa..bac2be3 100644 --- a/src/org/ibex/mail/Message.java +++ b/src/org/ibex/mail/Message.java @@ -1,5 +1,11 @@ package org.ibex.mail; import org.ibex.crypto.*; +import org.ibex.js.*; +import org.ibex.util.*; +import java.util.*; +import java.net.*; +import java.io.*; + // FIXME MIME: RFC2045, 2046, 2049 // NOTE: always use Win32 line endings // hard line limit: 998 chars @@ -19,6 +25,7 @@ public class Message extends JSReflection { public final String allHeaders; // pristine headers public final Hashtable headers; // hash of headers (not including resent's and traces) + public final String body; // entire body // parsed header fields public final Date date; @@ -36,12 +43,22 @@ public class Message extends JSReflection { public final Address envelopeFrom; public final Address[] envelopeTo; + public void dump(OutputStream os) { + Log.error(this, "not implemented"); + } + public static class StoredMessage extends Message { + public StoredMessage(/*ReadStream rs*/BufferedReader rs, boolean dotTerminatedLikeSMTP) throws IOException { + super(rs, dotTerminatedLikeSMTP); uid = -1; } public final int uid; public boolean deleted = false; public boolean read = false; public boolean answered = false; public String dumpStoredForm() { throw new Error("StoredMessage.dumpStoredForm() not implemented"); }; + public static StoredMessage undump(InputStream os) { + Log.error(StoredMessage.class, "not implemented"); + return null; + } } public static class Address extends JSReflection { @@ -71,21 +88,37 @@ public class Message extends JSReflection { } public class Trace { - final String returnPath = null; - final Element[] elements; + String returnPath = null; + Element[] elements; public class Element { - final String fromDomain; - final String fromIP; - final String toDomain; - final String forWhom; - final Date date; + // FIXME final + String fromDomain; + String fromIP; + String toDomain; + String forWhom; + Date date; } } // FIXME: support dotTerminatedLikeSMTP - public Message(ReadStream rs, boolean dotTermiantedLikeSMTP) { + public Message(/*ReadStream rs*/BufferedReader rs, boolean dotTerminatedLikeSMTP) throws IOException { String key = null; StringBuffer all = new StringBuffer(); + String lastKey = null; + replyto = null; + subject = null; + messageid = null; + cc = null; + bcc = null; + resent = null; + traces = null; + envelopeFrom = null; + envelopeTo = null; + + headers = new Hashtable(); + date = null; // FIXME + to = null; + from = null; for(String s = rs.readLine(); s != null && !s.equals(""); s = rs.readLine()) { all.append(s); all.append("\r\n"); @@ -114,7 +147,7 @@ public class Message extends JSReflection { headers.put(key, val); } - pristeneHeaders = all.toString(); + allHeaders = all.toString(); StringBuffer body = new StringBuffer(); for(String s = rs.readLine(); s != null && !s.equals(""); s = rs.readLine()) body.append(s); this.body = body.toString(); diff --git a/src/org/ibex/mail/filter/Filter.java b/src/org/ibex/mail/filter/Filter.java index f134f7d..ed6aaa0 100644 --- a/src/org/ibex/mail/filter/Filter.java +++ b/src/org/ibex/mail/filter/Filter.java @@ -1,4 +1,6 @@ package org.ibex.mail.filter; +import org.ibex.mail.*; /** generic superclass for processing elements that recieve a message and "usually" pass it on */ public class Filter { + public Message process(Message m) { return null; } } diff --git a/src/org/ibex/mail/protocol/Incoming.java b/src/org/ibex/mail/protocol/Incoming.java index 42c5f9a..f02b657 100644 --- a/src/org/ibex/mail/protocol/Incoming.java +++ b/src/org/ibex/mail/protocol/Incoming.java @@ -1,12 +1,14 @@ package org.ibex.mail.protocol; +import org.ibex.mail.*; +import org.ibex.mail.store.*; +import org.ibex.mail.target.*; +import java.io.*; public class Incoming { protected void accept(Message m) throws IOException { - // currently, we write all inbound messages to the transcript - MessageStore.transcript.add(m); - - // FIXME: figure out where the message goes next + MessageStore.transcript.add((Message.StoredMessage)m); // currently, we write all inbound messages to the transcript + Target.root.accept(m); } } diff --git a/src/org/ibex/mail/protocol/MessageProtocol.java b/src/org/ibex/mail/protocol/MessageProtocol.java index 7542c7b..b5079ef 100644 --- a/src/org/ibex/mail/protocol/MessageProtocol.java +++ b/src/org/ibex/mail/protocol/MessageProtocol.java @@ -1,7 +1,7 @@ package org.ibex.mail.protocol; /** base class for over-the-wire protocols used to send, recieve, and serve messages */ -import com.caucho.server.connection.*; -import com.caucho.server.port.*; +//import com.caucho.server.connection.*; +//import com.caucho.server.port.*; -public class MessageProtocol extends com.caucho.server.port.Protocol { +public class MessageProtocol/* extends com.caucho.server.port.Protocol*/ { } diff --git a/src/org/ibex/mail/protocol/SMTP.java b/src/org/ibex/mail/protocol/SMTP.java index 82838a5..85d5390 100644 --- a/src/org/ibex/mail/protocol/SMTP.java +++ b/src/org/ibex/mail/protocol/SMTP.java @@ -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