From ffe982612e6b20caf773d45e82b1c15f5dda54b9 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 7 May 2004 23:37:30 +0000 Subject: [PATCH] finished up Address parser darcs-hash:20040507233730-5007d-da6cbc94f086539375afde7dde8340b9b52b4d8c.gz --- src/org/ibex/mail/Message.java | 86 +++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/src/org/ibex/mail/Message.java b/src/org/ibex/mail/Message.java index 35840bf..c593a8a 100644 --- a/src/org/ibex/mail/Message.java +++ b/src/org/ibex/mail/Message.java @@ -32,12 +32,12 @@ public class Message extends JSReflection { public final Address[] cc; public final Address[] bcc; public final Hashtable[] resent; - public Trace[] traces; + public final Trace[] traces; public final Address envelopeFrom; public final Address[] envelopeTo; - public Date arrival = null; // when the message first arrived at this machine + public final Date arrival = null; // when the message first arrived at this machine public void dump(OutputStream os) throws IOException { Writer w = new OutputStreamWriter(os); @@ -94,23 +94,17 @@ public class Message extends JSReflection { } public static class Malformed extends MailException.Malformed { public Malformed(String s) { super(s); } } - public Message(LineReader rs) throws IOException, Malformed { + public Message(Address envelopeFrom, Address envelopeTo, LineReader rs) throws IOException, Malformed { + this.envelopeFrom = envelopeFrom; + this.envelopeTo = envelopeTo; + this.arrival = new Date(); + this.headers = new Hashtable(); String key = null; StringBuffer all = new StringBuffer(); - 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; + Date date = null; + Address to = null, from = null, replyto = null; + String subject = null, messageid = null; + Vec cc = new Vec(), bcc = new Vec(), resent = new Vec(), traces = new Vec(); for(String s = rs.readLine(); s != null && !s.equals(""); s = rs.readLine()) { all.append(s); all.append("\r\n"); @@ -124,29 +118,42 @@ public class Message extends JSReflection { for(int i=0; i 126) throw new Malformed("Header key contains invalid character \"" + s.charAt(i) + "\""); - String val = s.substring(0, s.indexOf(':') + 1); + String val = s.substring(0, s.indexOf(':')); while(Character.isSpace(val.charAt(0))) val = val.substring(1); - - if (headers.get(key) != null) - if (key.startsWith("Resent-")) { - // FIXME: multi-resent headers - - } else if (key.startsWith("Return-Path:")) { - rs.pushback(s); - Trace t = new Trace(rs); - Trace[] newTraces = new Trace[traces == null ? 1 : traces.length + 1]; - if (traces != null) System.arraycopy(traces, 0, newTraces, 0, traces.length); - traces = newTraces; - traces[traces.length-1] = t; - - } else { - // just append it to the previous one; valid for Comments/Keywords - val = headers.get(key) + " " + val; - } - - headers.put(key, val); + if (key.startsWith("Resent-")) { + if (key.startsWith("Resent-From")) resent.addElement(new Hashtable()); + ((Hashtable)resent.lastElement()).put(key.substring(7), val); + } else if (key.startsWith("Return-Path:")) { + rs.pushback(s); traces.addElement(new Trace(rs)); + } else { + // just append it to the previous one; valid for Comments/Keywords + if (headers.get(key) != null) val = headers.get(key) + " " + val; + headers.put(key, val); + } } + this.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")); + this.subject = (String)headers.get("Subject"); + this.messageid = (String)headers.get("Message-Id"); + if (headers.get("Cc") != null) { + StringTokenizer st = new StringTokenizer((String)headers.get("Cc")); + this.cc = new Address[st.countTokens()]; + for(int i=0; i