java的msg用法_java – 使用ColdFusion从Outlook .msg文件中提取附件

经过大量研究后,我找到了解决问题的方法.由于尚未实现的write()方法,我无法使用由ColdFusion附带的org.apache.poi.hsmf.MAPIMessage java对象保存嵌入的msg文件.相反,我使用了名为

Aspose.Email for Java的第三方工具

Aspose是一种付费产品,是我能够完成我需要做的唯一方式.

这是我的实施.这就是我需要的一切.

local.msgStruct.attachments = [];

// Create MapiMessage from the passed in .msg file

MapiMessage = createObject("java", "com.aspose.email.MapiMessage");

message = MapiMessage.fromFile(ARGUMENTS.msgFile);

// Get attachments

attachments = message.getAttachments();

numberOfAttachments = attachments.size();

// If attachments exist

if(numberOfAttachments > 0) {

// Loop over attachments

for ( i = 0; i LT numberOfAttachments; i++) {

// Get current Attachment

currentAttachment = attachments.get_Item(i);

// Create struct of attachment info

local.attachmentInfo = {};

local.attachmentInfo.fileName = currentAttachment.getLongFileName();

local.attachmentInfo.fileExtension = currentAttachment.getExtension();

// If an attachmentDestination was specified

if(ARGUMENTS.attachmentDestination NEQ ''){

// Ignore inline image attchments (mostly email signature images)

if( NOT (left(local.attachmentInfo.fileName, 6) EQ 'image0' AND local.attachmentInfo.fileExtension EQ '.jpg') ){

// Get attachment object data (only defined for Outlook Messages, will return undefined object for other attachment types)

attachmentObjectData = currentAttachment.getObjectData();

// Check if attachment is an outlook message

if( isDefined('attachmentObjectData') AND attachmentObjectData.isOutlookMessage()){

isAttachmentOutlookMessage = 'YES';

} else {

isAttachmentOutlookMessage = 'NO';

}

// ATTACHMENT IS AN EMAIL //

if( isAttachmentOutlookMessage ){

// Get attachment as a MapiMessage

messageAttachment = currentAttachment.getObjectData().toMapiMessage();

// If an attachmentDestination was specified

if(ARGUMENTS.attachmentDestination NEQ ''){

// Set file path

local.attachmentInfo.filePath = ARGUMENTS.attachmentDestination;

// Set file path and file name

local.attachmentInfo.filePathAndFileName = ARGUMENTS.attachmentDestination & local.attachmentInfo.fileName;

// Save attachment to filesystem

messageAttachment.save(local.attachmentInfo.filePathAndFileName);

}

// ATTACHMENT IS NOT AN EMAIL //

} else {

// If an attachment destination was specified

if(ARGUMENTS.attachmentDestination NEQ ''){

// Set file path

local.attachmentInfo.filePath = ARGUMENTS.attachmentDestination;

// Set file path and file name

local.attachmentInfo.filePathAndFileName = ARGUMENTS.attachmentDestination & local.attachmentInfo.fileName;

// Save attachment to filesystem

currentAttachment.save(local.attachmentInfo.filePathAndFileName);

}

}

// Verify that the file was saved to the file system

local.attachmentInfo.savedToFileSystem = fileExists(ARGUMENTS.attachmentDestination & local.attachmentInfo.fileName);

// Add attachment info struct to array

arrayAppend(local.msgStruct.attachments,local.attachmentInfo);

} // End ignore inline image attachments

} // End loop over attachments

} // End if attachments exist

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值