2017-12-11 1 views
4

인트라넷 사용자가 ColdFusion 사이트의 div에 파일을 드래그 앤 드롭 할 수있는 시스템을 구축 중입니다. 일부 시스템에서는 파일을 자동으로 파일 서버에 업로드합니다. 내 요구 사항 중 하나는 업로드 된 파일이 .msg 파일 (Outlook 전자 메일) 인 경우 해당 전자 메일의 첨부 파일을 추출하고 개별적으로 업로드하는 것입니다. 이는 org.apache.poi.hsmf.MAPIMessage Java 오브젝트를 사용하여 가능합니다. 다음 코드를 사용하여 나열된 각 첨부 파일 객체를 볼 수 있습니다. 그런 다음 파일 이름과 확장자를 가져 와서 각각을 로컬 파일 시스템에 저장할 수 있습니다.ColdFusion을 사용하여 Outlook .msg 파일에서 첨부 파일을 추출합니다.

그러나 첨부 파일이 다른 .msg 파일 인 경우에는 작동하지 않습니다. 첨부 된 .msg 파일에 getEmbeddedAttachmentObject()을 호출하면 "undefined"만 포함 된 개체가 반환됩니다. 비 .msg 파일은 FileWrite() ColdFusion 함수로 전달할 수있는 이진 객체를 반환합니다. MAPIMessage 오브젝트의 추가 검사는이 write() 방법을 가지고 있음을 보여 주지만, 전화에 나는라는 오류 얻을 :

주 - 쓰기는 아직 죄송합니다,이 파일 형식이 지원되지 않습니다.

이 내용은 http://poi.apache.org 설명서에도 백업되어 있습니다.

요약하면 첨부 파일이 다른 전자 메일 메시지가 아니라면 첨부 파일 시스템에 문제없이 첨부 할 수 있습니다. 나는 운이 없습니까? 아니면 이것을 수행 할 또 다른 방법이 있습니까?

<cfscript> 
    // Load test .msg into MAPIMessage object 
    MAPIMessage = createObject("java", "org.apache.poi.hsmf.MAPIMessage"); 
    message = MAPIMessage.init('C:\Test\Test Email 1 Attachment.msg'); 

    // Get array of attached files 
    attachments = message.getAttachmentFiles(); 

    // If attachments were found 
    if(arrayLen(attachments) > 0) { 

    // Loop over each attachment 
    for (i=1; i LTE arrayLen(attachments); i++) { 

     // Dump the current attachment object 
     writeDump(attachments[i]); 

     // Get current attachment's binary data 
     local.data=attachments[i].getEmbeddedAttachmentObject(); 

     // Dump binary data 
     writeDump(local.data); 

     // Get attachment's filename and extension 
     attachmentFileName = attachments[i].attachLongFileName.toString(); 
     attachmentExtension = attachments[i].attachExtension.toString(); 

     // Dump filename and extension 
     writeDump(attachmentFileName); 
     writeDump(attachmentExtension); 

     // Write attachment to local file system  
FileWrite("#expandPath('/')##attachments[i].attachLongFileName.toString()#", local.data); 

    } 
    } 
</cfscript> 

답변

0

많은 연구 끝에 내 문제에 대한 해결책을 찾았습니다. 아직 구현되지 않은 write() 메서드로 인해 ColdFusion과 함께 제공되는 org.apache.poi.hsmf.MAPIMessage Java 객체를 사용하여 포함 된 msg 파일을 저장할 수 없습니다. 대신, 제 3 자 도구 인 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 
관련 문제