String disposition = part.getDisposition();
if (disposition != null && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE))) {
// by SPEC, we should only save those parts whose disposition is "attachment" or "inline".
// disposition == null means that it is a content part (message body, readable content)
CvFileVO attachment = new CvFileVO();
String filename = (part.getFileName() != null) ? (String)part.getFileName() : "Part-" + i;
// prepend human readable date to the fileName. This is for uniqueness.
SimpleDateFormat df = new SimpleDateFormat("MMMM_dd_yyyy_hh_mm_ss_S");
String prependDate = df.format(new Date());
attachment.setName(prependDate + "-" + filename);
attachment.setTitle(filename);
attachment.setOwner(ownerID);
attachment.setAuthorId(ownerID);
attachment.setCreatedBy(ownerID);
attachment.setDescription("Email Attachment: " + filename);
attachment.setPhysical(CvFileVO.FP_PHYSICAL);
if (attachment.getTitle() == null || (attachment.getTitle()).length() <= 0) {
// this is not good, and we should never reach this point, because I
// have added some fail-proof default content for filename above
return -1;
}
int newFileID = fileFacade.addFile(ownerID, attachmentFolderID, attachment, part.getInputStream(), this.dataSource);
if (newFileID > 0) {
cvdal.clearParameters();
cvdal.setInt(1, messageID);
cvdal.setString(2, attachment.getTitle());
cvdal.setInt(3, newFileID);
int rowsAffected = cvdal.executeUpdate();
}
numberOfAttachments++;
}else if(contentType != null && contentType.toLowerCase().indexOf("rfc822") > -1){
// The attachment is itself an rfc822 message. Therefore, we need to
// create a new MailMessage object, and process all its parts too
this.saveAttachments(this.getPartContent(part), messageID, accountID, ownerID, attachmentFolderID, cvdal, embededImageMap);
} else if (contentType != null && (contentType.length() >= 10) && ((contentType.toLowerCase().substring(0, 10)).indexOf("image") != -1)) {
// The attachment is itself an rfc2387 message. Therefore, we need to
// create a new MailMessage object, and process all the embeded image parts too
CvFileVO attachment = new CvFileVO();
String contentID = null;
String partContentID[] = part.getHeader("Content-ID");
if(partContentID != null && partContentID.length != 0){
contentID = partContentID[0];
}
String filename = (part.getFileName() != null) ? (String)part.getFileName() : "Part-" + i;
// prepend human readable date to the fileName. This is for uniqueness.
SimpleDateFormat df = new SimpleDateFormat("MMMM_dd_yyyy_hh_mm_ss_S");
String prependDate = df.format(new Date());
String storedFileName = prependDate + "-" + filename;
attachment.setName(storedFileName);
attachment.setTitle(filename);
attachment.setOwner(ownerID);
attachment.setAuthorId(ownerID);
attachment.setCreatedBy(ownerID);
attachment.setDescription("Email Attachment: " + filename);
attachment.setPhysical(CvFileVO.FP_PHYSICAL);
if (attachment.getTitle() == null || (attachment.getTitle()).length() <= 0) {
// this is not good, and we should never reach this point, because I
// have added some fail-proof default content for filename above
return -1;
}