- public final Hashtable[] resent;
-
- public Message(Stream stream, Envelope envelope) throws Malformed {
- 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"));
+
+ public static Message newMessage(Fountain in) throws Malformed { return new Message(in); }
+
+ public Message reply(Fountain in, Address from, boolean includeReInSubject) throws Malformed {
+ /*
+ Address to = null;
+ if (to==null) to = Address.parse(headers.get("reply-to"));
+ if (to==null) to = Address.parse(headers.get("from"));
+ if (to==null) to = envelopeFrom;
+ Message ret = newMessage(in, from, to);
+ ret.headers.put("In-Reply-To", messageid);
+ String references = headers.get("references");
+ ret.headers.put("References", messageid + (references==null?"":(" "+references)));
+ if (includeReInSubject && subject!=null && !subject.toLowerCase().trim().startsWith("re:"))
+ headers.put("subject", "Re: "+subject);
+ return ret;
+ */
+ // FIXME
+ return null;
+ }
+
+ // FIXME
+ //public static Message newMessage(Headers headers, Fountain body, Address from, Address to) throws Malformed {
+ //}
+
+ public static Message newMessage(Fountain in, Address from, Address to) throws Malformed {
+ StringBuffer sb = new StringBuffer();
+ if (from != null) sb.append("Return-Path: " + from.toString(true) + "\r\n");
+ Stream stream = in.getStream();
+ while(true) {
+ String s = stream.readln();
+ if (s == null || s.length() == 0) {
+ if (to != null) sb.append("Envelope-To: " + to.toString(true) + "\r\n");
+ sb.append("\r\n");
+ break;
+ }
+ if (to != null && s.toLowerCase().startsWith("envelope-to:")) continue;
+ if (s.toLowerCase().startsWith("return-path:")) continue;
+ sb.append(s);
+ sb.append("\r\n");
+ }
+ for(String s = stream.readln(); s != null; s = stream.readln()) {
+ sb.append(s);
+ sb.append("\r\n");
+ }
+ return new Message(new Fountain.StringFountain(sb.toString()));
+ }
+
+ private Message(Fountain in) throws Malformed {
+ super(in);
+ this.envelopeTo = headers.get("Envelope-To") != null ? Address.parse(headers.get("Envelope-To")) : null;
+ this.envelopeFrom = headers.get("Return-Path") != null ? Address.parse(headers.get("Return-Path")) : null;
+ this.to = headers.get("To") != null ? Address.parse(headers.get("To")) : this.envelopeTo;
+ this.from = headers.get("From") != null ? Address.parse(headers.get("From")) : this.envelopeFrom;
+ this.replyto = headers.get("Reply-To") == null ? null : Address.parse(headers.get("Reply-To"));