Search in sources :

Example 1 with DSNAction

use of org.nhindirect.common.mail.dsn.DSNStandard.DSNAction in project nhin-d by DirectProject.

the class DSNGenerator method createDeliveryStatus.

/**
	 * Creates the deliver status section of the message
	 * @param recipientDSNHeaders
	 * @param messageDSNHeaders
	 * @return
	 * @throws MessagingException
	 */
protected DeliveryStatus createDeliveryStatus(List<DSNRecipientHeaders> recipientDSNHeaders, DSNMessageHeaders messageDSNHeaders) throws MessagingException {
    final DeliveryStatus deliveryStatus = new DeliveryStatus();
    for (DSNRecipientHeaders dsnHeaders : recipientDSNHeaders) {
        final InternetHeaders recipHeaders = new InternetHeaders();
        final DSNAction dsnAction = dsnHeaders.getAction();
        recipHeaders.addHeader(DSNStandard.Headers.Action, "" + dsnAction);
        final Address finalRecipient = dsnHeaders.getFinalRecipient();
        if (finalRecipient != null) {
            recipHeaders.addHeader(DSNStandard.Headers.FinalRecipient, finalRecipient.getType() + ";" + finalRecipient.toString());
        }
        String status = dsnHeaders.getStatus();
        recipHeaders.addHeader(DSNStandard.Headers.Status, status);
        deliveryStatus.addRecipientDSN(recipHeaders);
    }
    final InternetHeaders messageHeaders = new InternetHeaders();
    final MtaNameType mtaNameType = messageDSNHeaders.getMtaNameType();
    final String reportingMta = messageDSNHeaders.getReportingMta();
    messageHeaders.addHeader(DSNStandard.Headers.ReportingMTA, mtaNameType + ";" + reportingMta);
    // add a custom header with original message id
    final String originalMessageId = messageDSNHeaders.getOriginalMessageId();
    messageHeaders.addHeader(DSNStandard.Headers.OriginalMessageID, originalMessageId);
    deliveryStatus.setMessageDSN(messageHeaders);
    return deliveryStatus;
}
Also used : MtaNameType(org.nhindirect.common.mail.dsn.DSNStandard.MtaNameType) InternetHeaders(javax.mail.internet.InternetHeaders) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) DeliveryStatus(com.sun.mail.dsn.DeliveryStatus) DSNAction(org.nhindirect.common.mail.dsn.DSNStandard.DSNAction)

Aggregations

DeliveryStatus (com.sun.mail.dsn.DeliveryStatus)1 Address (javax.mail.Address)1 InternetAddress (javax.mail.internet.InternetAddress)1 InternetHeaders (javax.mail.internet.InternetHeaders)1 DSNAction (org.nhindirect.common.mail.dsn.DSNStandard.DSNAction)1 MtaNameType (org.nhindirect.common.mail.dsn.DSNStandard.MtaNameType)1