for (;it.hasNext();) {
sosMailAttachment = (SOSMailAttachment)it.next();
// check if the attachment = message
if (sosMailAttachment.getContentType().equalsIgnoreCase(
"message/rfc822")) {
SOSMimeMessage originalMessage = sosMimeMessage
.getAttachedSosMimeMessage(receiver.getSession(),
sosMailAttachment.getContent());
this
.setXSOSMailDeliveryCounterHeader(getXSOSMailDeliveryCounterHeader(originalMessage));
this.getLogger().info("....originally message attributes:");
this.getLogger().info(
"....message id [" + originalMessage.getMessageId()
+ "]");
this.getLogger().info(
"....from [" + originalMessage.getFromAddress() + "]");
this
.getLogger()
.info(
"....sent date ["
+ originalMessage
.getSentDateAsString("yyyy-MM-dd HH:mm:ss")
+ "]");
// .. get the mails.id of the originalMessage.getMessageId if exists
setMailId(getMailId(originalMessage.getMessageId()));
if(SOSString.isEmpty(getMailId())) // .. skip if no entry available
continue;
// .. then update the "MAILS" table
this.updateTableMails(originalMessage.getMessageId());
if (!SOSString.isEmpty(getXSOSMailDeliveryCounterHeader())) {
this
.getLogger()
.info(
"...current "
+ JobSchedulerMailBounceHandler.X_SOSMAIL_DELIVERY_COUNTER_HEADER
+ " ["
+ this
.getXSOSMailDeliveryCounterHeader()
+ "]");
}//if
bouncedMailAction = this
.getPatternAction(sosMimeMessage);
this.getLogger().info(
"..available pattern action for this bounce ["
+ bouncedMailAction + "]");
// handle action...
if (bouncedMailAction.equalsIgnoreCase("drop")) { // delete
// bounced
// message
this.getLogger().info(
"..Message with ID ["
+ sosMimeMessage.getMessageId()
+ "] is marked for delete.");
sosMimeMessage.deleteMessage();
bouncedMailStatus = BounceMailStatus.CANCELLED;
} else if (bouncedMailAction.equalsIgnoreCase("store")) {
String fileName = getLogDirectory() + File.separator
+ sosMimeMessage.getMessageId();
sosMimeMessage.dumpMessageToFile(fileName, true,false);
bouncedMailStatus = BounceMailStatus.REQUESTED;
} else if (bouncedMailAction.equalsIgnoreCase("retry")) {
// check if retry sending allowed
if (isRetrySendingAllowed(originalMessage.getMessageId())) {
setRetryInterval(getRetryInterval(originalMessage));
// incr. the X-Header if exists otherwise add a new one
int currentHeaderValue;
if ( (currentHeaderValue=originalMessage.incrementHeader(JobSchedulerMailBounceHandler.X_SOSMAIL_DELIVERY_COUNTER_HEADER)) == -1) {
currentHeaderValue = 1;
originalMessage.setHeader(JobSchedulerMailBounceHandler.X_SOSMAIL_DELIVERY_COUNTER_HEADER,"1");
getLogger().debug5(".. [" + JobSchedulerMailBounceHandler.X_SOSMAIL_DELIVERY_COUNTER_HEADER + "] set.");
}
getLogger().debug5("..current value of \"" + JobSchedulerMailBounceHandler.X_SOSMAIL_DELIVERY_COUNTER_HEADER + "\" [" +currentHeaderValue + "]");
getLogger().debug5("..query directory [" + bounceDirectory + " ] set.");
originalMessage.setQueueDir(bounceDirectory);
originalMessage.dumpMessageToFile(true,false);
this.getLogger().debug5("..currently dumped message [" +originalMessage.getDumpedFileName() + "]" );
if (!orderRetrySend(originalMessage))
continue;
}
bouncedMailStatus = BounceMailStatus.DELIVERED;