Search in sources :

Example 6 with NoSuchMimePartException

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

the class MimePackage method getPartHeader.

/**
     * Get the specified header value from a specified MIME part
     *
     * @param headerName
     * @param partNum
     * @param headerIndex
     * @return
     * @throws PackageException
     */
@PublicAtsApi
public String getPartHeader(String headerName, int partNum, int headerIndex) throws PackageException {
    try {
        String[] headers;
        if (partNum >= parts.size()) {
            throw new NoSuchMimePartException("No MIME part at position '" + partNum + "'");
        }
        MimePart part = parts.get(partNum);
        headers = part.getHeader(headerName);
        if ((headers != null) && (headers.length > headerIndex)) {
            return headers[headerIndex];
        } else {
            throw new NoSuchHeaderException(headerName, partNum, headerIndex);
        }
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : 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) NoSuchHeaderException(com.axway.ats.action.objects.model.NoSuchHeaderException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 7 with NoSuchMimePartException

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

the class MimePackage method getRegularPartContentType.

/**
     * Get the content type of a regular part
     *
     * @param partIndex
     *            the index of the regular part
     * @return the content type as string
     * @throws PackageException
     */
@PublicAtsApi
public String getRegularPartContentType(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.getBaseType();
    } 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 8 with NoSuchMimePartException

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

the class MimePackage method getAttachmentFileName.

/**
     * Get an attachment's file name
     *
     * @param partIndex
     * @return
     * @throws PackageException
     */
@PublicAtsApi
public String getAttachmentFileName(int partIndex) throws PackageException {
    // first check if there is part at this position at all
    if (partIndex >= attachmentPartIndices.size()) {
        throw new NoSuchMimePartException("No attachment at position '" + partIndex + "'");
    }
    try {
        MimePart part = getPart(attachmentPartIndices.get(partIndex));
        // get the attachment file name
        String fileName = part.getFileName();
        if (fileName == null) {
            throw new PackageException("Could not determine file name for attachment at position " + partIndex);
        }
        return fileName;
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : 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 9 with NoSuchMimePartException

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

the class Test_NoSuchMimePartException method constructors.

@Test
public void constructors() {
    NoSuchMimePartException exception;
    exception = new NoSuchMimePartException("test");
    assertEquals("test", exception.getMessage());
    assertNull(exception.getCause());
    Exception helperException = new Exception();
    exception = new NoSuchMimePartException("test", helperException);
    assertEquals("test", exception.getMessage());
    assertEquals(helperException, exception.getCause());
    exception = new NoSuchMimePartException(helperException);
    assertEquals("java.lang.Exception", exception.getMessage());
    assertEquals(helperException, exception.getCause());
}
Also used : NoSuchMimePartException(com.axway.ats.action.objects.model.NoSuchMimePartException) NoSuchMimePartException(com.axway.ats.action.objects.model.NoSuchMimePartException) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 10 with NoSuchMimePartException

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

the class MimePackage method getAttachmentCharset.

/**
     * Get the attachment character set
     *
     * @param partIndex
     *            the index of the attachment
     * @return the character set for this attachment, null if there is no such
     * @throws PackageException
     */
@PublicAtsApi
public String getAttachmentCharset(int partIndex) throws PackageException {
    // first check if there is part at this position at all
    if (partIndex >= attachmentPartIndices.size()) {
        throw new NoSuchMimePartException("No attachment at position '" + partIndex + "'");
    }
    try {
        MimePart part = getPart(attachmentPartIndices.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)

Aggregations

NoSuchMimePartException (com.axway.ats.action.objects.model.NoSuchMimePartException)14 MimePart (javax.mail.internet.MimePart)12 PackageException (com.axway.ats.action.objects.model.PackageException)9 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)8 PublicAtsApi (com.axway.ats.common.PublicAtsApi)8 MessagingException (javax.mail.MessagingException)8 MimePackage (com.axway.ats.action.objects.MimePackage)5 Test (org.junit.Test)5 BaseTest (com.axway.ats.action.BaseTest)4 ContentType (javax.mail.internet.ContentType)4 NoSuchHeaderException (com.axway.ats.action.objects.model.NoSuchHeaderException)2 BaseTest (com.axway.ats.rbv.BaseTest)1 ImapMetaData (com.axway.ats.rbv.imap.ImapMetaData)1 RbvException (com.axway.ats.rbv.model.RbvException)1 InputStream (java.io.InputStream)1