}
//Removes the dot stuffing
msgIn = new SMTPInputStream(msgIn);
//Parse out the message headers
MailHeaders headers = new MailHeaders(msgIn);
// if headers do not contains minimum REQUIRED headers fields,
// add them
if (!headers.isSet("Date")) {
headers.setHeader("Date",
RFC822DateFormat.toString(new Date()));
}
if (!headers.isSet("From") && state.get(SENDER) != null) {
headers.setHeader("From", state.get(SENDER).toString());
}
//Determine the Return-Path
String returnPath = headers.getHeader("Return-Path", "\r\n");
headers.removeHeader("Return-Path");
if (returnPath == null) {
if (state.get(SENDER) == null) {
returnPath = "<>";
} else {
returnPath = "<" + state.get(SENDER) + ">";
}
}
//We will rebuild the header object to put Return-Path and our
// Received message at the top
Enumeration headerLines = headers.getAllHeaderLines();
headers = new MailHeaders();
//Put the Return-Path first
headers.addHeaderLine("Return-Path: " + returnPath);
//Put our Received header next
headers.addHeaderLine("Received: from " + state.get(REMOTE_NAME)
+ " ([" + state.get(REMOTE_IP) + "])");
String temp = " by " + this.helloName + " ("
+ softwaretype + ") with SMTP ID " + state.get(SMTP_ID);
if (((Collection)state.get(RCPT_VECTOR)).size() == 1) {
//Only indicate a recipient if they're the only recipient
//(prevents email address harvesting and large headers in
// bulk email)
headers.addHeaderLine(temp);
headers.addHeaderLine(" for <"
+ ((Vector)state.get(RCPT_VECTOR)).get(0).toString()
+ ">;");
} else {
//Put the ; on the end of the 'by' line
headers.addHeaderLine(temp + ";");
}
headers.addHeaderLine(" "
+ RFC822DateFormat.toString(new Date()));
//Add all the original message headers back in next
while (headerLines.hasMoreElements()) {
headers.addHeaderLine((String)headerLines.nextElement());
}
ByteArrayInputStream headersIn
= new ByteArrayInputStream(headers.toByteArray());
MailImpl mail = new MailImpl(mailServer.getId(),
(MailAddress)state.get(SENDER),
(Vector)state.get(RCPT_VECTOR),
new SequenceInputStream(headersIn, msgIn));
// if the message size limit has been set, we'll