public void addAttachments(final MIMEEntity parent) {
try {
Stream streamFile = null;
for (IEmailAttachment attach : getAttachments()) {
InputStream is = null;
EmbeddedObject eo = null;
String fileName = attach.getFileName();
// Get content type
String contentType = URLConnection.guessContentTypeFromName(fileName);
if (null == contentType) {
contentType = "application/octet-stream";
}
int idex = StringUtil.indexOfIgnoreCase(fileName, ".", fileName.length() - 6);
if (idex > -1) {
String extension = fileName.substring(idex);
if (StringUtil.equals("gif", extension)) {
contentType = "image/gif";
} else if (StringUtil.equals("jpg", extension) || StringUtil.equals("jpeg", extension)) {
contentType = "image/jpeg";
} else if (StringUtil.equals("png", extension)) {
contentType = "image/png";
}
}
contentType += "; name=\"" + fileName + "\"";
try {
Type attachmentType = attach.getAttachmentType();
if (attachmentType == Type.DOCUMENT) {
//retrieve the document containing the attachment to send from the relevant
Database dbFile = getSession().getDatabase(getSession().getServerName(), attach.getDbPath());
Document docFile = dbFile.getDocumentByUNID(attach.getUnid());
if (null != docFile) {
eo = docFile.getAttachment(attach.getFileName());
is = eo.getInputStream();
}
} else if (attachmentType == Type.FILE) {
is = new FileInputStream(attach.getPath() + attach.getFileName());
} else if (attachmentType == Type.STREAM) {
is = attach.getInputStream();