use of javax.mail.MessagingException in project ats-framework by Axway.
the class MimePackage method getRegularPartCharset.
/**
* Get the character set of a regular part
*
* @param partIndex
* the index of the part
* @return the charset
* @throws PackageException
*/
@PublicAtsApi
public String getRegularPartCharset(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.getParameter("charset");
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of javax.mail.MessagingException 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 javax.mail.MessagingException in project ats-framework by Axway.
the class MimePackage method writeToFile.
/**
* Write the constructed MIME message to a file
*
* @param fileName
* the name of the file to write to
*
* @throws IOException
* @throws PackageException
*/
@PublicAtsApi
public void writeToFile(String fileName) throws IOException, PackageException {
FileOutputStream outStream = null;
boolean storeReconnected = false;
try {
storeReconnected = reconnectStoreIfClosed();
// store should be opened for actions including getting InputStream. Hence store open is not in getPart
outStream = new FileOutputStream(new File(fileName));
message.writeTo(outStream);
} catch (MessagingException me) {
throw new PackageException("Could not write message content", me);
} finally {
if (outStream != null) {
outStream.close();
}
try {
closeStoreConnection(storeReconnected);
} catch (MessagingException ex) {
log.warn("Error closing IMAP connection", ex);
}
}
}
use of javax.mail.MessagingException in project ats-framework by Axway.
the class MimePackage method getInternetHeaders.
private InternetHeaders getInternetHeaders(Object partContent) throws PackageException {
InternetHeaders internetHeaders = null;
if (partContent instanceof InputStream) {
try {
InputStream is = (InputStream) partContent;
internetHeaders = new InternetHeaders(is);
} catch (MessagingException e) {
// error converting to InternetHeaders
throw new PackageException("Error parsing internet headers with type rfc822-headers", e);
}
}
return internetHeaders;
}
use of javax.mail.MessagingException in project ats-framework by Axway.
the class MimePackage method getWholePackage.
@PublicAtsApi
public InputStream getWholePackage() throws PackageException {
boolean storeReconnected = false;
try {
storeReconnected = reconnectStoreIfClosed();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
message.writeTo(outStream);
return new ByteArrayInputStream(outStream.toByteArray());
} catch (MessagingException me) {
throw new PackageException("Could not write message content", me);
} catch (IOException ioe) {
throw new PackageException("Could not write message content", ioe);
} finally {
try {
closeStoreConnection(storeReconnected);
} catch (MessagingException ex) {
log.warn(ex);
}
}
}
Aggregations