corrected line counting
[org.ibex.mail.git] / src / org / ibex / mail / MIME.java
index 112feb3..ba85ca5 100644 (file)
@@ -115,6 +115,7 @@ public class MIME {
         public final Headers   headers;
         public final Part[]    subparts;
         public final String    body;
+        public final int       lines;
         private final boolean  last;
 
         private Part[] parseParts(Stream stream) {
@@ -125,6 +126,7 @@ public class MIME {
             while(true) {
                 Part p = new Part(stream, (String)content.parameters.get("boundary"), true);
                 v.addElement(p);
+                //lines += p.lines;
                 if (p.last) break;
             }
             return (Part[])v.copyInto(new Part[v.size()]);
@@ -141,9 +143,10 @@ public class MIME {
                 ctype = "application/octet-stream";
             }
             content = new Content(ctype, headers.get("content-description"), headers.get("content-id"), encoding);
-            //if (content.composite) { subparts = parseParts(stream); body = null; last = false; return; }
+            //if (content.composite) { subparts = parseParts(stream); body = null; last = false; lines = 0; return; }
             subparts = null;
             boolean last = false;
+            int lines = 0;
             StringBuffer body = new StringBuffer();
             for(String s = stream.readln(); s != null; s = stream.readln()) {
                 if (boundary != null && (s.equals(boundary) || s.equals(boundary + "--"))) {
@@ -152,16 +155,20 @@ public class MIME {
                     break;
                 }
                 body.append(s);
+                body.append("\r\n");
+                lines++;
             }
             if ("quoted-printable".equals(encoding)) this.body = MIME.QuotedPrintable.decode(body.toString(),false);
             else if ("base64".equals(encoding)) this.body = new String(Base64.decode(body.toString()));
             else this.body = body.toString();
             this.last = last;
+            this.lines = lines + headers.lines;
         }
     }
 
     public static class Headers extends org.ibex.js.JSReflection {
        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 static String uncomment(String val) {
@@ -176,9 +183,11 @@ public class MIME {
         public Headers(Stream stream, boolean assumeMime) throws MailException.Malformed {
             StringBuffer all = new StringBuffer();
             String key = null;
+            int lines = 0;
             for(String s = stream.readln(); s != null && !s.equals(""); s = stream.readln()) {
                 all.append(s);
                 all.append("\r\n");
+                lines++;
                 if (Character.isSpace(s.charAt(0))) {
                     if (key == null) throw new MailException.Malformed("Message began with a blank line; no headers");
                     head.put(key, head.get(key) + " " + s.trim());
@@ -194,6 +203,7 @@ public class MIME {
                 head.put(key, val);
             }
             this.raw = all.toString();
+            this.lines = lines;
 
             Enumeration e = head.keys();
             boolean mime = assumeMime | (get("mime-version") != null && get("mime-version").trim().equals("1.0"));