Attachment[] attachments = ((MessageExchange) result).getResponseAttachments();
if (attachments != null && attachments.length > 0) {
for (int c = 0; c < attachments.length; c++) {
fileName = nameBase + "-attachment-" + (c + 1) + ".";
Attachment attachment = attachments[c];
String contentType = attachment.getContentType();
if (!"application/octet-stream".equals(contentType) && contentType != null
&& contentType.indexOf('/') != -1) {
fileName += contentType.substring(contentType.lastIndexOf('/') + 1);
} else {
fileName += "dat";
}
fileName = absoluteOutputFolder + File.separator + fileName;
FileOutputStream outFile = new FileOutputStream(fileName);
Tools.writeAll(outFile, attachment.getInputStream());
outFile.close();
}
}
}