use of javax.mail.Address 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 javax.mail.Address in project nhin-d by DirectProject.
the class ReliableDispatchedNotificationProducer_produceTest method getMailRecipients.
protected NHINDAddressCollection getMailRecipients(MimeMessage mail) throws MessagingException {
final NHINDAddressCollection recipients = new NHINDAddressCollection();
final Address[] recipsAddr = mail.getAllRecipients();
for (Address addr : recipsAddr) {
recipients.add(new NHINDAddress(addr.toString(), (AddressSource) null));
}
return recipients;
}
use of javax.mail.Address 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;
}
use of javax.mail.Address in project nhin-d by DirectProject.
the class MockMail method getSender.
public MailAddress getSender() {
MailAddress retVal = null;
try {
Address addr = mimeMessage.getSender();
if (addr == null) {
Address[] addrs = mimeMessage.getFrom();
addr = addrs[0];
}
retVal = new MailAddress(addr.toString());
} catch (Exception e) {
}
return retVal;
}
use of javax.mail.Address in project nhin-d by DirectProject.
the class DefaultMimeXdsTransformer method getSubmissionSet.
/*
* Metadata Attribute XDS Minimal Metadata
* -----------------------------------------------------
* author R2 R
* contentTypeCode R R2
* entryUUID R R
* intendedRecipient O R
* patientId R R2
* sourceId R R
* submissionTime R R
* title O O
* uniqueId R R
*/
private DirectDocuments.SubmissionSet getSubmissionSet(String subject, Date sentDate, String auth, Address[] recipients) throws Exception {
DirectDocuments.SubmissionSet submissionSet = new DirectDocuments.SubmissionSet();
// (R) Minimal Metadata Source
// TODO: format this correctly
submissionSet.setAuthorTelecommunication(auth);
// TODO: "UUID URN mapped by configuration to sending organization"
submissionSet.setSourceId("TODO");
submissionSet.setSubmissionTime(sentDate);
submissionSet.setUniqueId(UUID.randomUUID().toString());
for (Address address : recipients) {
submissionSet.getIntendedRecipient().add("||^^Internet^" + address.toString());
}
// (R2) Minimal Metadata Source
// --
// (O) Minimal Metadata Source
// TODO: title (subject)
// Additional metadata from document parsing
documentType.parse(new String(xdsDocument), submissionSet);
return submissionSet;
}
Aggregations