use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class MimePackage method getAttachmentCharset.
/**
* Get the attachment character set
*
* @param partIndex
* the index of the attachment
* @return the character set for this attachment, null if there is no such
* @throws PackageException
*/
@PublicAtsApi
public String getAttachmentCharset(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.getParameter("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 addAttachmentDir.
/**
* Appends all files in a specified folder as attachments
*
* @param folder the folder containing all files to be attached
* @throws PackageException
*/
@PublicAtsApi
public void addAttachmentDir(String folder) throws PackageException {
// fetch list of files in specified directory
File dir = new File(folder);
File[] list = dir.listFiles();
if (null == list) {
throw new PackageException("Could not read from directory '" + folder + "'.");
} else {
// process all files, skipping directories
for (int i = 0; i < list.length; i++) {
if ((null != list[i]) && (!list[i].isDirectory())) {
// add attachment to multipart content
MimeBodyPart attPart = new MimeBodyPart();
FileDataSource ds = new FileDataSource(list[i].getPath());
try {
attPart.setDataHandler(new DataHandler(ds));
attPart.setDisposition(MimeBodyPart.ATTACHMENT);
attPart.setFileName(ds.getName());
} catch (MessagingException me) {
throw new PackageException(me);
}
addPart(attPart, PART_POSITION_LAST);
}
}
}
}
use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class MimePackage method tag.
/**
* Tagging the message by adding "Automation-Message-Tag" header with the current time value(in milliseconds).
* This is useful if want to recognize this message between others in the same IMAP folder.
* *
* @throws ActionException
*/
@PublicAtsApi
public void tag() throws ActionException {
// we use the message's sent time as a unique tag
String tagValue = Long.toString(Calendar.getInstance().getTimeInMillis());
try {
setHeader("Automation-Message-Tag", tagValue);
// if everything is OK, then this is our tag
tag = tagValue;
log.info(getDescription() + " tagged with tag '" + tag + "'");
} catch (PackageException e) {
throw new ObjectCannotBeTaggedException(getDescription(), null, e);
}
}
use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class MimePackage method getPartHeaderValues.
/**
* Get all header values from a specified MIME part
*
* @param headerName
* @param partNum
* @return
* @throws PackageException
*/
@PublicAtsApi
public String[] getPartHeaderValues(String headerName, int partNum) throws PackageException {
try {
String[] headers;
if (partNum >= parts.size()) {
throw new NoSuchMimePartException("No MIME part at position '" + partNum + "'");
}
MimePart part = parts.get(partNum);
headers = part.getHeader(headerName);
if ((headers != null) && (headers.length > 0)) {
return headers;
} else {
throw new NoSuchHeaderException(headerName, partNum);
}
} 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 getSenderAddress.
/**
* This method resturns only the email address portion of the sender
* contained in the first From header
*
* @return the sender address
* @throws PackageException
*/
@PublicAtsApi
public String getSenderAddress() throws PackageException {
try {
Address[] fromAddresses = message.getFrom();
if (fromAddresses == null || fromAddresses.length == 0) {
throw new PackageException("Sender not present");
}
InternetAddress fromAddress = (InternetAddress) fromAddresses[0];
return fromAddress.getAddress();
} catch (MessagingException me) {
throw new PackageException(me);
}
}
Aggregations