Search in sources :

Example 36 with MimePackage

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

the class Test_MimePackage method constructFromMimeMessage.

@Test
public void constructFromMimeMessage() throws Exception {
    MimePackage message = new MimePackage(new MimeMessage(Session.getDefaultInstance(new Properties()), new FileInputStream(mailMessagePath)));
    assertEquals(4, message.getRegularPartCount());
    assertEquals(2, message.getAttachmentPartCount());
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) MimeMessage(javax.mail.internet.MimeMessage) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Example 37 with MimePackage

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

the class Test_NestedMimePackage method loadNestedMessage.

private void loadNestedMessage() throws PackageException, FileNotFoundException {
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(MAIL_MESSAGE_PATH);
        emailMessage = new MimePackage(fis);
    } finally {
        IoUtils.closeStream(fis);
    }
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) FileInputStream(java.io.FileInputStream)

Example 38 with MimePackage

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

the class Test_Rfc822Headers method parse1Reg2Att.

/**
     * Test is parsing mail with no nested parts. It get the plain/text part on level 1.
     *  
     * - multipart/mixed;
     *   - text/plain
     *   - application/octet-stream
     *   - message/rfc822
     */
@Test
public void parse1Reg2Att() throws Exception {
    String mailMessagePath = Test_MimePackage.class.getResource("RFC822-headers-1_Regular_2_Attachments.eml").getPath();
    MimePackage mimeMessage = PackageLoader.loadMimePackageFromFile(mailMessagePath);
    assertEquals(1, mimeMessage.getRegularPartCount());
    assertEquals(1, mimeMessage.getAttachmentPartCount());
    // first attachment exists and is parsed
    MimePart part = mimeMessage.getPart(0, true);
    assertTrue(part != null);
    // one regular part with text
    assertTrue(mimeMessage.getPlainTextBody().startsWith("This report relates to a message you sent"));
    // nested MimePackage - the RFC822-headers
    MimePackage nestedPackWithHeadersOnly = mimeMessage.getNeededMimePackage(new int[] { 0 });
    List<PackageHeader> headers = nestedPackWithHeadersOnly.getAllHeaders();
    assertTrue(headers.size() == 31);
/* For test debugging
        int i = 0;
        for( PackageHeader packageHeader : headers ) {
            log.info("header[" + i + "] name: [" +  packageHeader.getName()
                               +"] value: [" +  packageHeader.getValue() + "]");
            i++;
        }
        */
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) PackageHeader(com.axway.ats.action.objects.model.PackageHeader) MimePart(javax.mail.internet.MimePart) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Example 39 with MimePackage

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

the class Test_Rfc822Headers method parse2Reg0Att.

/**
     * Test getting text body (plain or html) where text/plain part is located on 2nd level:
     * 
     * - multipart/mixed;
     *   - multipart/alternative;
     *     - text/plain
     *     - text/html
     *   - text/rfc822-headers
     */
@Test
public void parse2Reg0Att() throws Exception {
    String mailMessagePath = Test_MimePackage.class.getResource("RFC822-headers-Mailgate-Notification_2_Regular_0_Attachments.eml").getPath();
    MimePackage mimeMessage = PackageLoader.loadMimePackageFromFile(mailMessagePath);
    assertEquals(2, mimeMessage.getRegularPartCount());
    assertEquals(0, mimeMessage.getAttachmentPartCount());
    assertNotNull(mimeMessage.getPlainTextBody());
    assertNotNull(mimeMessage.getHtmlTextBody());
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) BaseTest(com.axway.ats.action.BaseTest) Test(org.junit.Test)

Example 40 with MimePackage

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

the class Test_MimePackage method constructFromInputStream.

@Test
public void constructFromInputStream() throws Exception {
    MimePackage message = new MimePackage(new FileInputStream(mailMessagePath));
    assertEquals(4, message.getRegularPartCount());
    assertEquals(2, message.getAttachmentPartCount());
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) FileInputStream(java.io.FileInputStream) BaseTest(com.axway.ats.action.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