Search in sources :

Example 71 with MessagingException

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;
}
Also used : BodyPart(javax.mail.BodyPart) InternetHeaders(javax.mail.internet.InternetHeaders) MessagingException(javax.mail.MessagingException) MessagingException(javax.mail.MessagingException)

Example 72 with MessagingException

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;
}
Also used : MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Example 73 with MessagingException

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;
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) TxDetail(org.nhindirect.common.tx.model.TxDetail)

Example 74 with MessagingException

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;
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders) MessagingException(javax.mail.MessagingException)

Example 75 with MessagingException

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();
}
Also used : MessagingException(javax.mail.MessagingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

MessagingException (javax.mail.MessagingException)343 MimeMessage (javax.mail.internet.MimeMessage)135 IOException (java.io.IOException)126 InternetAddress (javax.mail.internet.InternetAddress)70 MimeMultipart (javax.mail.internet.MimeMultipart)64 MimeBodyPart (javax.mail.internet.MimeBodyPart)63 Message (javax.mail.Message)49 Properties (java.util.Properties)45 Session (javax.mail.Session)45 InputStream (java.io.InputStream)43 Date (java.util.Date)34 Address (javax.mail.Address)33 PackageException (com.axway.ats.action.objects.model.PackageException)32 ArrayList (java.util.ArrayList)32 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)31 PublicAtsApi (com.axway.ats.common.PublicAtsApi)31 ServiceException (com.zimbra.common.service.ServiceException)30 ByteArrayInputStream (java.io.ByteArrayInputStream)26 DataHandler (javax.activation.DataHandler)25 UnsupportedEncodingException (java.io.UnsupportedEncodingException)24