- public static class Malformed extends MailException.Malformed { public Malformed(String s) { super(s); } }
- public Message(Address envelopeFrom, Address[] envelopeTo, LineReader rs) throws IOException, MailException.Malformed {
- this.envelopeFrom = envelopeFrom;
- this.envelopeTo = envelopeTo;
- this.arrival = new Date();
- this.headers = new Hashtable();
- String key = null;
- StringBuffer all = new StringBuffer();
- Date date = null;
- Address to = null, from = null, replyto = null;
- String subject = null, messageid = null;
- Vec cc = new Vec(), bcc = new Vec(), resent = new Vec(), traces = new Vec();
- for(String s = rs.readLine(); s != null && !s.equals(""); s = rs.readLine()) {
- all.append(s);
- all.append("\r\n");
- if (s.length() == 0 || Character.isSpace(s.charAt(0))) {
- if (key == null) throw new Malformed("Message began with a blank line; no headers");
- headers.put(key, headers.get(key) + s);
- continue;
- }
- if (s.indexOf(':') == -1) throw new Malformed("Header line does not contain colon: " + s);
- key = s.substring(0, s.indexOf(':'));
- for(int i=0; i<s.length(); i++)
- if (s.charAt(i) < 33 || s.charAt(i) > 126)
- throw new Malformed("Header key contains invalid character \"" + s.charAt(i) + "\"");
- String val = s.substring(0, s.indexOf(':'));
- while(Character.isSpace(val.charAt(0))) val = val.substring(1);
- if (key.startsWith("Resent-")) {
- if (key.startsWith("Resent-From")) resent.addElement(new Hashtable());
- ((Hashtable)resent.lastElement()).put(key.substring(7), val);
- } else if (key.startsWith("Return-Path:")) {
- rs.pushback(s); traces.addElement(new Trace(rs));
- } else {
- // just append it to the previous one; valid for Comments/Keywords
- if (headers.get(key) != null) val = headers.get(key) + " " + val;
- headers.put(key, val);
- }
- }