use of javax.mail.MessagingException in project nhin-d by DirectProject.
the class MDNStandard method getNotificationFieldsAsHeaders.
/**
* Parses the notification part fields of the MimeMultipart body of a MDN message. The multipart is expected to conform to the MDN specification
* as described in RFC3798.
* @return The notification part fields as a set of Internet headers.
*/
public static InternetHeaders getNotificationFieldsAsHeaders(MimeMultipart mm) {
InternetHeaders retVal = null;
if (mm == null)
throw new IllegalArgumentException("Multipart can not be null");
try {
if (mm.getCount() < 2)
throw new IllegalArgumentException("Multipart can not be null");
// the second part should be the notification
BodyPart part = mm.getBodyPart(1);
try {
Object contecntObj = part.getContent();
if (dsnClass != null && dsnClass.getCanonicalName().equals(contecntObj.getClass().getCanonicalName())) {
retVal = (InternetHeaders) getHeaders.invoke(contecntObj);
return retVal;
}
} catch (Exception e) {
/* no-op */
}
if (!part.getContentType().equalsIgnoreCase(MDNStandard.MediaType.DispositionNotification))
throw new IllegalArgumentException("Notification part content type is not " + MDNStandard.MediaType.DispositionNotification);
// parse fields
retVal = new InternetHeaders();
String[] fields = getPartContentBodyAsString(part).split("\r\n");
for (String field : fields) {
int idx = field.indexOf(":");
if (idx > -1) {
String name = field.substring(0, idx);
String value = field.substring(idx + 1).trim();
retVal.setHeader(name, value);
}
}
} catch (MessagingException e) {
throw new IllegalArgumentException("Failed to parse notification fields.", e);
}
return retVal;
}
use of javax.mail.MessagingException in project nhin-d by DirectProject.
the class HumanReadableTextAssembler method makeBodyPart.
protected MimeBodyPart makeBodyPart(List<Address> rejectedRecipients, String errorMessage) throws MessagingException {
String assembleHtmlBody;
try {
assembleHtmlBody = assembleHtmlBody(rejectedRecipients, errorMessage);
} catch (IOException e) {
throw new MessagingException("", e);
}
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setContent(assembleHtmlBody, "text/html");
return mimeBodyPart;
}
use of javax.mail.MessagingException in project nhin-d by DirectProject.
the class DefaultTxDetailParser method getMessageDetails.
public Map<String, TxDetail> getMessageDetails(InputStream stream) {
Map<String, TxDetail> retVal = null;
if (stream == null)
throw new IllegalArgumentException("Input stream cannot be null");
try {
// convert into a MimeMessage
final MimeMessage msg = new MimeMessage(null, stream);
retVal = getMessageDetails(msg);
}///CLOVER:OFF
catch (MessagingException e) {
LOGGER.warn("Failed to translate input stream into MimeMessage.", e);
}
return retVal;
}
use of javax.mail.MessagingException in project nhin-d by DirectProject.
the class Message method extractMimeEntity.
/**
* Gets a copy of this message without any non-mime headers.
* @returns A copy of this message without any non-mime headers.
*/
@SuppressWarnings("unchecked")
public MimeEntity extractMimeEntity() {
MimeEntity retVal = null;
try {
InternetHeaders headers = new InternetHeaders();
if (this.headers.getAllHeaders().hasMoreElements()) {
Enumeration<javax.mail.Header> hEnum = this.headers.getAllHeaders();
while (hEnum.hasMoreElements()) {
javax.mail.Header hdr = hEnum.nextElement();
if (MimeStandard.startsWith(hdr.getName(), MimeStandard.HeaderPrefix))
headers.addHeader(hdr.getName(), hdr.getValue());
}
if (!headers.getAllHeaders().hasMoreElements()) {
throw new MimeException(MimeError.InvalidMimeEntity);
}
retVal = new MimeEntity(headers, getContentAsBytes());
}
} catch (MessagingException e) {
throw new MimeException(MimeError.InvalidMimeEntity, e);
}
return retVal;
}
use of javax.mail.MessagingException in project nhin-d by DirectProject.
the class Notification method serializeToBytes.
/**
* Serializes the notification to an array of bytes.
* @return byte array serialized form on this notification.
*/
public byte[] serializeToBytes() {
if (report == null)
updateReport();
ByteArrayOutputStream oStream = null;
try {
oStream = new ByteArrayOutputStream();
report.writeTo(oStream);
oStream.flush();
} catch (MessagingException e) {
} catch (IOException e) {
}
return oStream.toByteArray();
}
Aggregations