X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FMessage.java;h=b1c8e0a7877ed1b18d50a388a03ab8457de1ae2c;hb=4b76a31e8f86bc8de673899bbb45252c01e9a0f6;hp=cb430396946b654ecff4602762e10716bc704681;hpb=842351b4a6b67ebe088bf56347b919e24f447391;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/Message.java b/src/org/ibex/mail/Message.java index cb43039..b1c8e0a 100644 --- a/src/org/ibex/mail/Message.java +++ b/src/org/ibex/mail/Message.java @@ -71,15 +71,24 @@ public class Message extends MIME.Part { 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 = ""; + Log.info(this, "synthesized messageid " + messageid); + } + this.messageid = messageid; } @@ -167,5 +176,19 @@ public class Message extends MIME.Part { 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())); + } }