Search in sources :

Example 21 with MimePackage

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

the class Test_Rfc822Headers method parseNestedNoBody.

/**
     * Test getting text body (plain or html) not possible, because text/plain part is located on 3nd level,
     *  and on 2nd level are located unknown parts:
     *  
     * - multipart/mixed;
     *    - multipart/mixed;
     *      - multipart/alternative;
     *          - text/plain
     *          - text/html
     *    - multipart/alternative;
     *          - text/myPlain
     *          - text/myHTML
     */
@Test
public void parseNestedNoBody() throws Exception {
    String mailMessagePath = Test_MimePackage.class.getResource("nestedMessagesNoBody.eml").getPath();
    MimePackage mimeMessage = PackageLoader.loadMimePackageFromFile(mailMessagePath);
    assertEquals(2, mimeMessage.getRegularPartCount());
    assertEquals(0, mimeMessage.getAttachmentPartCount());
    // exists but nested 3 levels.
    assertNull(mimeMessage.getPlainTextBody());
    // exists but nested 3 levels.
    assertNull(mimeMessage.getHtmlTextBody());
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Example 22 with MimePackage

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

the class AttachmentNameRule method performMatch.

@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
    //get the emailMessage
    //the meta data type check already passed, so it is safe to cast
    MimePackage emailMessage = getNeededMimePackage(metaData);
    String attachmentFileName;
    try {
        attachmentFileName = emailMessage.getAttachmentFileName(attachmentIndex);
    } catch (PackageException pe) {
        throw new RbvException(pe);
    }
    //if there is no such file name return false 
    boolean actualResult = false;
    if (attachmentFileName != null) {
        actualResult = Pattern.compile(expectedValue).matcher(attachmentFileName).matches();
        log.info("Actual attachment file name is '" + attachmentFileName + "'");
    } else {
        log.info("No attachment with name that matches '" + expectedValue + "' was found");
    }
    return actualResult;
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) RbvException(com.axway.ats.rbv.model.RbvException) PackageException(com.axway.ats.action.objects.model.PackageException)

Example 23 with MimePackage

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

the class HeaderRule method performMatch.

@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
    //get the emailMessage
    //the meta data type check already passed, so it is safe to cast
    MimePackage emailMessage = getNeededMimePackage(metaData);
    String[] headerValues;
    try {
        if (headerIndex == -1) {
            // we are going to check all header values
            if (partIndex == PART_MAIN_MESSAGE) {
                headerValues = emailMessage.getHeaderValues(headerName);
            } else {
                headerValues = emailMessage.getPartHeaderValues(headerName, partIndex);
            }
        } else {
            // we are going to check a particular header value
            String headerValue;
            if (partIndex == PART_MAIN_MESSAGE) {
                headerValue = emailMessage.getHeader(headerName, headerIndex);
            } else {
                headerValue = emailMessage.getPartHeader(headerName, partIndex, headerIndex);
            }
            headerValues = new String[] { headerValue };
        }
    } catch (NoSuchHeaderException nshe) {
        log.debug("Meta data has no header '" + headerName + "'");
        //no such header, so return false
        return false;
    } catch (PackageException pe) {
        throw new RbvException(pe);
    }
    //if there is no such header return false
    boolean actualResult = false;
    if (headerValues == null || headerValues.length == 0) {
        log.info("No header '" + headerName + "' was found");
    } else {
        for (String headerValue : headerValues) {
            switch(matchMode) {
                case LEFT:
                    actualResult = headerValue.startsWith(expectedValue);
                    break;
                case RIGHT:
                    actualResult = headerValue.endsWith(expectedValue);
                    break;
                case EQUALS:
                    actualResult = headerValue.equals(expectedValue);
                    break;
                case FIND:
                    actualResult = headerValue.indexOf(expectedValue) >= 0;
                    break;
                case REGEX:
                    actualResult = Pattern.compile(expectedValue).matcher(headerValue).find();
                    break;
            }
            log.info("Actual value for header '" + headerName + "' is '" + headerValue + "'");
            if (actualResult) {
                // we matched a header value, stop iterating the rest of the values
                break;
            }
        }
    }
    return actualResult;
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) RbvException(com.axway.ats.rbv.model.RbvException) PackageException(com.axway.ats.action.objects.model.PackageException) NoSuchHeaderException(com.axway.ats.action.objects.model.NoSuchHeaderException)

Example 24 with MimePackage

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

the class Test_StringInMimePartRule method isMatchRegexRegularPartUTF8Positive.

@Test
public void isMatchRegexRegularPartUTF8Positive() throws RbvException, PackageException {
    MimePackage utf8Package = new MimePackage();
    utf8Package.addPart("Изчерпателна информация", MimePackage.PART_TYPE_TEXT_PLAIN, "utf-8");
    ImapMetaData utf8MetaData = new ImapMetaData(utf8Package);
    //expected true
    StringInMimePartRule rule = new StringInMimePartRule(".*информация$", true, 0, false, "isMatchRegexRegularPartPositive1", true);
    assertTrue(rule.isMatch(utf8MetaData));
    //expected false
    rule = new StringInMimePartRule("Изчерпателна.*яа", true, 0, false, "isMatchRegexRegularPartPositive2", false);
    assertTrue(rule.isMatch(utf8MetaData));
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) ImapMetaData(com.axway.ats.rbv.imap.ImapMetaData) StringInMimePartRule(com.axway.ats.rbv.imap.rules.StringInMimePartRule) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 25 with MimePackage

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

the class Test_MimePartRule method isMatchRegularPartNoSuchPart.

@Test
public void isMatchRegularPartNoSuchPart() throws PackageException, RbvException {
    mailMessage = new MimePackage(Test_MimePartRule.class.getResourceAsStream("mail_with_one_attachment.msg"));
    metaData = new ImapMetaData(mailMessage);
    //expected true
    MimePartRule rule = new MimePartRule(expectedMailMessage, 2, false, "isMatchRegularPartNoSuchPart1", true);
    assertFalse(rule.isMatch(metaData));
    //expected false
    rule = new MimePartRule(expectedMailMessage, 2, false, "isMatchRegularPartNoSuchPart2", false);
    assertTrue(rule.isMatch(metaData));
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) ImapMetaData(com.axway.ats.rbv.imap.ImapMetaData) MimePartRule(com.axway.ats.rbv.imap.rules.MimePartRule) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Aggregations

MimePackage (com.axway.ats.action.objects.MimePackage)53 Test (org.junit.Test)35 BaseTest (com.axway.ats.action.BaseTest)29 ImapMetaData (com.axway.ats.rbv.imap.ImapMetaData)15 Before (org.junit.Before)7 PackageException (com.axway.ats.action.objects.model.PackageException)6 BaseTest (com.axway.ats.rbv.BaseTest)6 FileInputStream (java.io.FileInputStream)6 MimePart (javax.mail.internet.MimePart)6 NoSuchMimePartException (com.axway.ats.action.objects.model.NoSuchMimePartException)5 RbvException (com.axway.ats.rbv.model.RbvException)5 Test_ImapStorage (com.axway.ats.rbv.imap.Test_ImapStorage)4 StringInMimePartRule (com.axway.ats.rbv.imap.rules.StringInMimePartRule)4 MimePartRule (com.axway.ats.rbv.imap.rules.MimePartRule)2 InputStream (java.io.InputStream)2 MessagingException (javax.mail.MessagingException)2 BeforeClass (org.junit.BeforeClass)2 MailSender (com.axway.ats.action.mail.MailSender)1 MailTransportListener (com.axway.ats.action.mail.model.MailTransportListener)1 DELIVERY_STATE (com.axway.ats.action.mail.model.MailTransportListener.DELIVERY_STATE)1