Search in sources :

Example 46 with MimePackage

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

the class ImapFolder method createImapMetaData.

/**
     * This method will convert a MIME message to meta data
     *
     * @param mimeMessage   the input MimeMessage instance
     * @return              the MetaData produced
     * @throws RbvStorageException
     */
protected ImapMetaData createImapMetaData(MimeMessage mimeMessage) throws RbvException {
    try {
        MimePackage mimePackage = new MimePackage(mimeMessage);
        ImapMetaData metaData = new ImapMetaData(mimePackage);
        return metaData;
    } catch (PackageException pe) {
        throw new RbvStorageException("Could not get meta data from " + getDescription(), pe);
    }
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) PackageException(com.axway.ats.action.objects.model.PackageException) RbvStorageException(com.axway.ats.rbv.model.RbvStorageException)

Example 47 with MimePackage

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

the class Test_Rfc822Headers method parseNestedNoPlain.

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

Example 48 with MimePackage

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

the class Test_SubjectRule method setUp.

@Before
public void setUp() throws Exception {
    MimePackage mailMessage = new MimePackage(Test_ImapStorage.class.getResourceAsStream("mail.msg"));
    metaData = new ImapMetaData(mailMessage);
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) ImapMetaData(com.axway.ats.rbv.imap.ImapMetaData) Test_ImapStorage(com.axway.ats.rbv.imap.Test_ImapStorage) Before(org.junit.Before)

Example 49 with MimePackage

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

the class Test_StringInMimePartRule method isMatchRegularPartUTF8Positive.

@Test
public void isMatchRegularPartUTF8Positive() 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("Изчерпателна", false, 0, false, "isMatchRegularPartPositive1", true);
    assertTrue(rule.isMatch(utf8MetaData));
    //expected false
    rule = new StringInMimePartRule("Изчерпатслна", false, 0, false, "isMatchRegularPartPositive2", 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 50 with MimePackage

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

the class MailSender method send.

/**
     * Sends a MIME package by invoking the following actions:
     *
     * <blockquote> 1. Tags the package, this can be later used for IMAP verification<br>
     * 2. Sings the package when a signer is specified<br>
     * 3. Encrypts the package when a encryptor is specified<br>
     * 4. Sends it </blockquote>
     *
     * @see com.axway.ats.action.model.PackageSender#send(com.axway.ats.action.objects.model.Package)
     */
@Override
@PublicAtsApi
public void send(Package sourcePackage) throws ActionException {
    if (!(sourcePackage instanceof MimePackage)) {
        throw new WrongPackageException("Cannot send '" + sourcePackage.getClass().getSimpleName() + "' packages");
    }
    // initialize the SMTP session
    initSession();
    MimePackage mimePackage = (MimePackage) sourcePackage;
    // tag the package
    mimePackage.tag();
    // then send
    final DELIVERY_STATE messageDeliveryState;
    try {
        log.info("Connect to mail server " + mailHost + " at port " + mailPort);
        Object messageSendingMutex = new Object();
        MailTransportListener transListener = new MailTransportListener(messageSendingMutex);
        transport.addTransportListener(transListener);
        transport.connect();
        log.info("Sending " + mimePackage.getDescription());
        transport.sendMessage(mimePackage.getMimeMessage(), extractAllRecipients(mimePackage));
        synchronized (messageSendingMutex) {
            /*
                 * Wait some time for message delivery.
                 *
                 * We are either notified by the mail transport listener when the send has finished(successfully or not)
                 * or we have reached the wait timeout
                 */
            messageSendingMutex.wait(configurator.getMailTimeout());
        }
        messageDeliveryState = transListener.getDeliveryState();
        transport.close();
        transport.removeTransportListener(transListener);
    } catch (MessagingException e) {
        throw new ActionException("Could not send package", e);
    } catch (InterruptedException e) {
        throw new ActionException("Could not send package", e);
    }
    // evaluate the mail send result
    if (messageDeliveryState == DELIVERY_STATE.DELIVERED) {
        log.info(mimePackage.getDescription() + " " + messageDeliveryState);
    } else {
        throw new ActionException("Result of sending " + mimePackage.getDescription() + ": " + messageDeliveryState.toString());
    }
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) WrongPackageException(com.axway.ats.action.objects.model.WrongPackageException) MessagingException(javax.mail.MessagingException) MailTransportListener(com.axway.ats.action.mail.model.MailTransportListener) ActionException(com.axway.ats.action.model.ActionException) DELIVERY_STATE(com.axway.ats.action.mail.model.MailTransportListener.DELIVERY_STATE) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

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