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);
}
}
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++;
}
*/
}
Aggregations