// should be removed when making final delivery.
// headers.removeHeader(RFC2822Headers.RETURN_PATH);
StringBuffer headerLineBuffer = new StringBuffer(512);
// We will rebuild the header object to put our Received header at the top
Enumeration headerLines = headers.getAllHeaderLines();
MailHeaders newHeaders = new MailHeaders();
// Put our Received header first
headerLineBuffer.append(RFC2822Headers.RECEIVED + ": from ")
.append(session.getRemoteHost())
.append(" ([")
.append(session.getRemoteIPAddress())
.append("])");
newHeaders.addHeaderLine(headerLineBuffer.toString());
headerLineBuffer.delete(0, headerLineBuffer.length());
headerLineBuffer.append(" by ")
.append(session.getConfigurationData().getHelloName())
.append(" (")
.append(SOFTWARE_TYPE)
.append(") with SMTP ID ")
.append(session.getSessionID());
if (((Collection) session.getState().get(SMTPSession.RCPT_LIST)).size() == 1) {
// Only indicate a recipient if they're the only recipient
// (prevents email address harvesting and large headers in
// bulk email)
newHeaders.addHeaderLine(headerLineBuffer.toString());
headerLineBuffer.delete(0, headerLineBuffer.length());
headerLineBuffer.append(" for <")
.append(((List) session.getState().get(SMTPSession.RCPT_LIST)).get(0).toString())
.append(">;");
newHeaders.addHeaderLine(headerLineBuffer.toString());
headerLineBuffer.delete(0, headerLineBuffer.length());
} else {
// Put the ; on the end of the 'by' line
headerLineBuffer.append(";");
newHeaders.addHeaderLine(headerLineBuffer.toString());
headerLineBuffer.delete(0, headerLineBuffer.length());
}
headerLineBuffer = null;
newHeaders.addHeaderLine(" " + rfc822DateFormat.format(new Date()));
// Add all the original message headers back in next
while (headerLines.hasMoreElements()) {
newHeaders.addHeaderLine((String) headerLines.nextElement());
}
return newHeaders;
}