fixed get/gets mixup
authoradam <adam@megacz.com>
Wed, 21 Jul 2004 10:25:04 +0000 (10:25 +0000)
committeradam <adam@megacz.com>
Wed, 21 Jul 2004 10:25:04 +0000 (10:25 +0000)
darcs-hash:20040721102504-5007d-d1e87f8889bafaf0ce4aea069f547e59b99917d2.gz

src/org/ibex/mail/Address.java
src/org/ibex/mail/MIME.java
src/org/ibex/mail/Message.java
src/org/ibex/mail/protocol/IMAP.java

index 041c598..4b3732a 100644 (file)
@@ -12,7 +12,7 @@ public class Address extends JSReflection {
     public final String user;
     public final String host;
     public final String description;
-    public static Address parse(String s) { try { return new Address(s); } catch (Malformed _) { return null; } }
+    public static Address parse(String s) { try { return s==null?null:new Address(s); } catch (Malformed _) { return null; } }
     public Address(String user, String host, String description) {this.user=user;this.host=host;this.description=description;}
     public Address(String s0) throws Address.Malformed {
         String s = s0.trim();
index ba85ca5..42b36cf 100644 (file)
@@ -134,15 +134,15 @@ public class MIME {
        
         public Part(Stream stream, String boundary, boolean assumeMime) throws MailException.Malformed {
             this.headers     = new Headers(stream, assumeMime);
-            this.mime        = assumeMime | (headers.get("mime-version")!=null&&headers.get("mime-version").trim().equals("1.0"));
-            String ctype     = headers.get("content-type");
-            String encoding  = headers.get("content-transfer-encoding");
+            this.mime        = assumeMime | (headers.gets("mime-version")!=null&&headers.gets("mime-version").trim().equals("1.0"));
+            String ctype     = headers.gets("content-type");
+            String encoding  = headers.gets("content-transfer-encoding");
             if (!(encoding == null || encoding.equals("7bit") || encoding.equals("8bit") || encoding.equals("binary") ||
                   encoding.equals("quoted-printable") || encoding.equals("base64"))) {
                 Log.warn(MIME.class, "unknown TransferEncoding \"" + encoding + "\"");
                 ctype = "application/octet-stream";
             }
-            content = new Content(ctype, headers.get("content-description"), headers.get("content-id"), encoding);
+            content = new Content(ctype, headers.gets("content-description"), headers.gets("content-id"), encoding);
             //if (content.composite) { subparts = parseParts(stream); body = null; last = false; lines = 0; return; }
             subparts = null;
             boolean last = false;
@@ -170,7 +170,8 @@ public class MIME {
        private Hashtable head = new Hashtable();
         public final int lines;
         public final String raw;
-        public String get(String s) { return (String)head.get(s.toLowerCase()); }
+        public Object get(Object s) { return head.get(((String)s).toLowerCase()); }
+        public String gets(String s) { return (String)get(s); }
         public static String uncomment(String val) {
             boolean inquotes = false;
             for(int i=0; i<val.length(); i++) {
@@ -206,7 +207,7 @@ public class MIME {
             this.lines = lines;
 
             Enumeration e = head.keys();
-            boolean mime = assumeMime | (get("mime-version") != null && get("mime-version").trim().equals("1.0"));
+            boolean mime = assumeMime | (gets("mime-version") != null && gets("mime-version").trim().equals("1.0"));
             while(e.hasMoreElements()) {
                 String k = (String)e.nextElement();
                 String v = (String)head.get(k);
index 1243c56..79744c8 100644 (file)
@@ -38,8 +38,8 @@ public class Message extends MIME.Part {
         public final Address from;
         public static Envelope augment(Envelope e, MIME.Headers h) {
             if (e.from != null && e.to != null) return e;
-            Address to   = e.to   == null ? Address.parse(h.get("X-org.ibex.mail.headers.envelope.To"))   : e.to;
-            Address from = e.from == null ? Address.parse(h.get("X-org.ibex.mail.headers.envelope.From")) : e.from;
+            Address to   = e.to   == null ? Address.parse(h.gets("X-org.ibex.mail.headers.envelope.To"))   : e.to;
+            Address from = e.from == null ? Address.parse(h.gets("X-org.ibex.mail.headers.envelope.From")) : e.from;
             return new Envelope(from, to, e.arrival);
         }
     }
@@ -61,14 +61,14 @@ public class Message extends MIME.Part {
         super(stream, null, false);
         Vec resent = new Vec(), traces = new Vec();
         this.envelope     = Envelope.augment(envelope, headers);
-        this.to           = headers.get("To") == null       ? envelope.to    : Address.parse(headers.get("To"));
-        this.from         = headers.get("From") == null     ? envelope.from  : Address.parse(headers.get("From"));
-        this.replyto      = headers.get("Reply-To") == null ? null           : Address.parse(headers.get("Reply-To"));
-        this.subject      = headers.get("Subject");
-        this.messageid    = headers.get("Message-Id");
-        this.cc           = Address.list(headers.get("Cc"));
-        this.bcc          = Address.list(headers.get("BCc"));
-        this.date         = parseDate(headers.get("Date"));
+        this.to           = headers.gets("To") == null       ? envelope.to    : Address.parse(headers.gets("To"));
+        this.from         = headers.gets("From") == null     ? envelope.from  : Address.parse(headers.gets("From"));
+        this.replyto      = headers.gets("Reply-To") == null ? null           : Address.parse(headers.gets("Reply-To"));
+        this.subject      = headers.gets("Subject");
+        this.messageid    = headers.gets("Message-Id");
+        this.cc           = Address.list(headers.gets("Cc"));
+        this.bcc          = Address.list(headers.gets("BCc"));
+        this.date         = parseDate(headers.gets("Date"));
         resent.copyInto(this.resent = new Hashtable[resent.size()]);
         traces.copyInto(this.traces = new Trace[traces.size()]);
     }
index e143420..36a5371 100644 (file)
@@ -441,7 +441,7 @@ public class IMAP {
             if (!negate) {
                 if(e) for(int j=0; j<headers.length; j++) {
                     r.append(headers[j] + (j<headers.length-1?" ":""));
-                    if (m.headers.get(headers[j]) != null) payload += headers[j]+": "+m.headers.get(headers[j])+"\r\n";
+                    if (m.headers.gets(headers[j]) != null) payload += headers[j]+": "+m.headers.gets(headers[j])+"\r\n";
                 }
             } else {
                throw new Server.No("HEADERS.NOT temporarily disaled");
@@ -450,7 +450,7 @@ public class IMAP {
                 if(e) { OUTER: for(Enumeration x=m.headers.keys(); x.hasMoreElements();) {
                     String key = (String)x.nextElement();
                     for(int j=0; j<headers.length; j++) if (key.equalsIgnoreCase(headers[j])) continue OUTER;
-                    payload += key + ": " + m.headers.get(key)+"\r\n";
+                    payload += key + ": " + m.headers.gets(key)+"\r\n";
                 } }
                */
             }
@@ -747,12 +747,12 @@ public class IMAP {
                 "(" + quotify(m.envelope.arrival.toString()) +
                 " " + quotify(m.subject) +          
                 " " + addressList(m.from) +      
-                " " + addressList(m.headers.get("sender")) +
+                " " + addressList(m.headers.gets("sender")) +
                 " " + addressList(m.replyto) + 
                 " " + addressList(m.to) + 
                 " " + addressList(m.cc) + 
                 " " + addressList(m.bcc) + 
-                " " + quotify((String)m.headers.get("in-reply-to")) +
+                " " + quotify((String)m.headers.gets("in-reply-to")) +
                 " " + quotify(m.messageid) +
                 ")";
         }