*/
public void service(Mail originalMail) throws MessagingException {
// duplicates the Mail object, to be able to modify the new mail keeping the original untouched
Mail newMail = ((MailImpl) originalMail).duplicate(newName((MailImpl) originalMail));
// We don't need to use the original Remote Address and Host,
// and doing so would likely cause a loop with spam detecting
// matchers.
try {
((MailImpl)newMail).setRemoteAddr(java.net.InetAddress.getLocalHost().getHostAddress());
((MailImpl)newMail).setRemoteHost(java.net.InetAddress.getLocalHost().getHostName());
} catch (java.net.UnknownHostException _) {
((MailImpl) newMail).setRemoteAddr("127.0.0.1");
((MailImpl) newMail).setRemoteHost("localhost");
}
MailAddress returnAddress = getExistingReturnPath(originalMail);
Collection newRecipients = new HashSet();
if (returnAddress == SpecialAddress.NULL) {
if (isDebug)
log("Processing a bounce request for a message with an empty reverse-path. No bounce will be sent.");
if(!getPassThrough(originalMail)) {
originalMail.setState(Mail.GHOST);
}
return;
} else if (returnAddress == null) {
log("WARNING: Mail to be bounced does not contain a reverse-path.");
} else {
if (isDebug)
log("Processing a bounce request for a message with a return path header. The bounce will be sent to " + returnAddress);
}
newRecipients.add(returnAddress);
((MailImpl)newMail).setRecipients(newRecipients);
if (isDebug) {
MailImpl newMailImpl = (MailImpl) newMail;
log("New mail - sender: " + newMailImpl.getSender()
+ ", recipients: " +
arrayToString(newMailImpl.getRecipients().toArray())
+ ", name: " + newMailImpl.getName()
+ ", remoteHost: " + newMailImpl.getRemoteHost()
+ ", remoteAddr: " + newMailImpl.getRemoteAddr()
+ ", state: " + newMailImpl.getState()
+ ", lastUpdated: " + newMailImpl.getLastUpdated()
+ ", errorMessage: " + newMailImpl.getErrorMessage());
}
// create the bounce message
MimeMessage newMessage =
new MimeMessage(Session.getDefaultInstance(System.getProperties(),
null));
MimeMultipartReport multipart = new MimeMultipartReport ();
multipart.setReportType ("delivery-status");
// part 1: descripive text message
MimeBodyPart part1 = createTextMsg(originalMail);
multipart.addBodyPart(part1);
// part 2: DSN
MimeBodyPart part2 = createDSN(originalMail);
multipart.addBodyPart(part2);
// part 3: original mail (optional)
if (getAttachmentType() != NONE) {
MimeBodyPart part3 = createAttachedOriginal(originalMail);
multipart.addBodyPart(part3);
}
// stuffing all together
newMessage.setContent(multipart);
newMessage.setHeader(RFC2822Headers.CONTENT_TYPE, multipart.getContentType());
newMail.setMessage(newMessage);
//Set additional headers
setRecipients(newMail, getRecipients(originalMail), originalMail);
setTo(newMail, getTo(originalMail), originalMail);
setSubjectPrefix(newMail, getSubjectPrefix(originalMail), originalMail);
if(newMail.getMessage().getHeader(RFC2822Headers.DATE) == null) {
newMail.getMessage().setHeader(RFC2822Headers.DATE,rfc822DateFormat.format(new Date()));
}
setReplyTo(newMail, getReplyTo(originalMail), originalMail);
setReversePath(newMail, getReversePath(originalMail), originalMail);
setSender(newMail, getSender(originalMail), originalMail);
setIsReply(newMail, isReply(originalMail), originalMail);
newMail.getMessage().saveChanges();
getMailetContext().sendMail(newMail);
// ghosting the original mail
if(!getPassThrough(originalMail)) {
originalMail.setState(Mail.GHOST);