make CaseInsensitiveHash manipulatable by JS
authoradam <adam@megacz.com>
Thu, 24 Jun 2004 01:28:58 +0000 (01:28 +0000)
committeradam <adam@megacz.com>
Thu, 24 Jun 2004 01:28:58 +0000 (01:28 +0000)
darcs-hash:20040624012858-5007d-9fe858264cdbf9ef7319d3a3b319515c29347909.gz

src/org/ibex/mail/Message.java

index c094912..3d9c548 100644 (file)
@@ -29,7 +29,7 @@ import java.io.*;
 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 CaseInsensitiveHash headers; // hash of headers (not including resent's and traces)
     public final String body;                 // entire body
     public final int lines;                   // lines in the body
 
@@ -155,6 +155,7 @@ public class Message extends JSReflection {
             this.subject   = (String)headers.get("Subject");
             this.messageid = (String)headers.get("Message-Id");
             if (headers.get("Cc") != null) {
+                // FIXME: tokenize better
                 StringTokenizer st = new StringTokenizer((String)headers.get("Cc"));
                 this.cc = new Address[st.countTokens()];
                 for(int i=0; i<this.cc.length; i++) this.cc[i] = new Address(st.nextToken());
@@ -172,8 +173,12 @@ public class Message extends JSReflection {
             traces.copyInto(this.traces = new Trace[traces.size()]);
             allHeaders = all.toString();
             StringBuffer body = new StringBuffer();
-            int lines = 0;
-            for(String s = rs.readLine();; s = rs.readLine()) { if (s == null) break; lines++; body.append(s + "\r\n"); }
+            for(String s = rs.readLine();; s = rs.readLine()) {
+               if (s == null) break;
+               lines++;
+               body.append(s);       // FIXME: we're assuming all mail messages fit in memory
+               body.append("\r\n");
+           }
             this.lines = lines;
             this.body = body.toString();
         } catch (IOException e) { throw new MailException.IOException(e); }
@@ -206,11 +211,11 @@ public class Message extends JSReflection {
 
     //  use null-sender for error messages (don't send errors to the null addr)
     public Message bounce(String reason) { throw new RuntimeException("bounce not implemented"); }  // FIXME!
-
-    private static class CaseInsensitiveHash extends Hashtable {
-        public Object get(Object o) { return (o instanceof String) ? super.get(((String)o).toLowerCase()) : super.get(o); }
-        public Object put(Object k, Object v) { throw new Error("you cannot write to a CaseInsensitiveHash"); }
-        void add(Object k, Object v) { if (k instanceof String) super.put(((String)k).toLowerCase(), v); else super.put(k, v); }
+    public static class CaseInsensitiveHash extends org.ibex.js.JSReflection {
+       private Hashtable stuff = new Hashtable();
+        public Object get(Object o) { return stuff.get(((String)o).toLowerCase()); }
+        void add(Object k, Object v) { if (k instanceof String) stuff.put(((String)k).toLowerCase(), v); else stuff.put(k, v); }
     }
 
 }