X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FMIME.java;h=477ce639049228da8e82b67d0993918946a755c8;hb=43b53fd9e204f99ff18101c029e8c3a3a7cf5763;hp=36d125b778018998b3915a16cd6a3bb0451ac6af;hpb=31f6bfd3b57924e8c3d506592132e91e73145462;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/MIME.java b/src/org/ibex/mail/MIME.java index 36d125b..477ce63 100644 --- a/src/org/ibex/mail/MIME.java +++ b/src/org/ibex/mail/MIME.java @@ -33,20 +33,19 @@ public class MIME { public long getLength() { return all.getLength(); } public Fountain getBody() { return body; } - private class BodyFountain implements Fountain { - public int getNumLines() { return Stream.countLines(getStream()); } - public long getLength() { return Part.this.getLength() - headers.getLength() - 2 /*FIXME: correct?*/; } - 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 JS get(JS key) throws JSExn { + String k = JSU.toString(key); + if ("body".equals(k)) { + StringBuffer sb = new StringBuffer(); + getBody().getStream().transcribe(sb); + return JSU.S(sb.toString()); } + return super.get(key); } - public Part(Fountain all) { - this.headers = new Headers(all); + public Part(final Fountain fount, String[] keyval) { + Headers h = new Headers(fount); + this.headers = keyval==null ? h : new Headers(h, keyval); String ctype = headers.get("content-type"); this.encoding = headers.get("content-transfer-encoding"); String enc = this.encoding; @@ -57,8 +56,22 @@ public class MIME { 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(); + // FIXME: this is a horrible, tangled mess. + this.body = new Fountain() { + public int getNumLines() { return Stream.countLines(this.getStream()); } + public long getLength() { return Stream.countBytes(this.getStream()); } + public Stream getStream() { return transformBodyStream(Headers.skip(fount.getStream())); } + }; + this.all = + keyval==null + ? fount + : Fountain.Util.concat(this.headers, Fountain.Util.create("\r\n"), this.body); + } + + private Stream transformBodyStream(Stream body) { + //"quoted-printable".equals(encoding) ? Encode.QuotedPrintable.decode(body.toString(),false) : + //"base64".equals(encoding) ? Encode.fromBase64(body.toString()) : + return body; } /* @@ -78,6 +91,7 @@ public class MIME { } */ } + /* public static class Boundary implements Stream.Transformer { private final String boundary;