use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class MimePackage method getRegularPartContentType.
/**
* Get the content type of a regular part
*
* @param partIndex
* the index of the regular part
* @return the content type as string
* @throws PackageException
*/
@PublicAtsApi
public String getRegularPartContentType(int partIndex) throws PackageException {
// first check if there is part at this position at all
if (partIndex >= regularPartIndices.size()) {
throw new NoSuchMimePartException("No regular part at position '" + partIndex + "'");
}
try {
MimePart part = getPart(regularPartIndices.get(partIndex));
// get the content type header
ContentType contentType = new ContentType(part.getContentType());
return contentType.getBaseType();
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class MimePackage method setRecipient.
/**
* Set the specified type of recipients of a mime package
*
* @param type the recipients' type
* @param address the email addresses of the recipients
* @throws PackageException
*/
@PublicAtsApi
public void setRecipient(RecipientType type, String[] addresses) throws PackageException {
try {
// add the recipient
InternetAddress[] address = new InternetAddress[addresses.length];
for (int i = 0; i < addresses.length; i++) address[i] = new InternetAddress(addresses[i]);
message.setRecipients(type.toJavamailType(), address);
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class MimePackage method addPart.
private void addPart(BodyPart part, int position) throws NoSuchMimePartException, PackageException {
try {
Object messageContent = message.getContent();
if (messageContent instanceof MimeMultipart) {
MimeMultipart multipartContent = (MimeMultipart) messageContent;
int positionToInsertAt = position;
if (position > multipartContent.getCount()) {
positionToInsertAt = multipartContent.getCount();
}
multipartContent.addBodyPart(part, positionToInsertAt);
// set back the modified content
message.setContent(multipartContent);
// decomposing
try {
message.saveChanges();
} catch (MessagingException me) {
throw new PackageException("Could not save message changes", me);
}
// we need to decompose again, as a new part has been added
decompose();
} else {
// TODO: we can transform the part to MimeMultipart if desired
throw new PackageException("Message is not multipart!");
}
} catch (MessagingException me) {
throw new PackageException(me);
} catch (IOException ioe) {
throw new PackageException(ioe);
}
}
use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class MimePackage method setRecipient.
/**
* Set the To recipient of a mime package, the CC and BCC recipients are
* cleared
*
* @param address the email address of the recipient
* @throws PackageException
*/
@PublicAtsApi
public void setRecipient(String address) throws PackageException {
try {
// add the recipient
InternetAddress inetAddress = new InternetAddress(address);
message.setRecipients(javax.mail.internet.MimeMessage.RecipientType.TO, new InternetAddress[] { inetAddress });
message.setRecipients(javax.mail.internet.MimeMessage.RecipientType.CC, new InternetAddress[] {});
message.setRecipients(javax.mail.internet.MimeMessage.RecipientType.BCC, new InternetAddress[] {});
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class MimePackage method getAttachmentFileName.
/**
* Get an attachment's file name
*
* @param partIndex
* @return
* @throws PackageException
*/
@PublicAtsApi
public String getAttachmentFileName(int partIndex) throws PackageException {
// first check if there is part at this position at all
if (partIndex >= attachmentPartIndices.size()) {
throw new NoSuchMimePartException("No attachment at position '" + partIndex + "'");
}
try {
MimePart part = getPart(attachmentPartIndices.get(partIndex));
// get the attachment file name
String fileName = part.getFileName();
if (fileName == null) {
throw new PackageException("Could not determine file name for attachment at position " + partIndex);
}
return fileName;
} catch (MessagingException me) {
throw new PackageException(me);
}
}
Aggregations