Search in sources :

Example 1 with NoSuchMimePartException

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

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

the class MimePackage method setAttachmentFileName.

/**
     * Set/modify attachment file name
     *
     * @param attachmentPartIndex index among attachment parts only
     * @param fileName the file name. Add one or reset existing one
     * @throws NoSuchMimePartException if not such attachment part is found
     * @throws PackageException in case of other mail messaging exception
     */
@PublicAtsApi
public void setAttachmentFileName(int attachmentPartIndex, String fileName) throws PackageException {
    // first check if there is part at this position at all
    if (attachmentPartIndex >= attachmentPartIndices.size()) {
        throw new NoSuchMimePartException("No attachment at position '" + attachmentPartIndex + "'");
    }
    try {
        MimePart part = getPart(attachmentPartIndices.get(attachmentPartIndex));
        // set the attachment file name
        part.setFileName(fileName);
        // must save now
        this.message.saveChanges();
    } 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 3 with NoSuchMimePartException

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

the class MimePartRule method performMatch.

@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
    boolean actualResult = false;
    //get the emailMessage
    //the meta data type check already passed, so it is safe to cast
    MimePackage emailMessage = ((ImapMetaData) metaData).getMimePackage();
    try {
        InputStream actualPartDataStream = null;
        try {
            actualPartDataStream = emailMessage.getPartData(partIndex, isPartAttachment);
        } catch (NoSuchMimePartException e) {
            //if there is no such mime part then the parts do not match
            log.debug("No MIME part at position '" + partIndex + "'");
            return false;
        }
        if (actualPartDataStream != null) {
            long actualChecksum = emailMessage.getPartChecksum(partIndex, isPartAttachment);
            actualResult = (expectedChecksum == actualChecksum);
        } else {
            log.debug("MIME part at position '" + partIndex + "' does not have any content");
            return false;
        }
    } catch (PackageException pe) {
        throw new RbvException(pe);
    }
    return actualResult;
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) ImapMetaData(com.axway.ats.rbv.imap.ImapMetaData) InputStream(java.io.InputStream) RbvException(com.axway.ats.rbv.model.RbvException) NoSuchMimePartException(com.axway.ats.action.objects.model.NoSuchMimePartException) PackageException(com.axway.ats.action.objects.model.PackageException)

Example 4 with NoSuchMimePartException

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

the class Test_MimePackage method setBody_multiParts_with_textAndHtmlParts.

@Test
public void setBody_multiParts_with_textAndHtmlParts() throws Exception {
    // create a new message and add TEXT and HTML parts to it
    MimePackage newMailMessage = new MimePackage();
    newMailMessage.addPart("text plain body", MimePackage.PART_TYPE_TEXT_PLAIN);
    newMailMessage.addPart("html body", MimePackage.PART_TYPE_TEXT_HTML);
    MimePart textPart = newMailMessage.getPart(0, false);
    assertEquals(textPart.getContent(), "text plain body");
    assertEquals(textPart.getContentType(), "text/plain; charset=us-ascii");
    MimePart htmlPart = newMailMessage.getPart(1, false);
    assertEquals(htmlPart.getContent(), "html body");
    assertEquals(htmlPart.getContentType(), "text/html; charset=us-ascii");
    // modify both parts
    newMailMessage.setBody("new body");
    // verify the modifications
    MimePart newTextPart = newMailMessage.getPart(0, false);
    assertEquals(newTextPart.getContent(), "new body");
    assertEquals(newTextPart.getContentType(), "text/plain; charset=us-ascii");
    MimePart newHtmlPart = newMailMessage.getPart(1, false);
    assertEquals(newHtmlPart.getContent(), "new body");
    assertEquals(newHtmlPart.getContentType(), "text/html; charset=us-ascii");
    // verify there are no more parts
    try {
        newMailMessage.getPart(2, false);
        assertTrue("There is more than 2 parts, while we expect to have just 2", false);
    } catch (NoSuchMimePartException e) {
    }
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) MimePart(javax.mail.internet.MimePart) NoSuchMimePartException(com.axway.ats.action.objects.model.NoSuchMimePartException) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Example 5 with NoSuchMimePartException

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

the class Test_MimePackage method setBody_multiParts_with_htmlPart_only.

@Test
public void setBody_multiParts_with_htmlPart_only() throws Exception {
    // create a new message and add HTML part to it
    MimePackage newMailMessage = new MimePackage();
    newMailMessage.addPart("html body", MimePackage.PART_TYPE_TEXT_HTML);
    MimePart htmlPart = newMailMessage.getPart(0, false);
    assertEquals(htmlPart.getContent(), "html body");
    assertEquals(htmlPart.getContentType(), "text/html; charset=us-ascii");
    // modify the only part
    newMailMessage.setBody("new body");
    // verify the modifications
    MimePart newHtmlPart = newMailMessage.getPart(0, false);
    assertEquals(newHtmlPart.getContent(), "new body");
    assertEquals(newHtmlPart.getContentType(), "text/html; charset=us-ascii");
    // verify there are no more parts
    try {
        newMailMessage.getPart(1, false);
        assertTrue("There is more than 1 part, while we expect to have just 1", false);
    } catch (NoSuchMimePartException e) {
    }
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) MimePart(javax.mail.internet.MimePart) NoSuchMimePartException(com.axway.ats.action.objects.model.NoSuchMimePartException) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

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