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);
}
}
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());
}
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);
}
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));
}
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());
}
}
Aggregations