try {
int multipartCount = multipart.getCount();
// Debug.logInfo(currentIndex + "====number of attachments: " + multipartCount, module);
for (int i=0; i < multipartCount; i++) {
// Debug.logInfo(currentIndex + "====processing attachment: " + i, module);
Part part = multipart.getBodyPart(i);
String thisContentTypeRaw = part.getContentType();
// Debug.logInfo("====thisContentTypeRaw: " + thisContentTypeRaw, module);
int idx2 = thisContentTypeRaw.indexOf(";");
if (idx2 == -1) idx2 = thisContentTypeRaw.length();
String thisContentType = thisContentTypeRaw.substring(0, idx2);
String disposition = part.getDisposition();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (part instanceof Multipart) {
currentIndex = currentIndex.concat("." + i);
// Debug.logInfo("=====attachment contain attachment, index:" + currentIndex, module);
return addMultipartAttachementToComm((Multipart) part.getContent(), commEventMap, subject, dispatcher, userLogin);
}
// Debug.logInfo("=====attachment not contains attachment, index:" + currentIndex, module);
// Debug.logInfo("=====check for currentIndex(" + currentIndex + ") against master contentIndex(" + EmailServices.contentIndex + ")", module);
if (currentIndex.concat("." + i).equals(CommunicationEventServices.contentIndex)) continue;
// The first test should not pass, because if it exists, it should be the bodyContentIndex part
// Debug.logInfo("====check for disposition: " + disposition + " contentType: '" + thisContentType + "' variable i:" + i, module);
if ((disposition == null && thisContentType.startsWith("text"))
|| ((disposition != null)
&& (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))
) )
{
String attFileName = part.getFileName();
Debug.logInfo("===processing attachment: " + attFileName, module);
if (!UtilValidate.isEmpty(attFileName)) {
commEventMap.put("contentName", attFileName);
commEventMap.put("description", subject + "-" + attachmentCount);
} else {
commEventMap.put("contentName", subject + "-" + attachmentCount);
}
commEventMap.put("drMimeTypeId", thisContentType);
if (thisContentType.startsWith("text")) {
String content = (String)part.getContent();
commEventMap.put("drDataResourceTypeId", "ELECTRONIC_TEXT");
commEventMap.put("textData", content);
} else {
InputStream is = part.getInputStream();
int c;
while ((c = is.read()) > -1) {
baos.write(c);
}
ByteBuffer imageData = ByteBuffer.wrap(baos.toByteArray());
int len = imageData.limit();
if (Debug.infoOn()) Debug.logInfo("imageData length: " + len, module);
commEventMap.put("drDataResourceName", part.getFileName());
commEventMap.put("imageData", imageData);
commEventMap.put("drDataResourceTypeId", "IMAGE_OBJECT");
commEventMap.put("_imageData_contentType", thisContentType);
}
dispatcher.runSync("createCommContentDataResource", commEventMap);