Search in sources :

Example 56 with MessagingException

use of javax.mail.MessagingException in project ats-framework by Axway.

the class MimePackage method getRegularPartCharset.

/**
     * Get the character set of a regular part
     *
     * @param partIndex
     *            the index of the part
     * @return the charset
     * @throws PackageException
     */
@PublicAtsApi
public String getRegularPartCharset(int partIndex) throws PackageException {
    // first check if there is part at this position at all
    if (partIndex >= regularPartIndices.size()) {
        throw new NoSuchMimePartException("No regular part at position '" + partIndex + "'");
    }
    try {
        MimePart part = getPart(regularPartIndices.get(partIndex));
        // get the content type header
        ContentType contentType = new ContentType(part.getContentType());
        return contentType.getParameter("charset");
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : ContentType(javax.mail.internet.ContentType) MessagingException(javax.mail.MessagingException) NoSuchMimePartException(com.axway.ats.action.objects.model.NoSuchMimePartException) MimePart(javax.mail.internet.MimePart) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 57 with MessagingException

use of javax.mail.MessagingException in project ats-framework by Axway.

the class MimePackage method getAllHeaders.

@SuppressWarnings("unchecked")
@PublicAtsApi
public List<PackageHeader> getAllHeaders() throws PackageException {
    try {
        List<PackageHeader> headers = new ArrayList<PackageHeader>();
        Enumeration<Header> messageHeaders = message.getAllHeaders();
        while (messageHeaders.hasMoreElements()) {
            Header messageHeader = messageHeaders.nextElement();
            headers.add(new PackageHeader(messageHeader.getName(), messageHeader.getValue()));
        }
        return headers;
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : Header(javax.mail.Header) PackageHeader(com.axway.ats.action.objects.model.PackageHeader) MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) PackageHeader(com.axway.ats.action.objects.model.PackageHeader) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 58 with MessagingException

use of javax.mail.MessagingException in project ats-framework by Axway.

the class MimePackage method writeToFile.

/**
     * Write the constructed MIME message to a file
     *
     * @param fileName
     *            the name of the file to write to
     *
     * @throws IOException
     * @throws PackageException
     */
@PublicAtsApi
public void writeToFile(String fileName) throws IOException, PackageException {
    FileOutputStream outStream = null;
    boolean storeReconnected = false;
    try {
        storeReconnected = reconnectStoreIfClosed();
        // store should be opened for actions including getting InputStream. Hence store open is not in getPart
        outStream = new FileOutputStream(new File(fileName));
        message.writeTo(outStream);
    } catch (MessagingException me) {
        throw new PackageException("Could not write message content", me);
    } finally {
        if (outStream != null) {
            outStream.close();
        }
        try {
            closeStoreConnection(storeReconnected);
        } catch (MessagingException ex) {
            log.warn("Error closing IMAP connection", ex);
        }
    }
}
Also used : MessagingException(javax.mail.MessagingException) FileOutputStream(java.io.FileOutputStream) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) File(java.io.File) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 59 with MessagingException

use of javax.mail.MessagingException in project ats-framework by Axway.

the class MimePackage method getInternetHeaders.

private InternetHeaders getInternetHeaders(Object partContent) throws PackageException {
    InternetHeaders internetHeaders = null;
    if (partContent instanceof InputStream) {
        try {
            InputStream is = (InputStream) partContent;
            internetHeaders = new InternetHeaders(is);
        } catch (MessagingException e) {
            // error converting to InternetHeaders
            throw new PackageException("Error parsing internet headers with type rfc822-headers", e);
        }
    }
    return internetHeaders;
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders) MessagingException(javax.mail.MessagingException) CheckedInputStream(java.util.zip.CheckedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SeekInputStream(com.axway.ats.core.io.SeekInputStream) InputStream(java.io.InputStream) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException)

Example 60 with MessagingException

use of javax.mail.MessagingException in project ats-framework by Axway.

the class MimePackage method getWholePackage.

@PublicAtsApi
public InputStream getWholePackage() throws PackageException {
    boolean storeReconnected = false;
    try {
        storeReconnected = reconnectStoreIfClosed();
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        message.writeTo(outStream);
        return new ByteArrayInputStream(outStream.toByteArray());
    } catch (MessagingException me) {
        throw new PackageException("Could not write message content", me);
    } catch (IOException ioe) {
        throw new PackageException("Could not write message content", ioe);
    } finally {
        try {
            closeStoreConnection(storeReconnected);
        } catch (MessagingException ex) {
            log.warn(ex);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MessagingException(javax.mail.MessagingException) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

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