I am creating a system where intranet users are allowed to drag and drop files into div
our ColdFusion website, which after some verification will automatically upload them to the file server. One of my requirements: when the downloaded file is a file .msg
(Outlook Email), extract any files that are attachments to this email and download them separately. This is possible using a org.apache.poi.hsmf.MAPIMessage
Java object . Following the code below, I can see how each of the listed objects is attached. Then I can get their names and extensions and save them to the local file system.
However, this does not work if the attachment is a different file .msg
. When I call getEmbeddedAttachmentObject()
in the attached file .msg
, it returns an object that contains only "undefined". Files .msg
return a binary object that I can then pass to the FileWrite()
ColdFusion function . Further examination of the object MAPIMessage
shows that it has a method write()
, but after calling it, I get an error message:
Note. Recording on this file is not yet supported.
This is confirmed by the documentation at http://poi.apache.org .
To summarize, I can write each attachment of an electronic message to the file system without problems if the attachment is not another electronic message. Am I lucky or is there another way to do this?
<cfscript>
MAPIMessage = createObject("java", "org.apache.poi.hsmf.MAPIMessage");
message = MAPIMessage.init('C:\Test\Test Email 1 Attachment.msg');
attachments = message.getAttachmentFiles();
if(arrayLen(attachments) > 0) {
for (i=1; i LTE arrayLen(attachments); i++) {
writeDump( attachments[i] );
local.data=attachments[i].getEmbeddedAttachmentObject();
writeDump( local.data );
attachmentFileName = attachments[i].attachLongFileName.toString();
attachmentExtension = attachments[i].attachExtension.toString();
writeDump( attachmentFileName );
writeDump( attachmentExtension );
FileWrite("#expandPath('/')##attachments[i].attachLongFileName.toString()#", local.data);
}
}
</cfscript>