- 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.gets("To") == null ? envelope.to : Address.parse(headers.gets("To"));
- this.from = headers.gets("From") == null ? envelope.from : Address.parse(headers.gets("From"));
- this.replyto = headers.gets("Reply-To") == null ? null : Address.parse(headers.gets("Reply-To"));
- this.subject = headers.gets("Subject");
- this.messageid = headers.gets("Message-Id");
- this.cc = Address.list(headers.gets("Cc"));
- this.bcc = Address.list(headers.gets("BCc"));
- this.date = parseDate(headers.gets("Date"));
- resent.copyInto(this.resent = new Hashtable[resent.size()]);
- traces.copyInto(this.traces = new Trace[traces.size()]);
+
+ public static Message newMessage(Fountain in) throws Malformed { return new Message(in, null); }
+ public static Message newMessageFromHeadersAndBody(Headers head, Fountain body, Address from, Address to) throws Malformed {
+ return new Message(Fountain.Util.concat(head, Fountain.Util.create("\r\n"), body),
+ new String[] {
+ "Return-Path", from==null ? "<>" : from.toString(true),
+ "Envelope-To", to.toString(true)
+ });
+ }
+ /*
+ public static Message newMessageWithEnvelope(Fountain in, Address from, Address to) throws Malformed {
+ return new Message(in,
+ new String[] {
+ "Return-Path", from==null ? "<>" : from.toString(true),
+ "Envelope-To", to.toString(true)
+ });
+ }
+ */
+ public Message withEnvelope(Address from, Address to) {
+ return new Message(this,
+ new String[] {
+ "Return-Path", from==null ? "<>" : from.toString(true),
+ "Envelope-To", to.toString(true)
+ });
+ }
+ private Message(Fountain in, String[] keyval) throws Malformed {
+ super(in, keyval);
+
+ 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"));
+ this.subject = headers.get("Subject");
+ String messageid = headers.get("Message-Id");
+ this.cc = Address.list(headers.get("Cc"));
+ this.bcc = Address.list(headers.get("Bcc"));
+ Date date = RobustDateParser.parseDate(headers.get("Date"));
+ this.date = date==null ? new Date() : date;
+ this.arrival = this.date; // FIXME wrong: should grab this from traces, I think?
+
+ if (messageid == null) {
+ SHA1 sha1 = new SHA1();
+ Stream s = this.getStream();
+ s.setInputDigest(sha1);
+ s.transcribe(new Stream(new NullOutputStream()));
+ byte[] end = new byte[sha1.getDigestSize()];
+ sha1.doFinal(end, 0);
+ messageid = "<synthetic.messageid." + Encode.toBase64String(end) + ">";
+ Log.info(this, "synthesized messageid " + messageid);
+ }
+ this.messageid = messageid;