Search in sources :

Example 1 with PackageException

use of com.axway.ats.action.objects.model.PackageException 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 2 with PackageException

use of com.axway.ats.action.objects.model.PackageException 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 3 with PackageException

use of com.axway.ats.action.objects.model.PackageException 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 4 with PackageException

use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.

the class MimePackage method getPartChecksum.

/**
     * Return the CRC checksum of a given part
     *
     * @param partIndex
     *            the index of the part
     * @param isAttachment
     *            true if the part is an attachment
     * @return the part checksum
     * @throws PackageException
     */
@PublicAtsApi
public long getPartChecksum(int partIndex, boolean isAttachment) throws PackageException {
    InputStream partDataStream = getPartData(partIndex, isAttachment);
    if (partDataStream != null) {
        try {
            SeekInputStream seekDataStream = new SeekInputStream(partDataStream);
            seekDataStream.seek(0);
            // create a new crc and reset it
            CRC32 crc = new CRC32();
            // use checked stream to get the checksum
            CheckedInputStream stream = new CheckedInputStream(seekDataStream, crc);
            int bufLen = 4096;
            byte[] buffer = new byte[bufLen];
            int numBytesRead = bufLen;
            while (numBytesRead == bufLen) {
                numBytesRead = stream.read(buffer, 0, bufLen);
            }
            long checksum = stream.getChecksum().getValue();
            stream.close();
            return checksum;
        } catch (IOException ioe) {
            throw new PackageException(ioe);
        }
    } else {
        throw new MimePartWithoutContentException("MIME part does not have any content");
    }
}
Also used : SeekInputStream(com.axway.ats.core.io.SeekInputStream) CRC32(java.util.zip.CRC32) CheckedInputStream(java.util.zip.CheckedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SeekInputStream(com.axway.ats.core.io.SeekInputStream) InputStream(java.io.InputStream) MimePartWithoutContentException(com.axway.ats.action.objects.model.MimePartWithoutContentException) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) IOException(java.io.IOException) CheckedInputStream(java.util.zip.CheckedInputStream) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 5 with PackageException

use of com.axway.ats.action.objects.model.PackageException 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)

Aggregations

PackageException (com.axway.ats.action.objects.model.PackageException)52 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)34 MessagingException (javax.mail.MessagingException)32 PublicAtsApi (com.axway.ats.common.PublicAtsApi)31 MimePart (javax.mail.internet.MimePart)11 IOException (java.io.IOException)10 NoSuchMimePartException (com.axway.ats.action.objects.model.NoSuchMimePartException)9 FilePackage (com.axway.ats.action.objects.FilePackage)7 BaseTest (com.axway.ats.rbv.BaseTest)7 InternetAddress (javax.mail.internet.InternetAddress)7 Test (org.junit.Test)7 MimePackage (com.axway.ats.action.objects.MimePackage)6 RbvException (com.axway.ats.rbv.model.RbvException)6 InputStream (java.io.InputStream)6 RbvStorageException (com.axway.ats.rbv.model.RbvStorageException)5 ContentType (javax.mail.internet.ContentType)5 MimeBodyPart (javax.mail.internet.MimeBodyPart)5 MimeMultipart (javax.mail.internet.MimeMultipart)5 FileSystemMetaData (com.axway.ats.rbv.filesystem.FileSystemMetaData)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4