Search in sources :

Example 11 with PackageException

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

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

the class MimePackage method getRecipients.

/**
     * Get the recipients of the specified type
     *
     * @param recipientType
     *            the type of recipient - to, cc or bcc
     * @return array with recipients, emtpy array of no recipients of this type
     *         are present
     * @throws PackageException
     */
@PublicAtsApi
public String[] getRecipients(RecipientType recipientType) throws PackageException {
    try {
        Address[] recipientAddresses = message.getRecipients(recipientType.toJavamailType());
        // return an empty string if no recipients are present
        if (recipientAddresses == null) {
            return new String[] {};
        }
        String[] recipients = new String[recipientAddresses.length];
        for (int i = 0; i < recipientAddresses.length; i++) {
            recipients[i] = recipientAddresses[i].toString();
        }
        return recipients;
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) MessagingException(javax.mail.MessagingException) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 13 with PackageException

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

the class MimePackage method addAlternativePart.

/**
     * Add a multipart/alternative part to message body
     *
     * @param plainContent
     *            the content of the text/plain sub-part
     * @param htmlContent
     *            the content of the text/html sub-part
     * @param charset
     *            the character set for the part
     * @throws PackageException
     */
@PublicAtsApi
public void addAlternativePart(String plainContent, String htmlContent, String charset) throws PackageException {
    MimeMultipart alternativePart = new MimeMultipart("alternative");
    try {
        // create a new text/plain part
        MimeBodyPart plainPart = new MimeBodyPart();
        plainPart.setText(plainContent, charset, PART_TYPE_TEXT_PLAIN);
        plainPart.setDisposition(MimeBodyPart.INLINE);
        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setText(htmlContent, charset, PART_TYPE_TEXT_HTML);
        htmlPart.setDisposition(MimeBodyPart.INLINE);
        alternativePart.addBodyPart(plainPart, 0);
        alternativePart.addBodyPart(htmlPart, 1);
        MimeBodyPart mimePart = new MimeBodyPart();
        mimePart.setContent(alternativePart);
        addPart(mimePart, PART_POSITION_LAST);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) MessagingException(javax.mail.MessagingException) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) MimeBodyPart(javax.mail.internet.MimeBodyPart) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 14 with PackageException

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

the class MimePackage method addRecipient.

/**
     * Add recipients of a specified type
     *
     * @param type the recipients' type
     * @param addresses the email addresses of the recipients
     * @throws PackageException
     */
@PublicAtsApi
public void addRecipient(RecipientType type, String[] addresses) throws PackageException {
    try {
        // add the recipient
        InternetAddress[] address = new InternetAddress[addresses.length];
        for (int i = 0; i < addresses.length; i++) address[i] = new InternetAddress(addresses[i]);
        message.addRecipients(type.toJavamailType(), address);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MessagingException(javax.mail.MessagingException) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 15 with PackageException

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

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