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");
- this.messageid = headers.get("Message-Id");
+ 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 (this.messageid == null)
- throw new RuntimeException("every RFC2822 message must have a Message-ID: header");
+ 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;
}
public final String summary() { return "[" + envelopeFrom + " -> " + envelopeTo + "] " + subject; }
public static class Malformed extends MailException { public Malformed(String s) { super(s); } }
+
+ /** reads an SMTP-style dot-escaped message */
+ static Message readDotEncodedMessage(Stream conn) {
+ StringBuffer buf = new StringBuffer();
+ while(true) {
+ String s = conn.readln();
+ if (s == null) throw new RuntimeException("connection closed");
+ if (s.equals(".")) break;
+ if (s.startsWith(".")) s = s.substring(1);
+ buf.append(s);
+ buf.append("\r\n");
+ }
+ return Message.newMessage(new Fountain.StringFountain(buf.toString()));
+ }
}