From: adam Date: Tue, 20 Jul 2004 10:07:16 +0000 (+0000) Subject: corrected line counting X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=f45de886d35e8fc1def15d5b5d1589025866d450;p=org.ibex.mail.git corrected line counting darcs-hash:20040720100716-5007d-7b465bf7c08890ad245a6c08b30f5ba095ba7748.gz --- diff --git a/src/org/ibex/mail/MIME.java b/src/org/ibex/mail/MIME.java index 112feb3..ba85ca5 100644 --- a/src/org/ibex/mail/MIME.java +++ b/src/org/ibex/mail/MIME.java @@ -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")); diff --git a/src/org/ibex/mail/Message.java b/src/org/ibex/mail/Message.java index c9fc2ae..1243c56 100644 --- a/src/org/ibex/mail/Message.java +++ b/src/org/ibex/mail/Message.java @@ -56,8 +56,6 @@ public class Message extends MIME.Part { public final Address[] cc; public final Address[] bcc; public final Hashtable[] resent; - public final int lines; // lines in the body FIXME not accurate anymore - public Message(Stream stream, Envelope envelope) throws Malformed { super(stream, null, false); @@ -71,7 +69,6 @@ public class Message extends MIME.Part { this.cc = Address.list(headers.get("Cc")); this.bcc = Address.list(headers.get("BCc")); this.date = parseDate(headers.get("Date")); - this.lines = 0; /* FIMXE */ resent.copyInto(this.resent = new Hashtable[resent.size()]); traces.copyInto(this.traces = new Trace[traces.size()]); }