use of org.nhindirect.common.mail.dsn.DSNRecipientHeaders in project nhin-d by DirectProject.
the class DSNMessageGenerator method generateDSNFailureMessage.
/**
* Generates the DSN message a replacing the existing exchange in body with the DSN message as a MimeMessage object.
* @param txs Collection of correlated Tx objects.
* @param ex The message exchange.
* @throws Exception
*/
@Handler
public void generateDSNFailureMessage(Collection<Tx> txs, Exchange ex) throws Exception {
// change the inbound message body to null
ex.getIn().setBody(null);
// get the message that is being tracked so we can generate an error message for it
Tx messageToTrack = AbstractCompletionCondition.getMessageToTrack(txs);
if (messageToTrack != null) {
// make sure we have incomplete recipients
final Collection<String> incompleteRecips = conditionChecker.getIncompleteRecipients(txs);
if (incompleteRecips != null && !incompleteRecips.isEmpty()) {
InternetAddress originalSender = null;
String originalSubject = "";
InternetAddress postmaster = null;
String originalMessageId = "";
Enumeration<Header> fullMessageHeaders = null;
final List<DSNRecipientHeaders> recipientDSNHeaders = new ArrayList<DSNRecipientHeaders>();
final List<Address> failedRecipAddresses = new ArrayList<Address>();
final TxDetail sender = messageToTrack.getDetail(TxDetailType.FROM);
if (sender != null) {
originalSender = new InternetAddress(sender.getDetailValue());
postmaster = new InternetAddress(postmasterMailbox + "@" + getAddressDomain(originalSender));
}
final TxDetail subject = messageToTrack.getDetail(TxDetailType.SUBJECT);
if (subject != null)
originalSubject = subject.getDetailValue();
for (String incompleteRecip : incompleteRecips) {
final Address failedRecipAddress = new InternetAddress(incompleteRecip);
DSNRecipientHeaders dsnRecipHeaders = new DSNRecipientHeaders(DSNAction.FAILED, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.UNDEFINED_STATUS), failedRecipAddress);
recipientDSNHeaders.add(dsnRecipHeaders);
failedRecipAddresses.add(failedRecipAddress);
}
///CLOVER:OFF
final TxDetail origMessId = messageToTrack.getDetail(TxDetailType.MSG_ID);
if (origMessId != null)
originalMessageId = origMessId.getDetailValue();
///CLOVER:ON
final DSNMessageHeaders messageDSNHeaders = new DSNMessageHeaders(reportingMta, originalMessageId, MtaNameType.DNS);
final TxDetail fullHeaders = messageToTrack.getDetail(TxDetailType.MSG_FULL_HEADERS);
if (fullHeaders != null)
fullMessageHeaders = this.convertStringToHeaders(fullHeaders.getDetailValue());
final MimeBodyPart textBodyPart = textGenerator.generate(originalSender, failedRecipAddresses, fullMessageHeaders);
final MimeMessage dnsMessage = generator.createDSNMessage(originalSender, originalSubject, postmaster, recipientDSNHeaders, messageDSNHeaders, textBodyPart);
ex.getIn().setBody(dnsMessage);
}
}
}
use of org.nhindirect.common.mail.dsn.DSNRecipientHeaders in project nhin-d by DirectProject.
the class AbstractDSNCreator method createDSNFailure.
@Override
public MimeMessage createDSNFailure(Tx tx, NHINDAddressCollection failedRecipeints) throws MessagingException {
InternetAddress originalSender = null;
String originalSubject = "";
InternetAddress postmaster = null;
String originalMessageId = "";
Enumeration<Header> fullMessageHeaders = null;
final List<DSNRecipientHeaders> recipientDSNHeaders = new ArrayList<DSNRecipientHeaders>();
final List<Address> failedRecipAddresses = new ArrayList<Address>();
final TxDetail sender = tx.getDetail(TxDetailType.FROM);
if (sender != null) {
originalSender = new InternetAddress(sender.getDetailValue());
postmaster = new InternetAddress(postmasterMailbox + "@" + getAddressDomain(originalSender));
}
final TxDetail subject = tx.getDetail(TxDetailType.SUBJECT);
if (subject != null)
originalSubject = subject.getDetailValue();
for (NHINDAddress incompleteRecip : failedRecipeints) {
DSNRecipientHeaders dsnRecipHeaders = new DSNRecipientHeaders(DSNAction.FAILED, DSNStatus.getStatus(DSNStatus.PERMANENT, dsnStatus), incompleteRecip);
recipientDSNHeaders.add(dsnRecipHeaders);
failedRecipAddresses.add(incompleteRecip);
}
///CLOVER:OFF
final TxDetail origMessId = tx.getDetail(TxDetailType.MSG_ID);
if (origMessId != null)
originalMessageId = origMessId.getDetailValue();
///CLOVER:ON
final DSNMessageHeaders messageDSNHeaders = new DSNMessageHeaders(reportingMta, originalMessageId, MtaNameType.DNS);
final TxDetail fullHeaders = tx.getDetail(TxDetailType.MSG_FULL_HEADERS);
if (fullHeaders != null)
fullMessageHeaders = this.convertStringToHeaders(fullHeaders.getDetailValue());
final MimeBodyPart textBodyPart = textGenerator.generate(originalSender, failedRecipAddresses, fullMessageHeaders);
return generator.createDSNMessage(originalSender, originalSubject, postmaster, recipientDSNHeaders, messageDSNHeaders, textBodyPart);
}
use of org.nhindirect.common.mail.dsn.DSNRecipientHeaders in project nhin-d by DirectProject.
the class AbstractDSNCreator method createDSNFailure.
@Override
public Collection<MimeMessage> createDSNFailure(Tx tx, NHINDAddressCollection failedRecipeints, boolean useSenderDomainForPostmaster) throws MessagingException {
Collection<MimeMessage> retVal = new ArrayList<MimeMessage>();
InternetAddress originalSender = null;
String originalSubject = "";
String originalMessageId = "";
Enumeration<Header> fullMessageHeaders = null;
final List<Address> failedRecipAddresses = new ArrayList<Address>();
final TxDetail subject = tx.getDetail(TxDetailType.SUBJECT);
if (subject != null)
originalSubject = subject.getDetailValue();
///CLOVER:OFF
final TxDetail origMessId = tx.getDetail(TxDetailType.MSG_ID);
if (origMessId != null)
originalMessageId = origMessId.getDetailValue();
///CLOVER:ON
final TxDetail fullHeaders = tx.getDetail(TxDetailType.MSG_FULL_HEADERS);
if (fullHeaders != null)
fullMessageHeaders = this.convertStringToHeaders(fullHeaders.getDetailValue());
final DSNMessageHeaders messageDSNHeaders = new DSNMessageHeaders(reportingMta, originalMessageId, MtaNameType.DNS);
final TxDetail sender = tx.getDetail(TxDetailType.FROM);
if (sender != null)
originalSender = new InternetAddress(sender.getDetailValue());
final Map<InternetAddress, Collection<NHINDAddress>> dsnMessagePostmasterToFailedRecipMap = groupPostMasterAndFailedRecips(sender, failedRecipeints, useSenderDomainForPostmaster);
if (dsnMessagePostmasterToFailedRecipMap.size() > 0) {
for (Entry<InternetAddress, Collection<NHINDAddress>> entry : dsnMessagePostmasterToFailedRecipMap.entrySet()) {
final List<DSNRecipientHeaders> recipientDSNHeaders = new ArrayList<DSNRecipientHeaders>();
for (NHINDAddress incompleteRecip : entry.getValue()) {
final DSNRecipientHeaders dsnRecipHeaders = new DSNRecipientHeaders(DSNAction.FAILED, DSNStatus.getStatus(DSNStatus.PERMANENT, dsnStatus), incompleteRecip);
recipientDSNHeaders.add(dsnRecipHeaders);
failedRecipAddresses.add(incompleteRecip);
}
final MimeBodyPart textBodyPart = textGenerator.generate(originalSender, failedRecipAddresses, fullMessageHeaders);
final MimeMessage dsnMessage = generator.createDSNMessage(originalSender, originalSubject, entry.getKey(), recipientDSNHeaders, messageDSNHeaders, textBodyPart);
retVal.add(dsnMessage);
}
}
return retVal;
}
Aggregations