Search in sources :

Example 1 with PackageHeader

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

the class MimePackage method getAllHeaders.

@SuppressWarnings("unchecked")
@PublicAtsApi
public List<PackageHeader> getAllHeaders() throws PackageException {
    try {
        List<PackageHeader> headers = new ArrayList<PackageHeader>();
        Enumeration<Header> messageHeaders = message.getAllHeaders();
        while (messageHeaders.hasMoreElements()) {
            Header messageHeader = messageHeaders.nextElement();
            headers.add(new PackageHeader(messageHeader.getName(), messageHeader.getValue()));
        }
        return headers;
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : Header(javax.mail.Header) PackageHeader(com.axway.ats.action.objects.model.PackageHeader) MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) PackageHeader(com.axway.ats.action.objects.model.PackageHeader) 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 PackageHeader

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

Aggregations

PackageHeader (com.axway.ats.action.objects.model.PackageHeader)2 BaseTest (com.axway.ats.action.BaseTest)1 MimePackage (com.axway.ats.action.objects.MimePackage)1 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)1 PackageException (com.axway.ats.action.objects.model.PackageException)1 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 ArrayList (java.util.ArrayList)1 Header (javax.mail.Header)1 MessagingException (javax.mail.MessagingException)1 MimePart (javax.mail.internet.MimePart)1 Test (org.junit.Test)1