add finally to dump connection log in IMAP
[org.ibex.mail.git] / src / org / ibex / mail / MIME.java
index 3635fd1..c8dce2a 100644 (file)
@@ -25,29 +25,38 @@ public class MIME {
         private final  String       encoding;
 
         private final Fountain     all;
+        private final Fountain     body;
+
         public Stream getStream() { return all.getStream(); }
         public int getNumLines()  { return all.getNumLines(); }
         public int getLength()    { return all.getLength(); }
+        public Fountain getBody()   { return body; }
 
-        public Stream getBody()   {
-            return /*
-                     "quoted-printable".equals(encoding) ? Encode.QuotedPrintable.decode(body.toString(),false) :
-                     "base64".equals(encoding)           ? Encode.fromBase64(body.toString()) :
-                   */
-                Headers.skip(getStream());
+        private class BodyFountain implements Fountain {
+            public int getNumLines()  { return Stream.countLines(getStream()); }
+            public int getLength()    { return Part.this.getLength() - headers.getLength() - 2; }
+            public Stream getStream() {
+                return /*
+                         "quoted-printable".equals(encoding) ? Encode.QuotedPrintable.decode(body.toString(),false) :
+                         "base64".equals(encoding)           ? Encode.fromBase64(body.toString()) :
+                       */
+                    Headers.Original.skip(all.getStream());
+            }
         }
 
         public Part(Fountain all) {
-            this.headers     = new Headers(all.getStream());
+            this.headers     = new Headers.Original(all.getStream());
             String ctype     = headers.get("content-type");
             this.encoding    = headers.get("content-transfer-encoding");
             if (!(encoding == null || encoding.equals("7bit") || encoding.equals("8bit") || encoding.equals("binary") ||
                   encoding.equals("quoted-printable") || encoding.equals("base64"))) {
+                // FIXME: "7BIT" is popular
                 Log.warn(MIME.class, "unknown TransferEncoding \"" + encoding + "\"");
                 ctype = "application/octet-stream";
             }
             this.contentType = new ContentType(ctype, headers.get("content-description"), headers.get("content-id"), encoding);
             this.all = all;
+            this.body = new BodyFountain();
         }
 
         /*