use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class MimePackage method addAttachment.
/**
* Add an attachment with the specified content - the attachment will have a
* content type text\plain and the specified character set
*
* @param content
* the content of the attachment
* @param charset
* the character set
* @param fileName
* the file name for the content-disposition header
* @throws PackageException
* on error
*/
@PublicAtsApi
public void addAttachment(String content, String charset, String fileName) throws PackageException {
try {
// add attachment to multipart content
MimeBodyPart attPart = new MimeBodyPart();
attPart.setText(content, charset, PART_TYPE_TEXT_PLAIN);
attPart.setDisposition(MimeBodyPart.ATTACHMENT);
attPart.setFileName(fileName);
addPart(attPart, PART_POSITION_LAST);
} 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 setPriority.
/**
* Set the message priority
*
* @param priority
* @throws PackageException
*/
@PublicAtsApi
public void setPriority(PackagePriority priority) throws PackageException {
try {
// set the priority
message.setHeader("X-Priority", String.valueOf(priority.toInt()));
// set MS Outlook display-priority header
message.setHeader("Importance", priority.toString());
} 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 getAttachmentContentType.
/**
* Get the attachment content type
*
* @param partIndex
* @return
* @throws PackageException
*/
@PublicAtsApi
public String getAttachmentContentType(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 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 setSubject.
/**
* Set the message subject
*
* @param subject
* @param charset
* @throws PackageException
*/
@PublicAtsApi
public void setSubject(String subject, String charset) throws PackageException {
try {
message.setSubject(subject, charset);
subjectCharset = charset;
} 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 getFirstBody.
/**
* Get the content of the first part with the specified content type
* <br>If this is a multipart message, we search only into the first nested level.
*
* @return the contents (body) of the first part with given content type.
* Null if such is not found in current or the direct sub-level
* @throws PackageException
*/
@PublicAtsApi
private String getFirstBody(String contentType) throws PackageException {
String textBody = null;
boolean storeReconnected;
try {
String messageContentType = message.getContentType().toLowerCase();
String contentDisposition = null;
storeReconnected = reconnectStoreIfClosed();
try {
if (messageContentType.startsWith(contentType)) {
contentDisposition = message.getDisposition();
if (!Part.ATTACHMENT.equalsIgnoreCase(contentDisposition)) {
// this is a plain text message
textBody = message.getContent().toString();
}
} else {
Object content = message.getContent();
if (content instanceof Multipart) {
// a multi-part message
Multipart parts = (Multipart) message.getContent();
// first look on top level
for (int i = 0; i < parts.getCount(); i++) {
BodyPart mimePart = parts.getBodyPart(i);
if (!(mimePart.getContent() instanceof Multipart)) {
textBody = getBodyIfNotAttachment(mimePart, contentType);
if (textBody != null) {
break;
}
}
}
if (textBody == null) {
// not found on top level - look multipart entries
for (int i = 0; i < parts.getCount(); i++) {
BodyPart mimePart = parts.getBodyPart(i);
if (mimePart.getContent() instanceof Multipart) {
Multipart nestedParts = (Multipart) mimePart.getContent();
for (int m = 0; m < nestedParts.getCount(); m++) {
BodyPart nestedMimePart = nestedParts.getBodyPart(m);
textBody = getBodyIfNotAttachment(nestedMimePart, contentType);
if (textBody != null) {
break;
}
}
}
if (textBody != null) {
break;
}
}
}
}
}
} finally {
closeStoreConnection(storeReconnected);
}
return textBody;
} catch (MessagingException e) {
throw new PackageException(e);
} catch (IOException e) {
throw new PackageException(e);
}
}
Aggregations