2016-09-20 7 views
0

인라인/임베디드 이미지가 포함 된 이메일을 주로 읽습니다. 주로 보낸 사람 서명 이미지입니다. 하지만 email.hasAttachments()가 false를 반환하는지 확인하려고 할 때 검사 할 경우 email.getAttachments(); 그것은 인라인 첨부 파일을 보여줍니다. 여기에 내 코드가 있는데, 나는 잘못된 것을하고있다.EWS Java - hasAttachments가 인라인/임베디드 첨부 파일에 대해 false를 반환합니다.

try { 
     Item itm = Item.bind(service, itemId, new PropertySet(
       BasePropertySet.FirstClassProperties, 
       ItemSchema.Attachments,ItemSchema.HasAttachments, 
       ItemSchema.extendedProperties)); 

     emailMessage = EmailMessage.bind(service, itm.getId(), 
       new PropertySet(BasePropertySet.FirstClassProperties, 
         EmailMessageSchema.Attachments, EmailMessageSchema.HasAttachments)); 

     log.info(From: " + emailMessage.getFrom()); 
     log.info(Subject: " + emailMessage.getSubject()); 
     log.info(Received: " + emailMessage.getDateTimeReceived()); 

     //get email attachments. 
     attachments = getEmailAttachments(emailMessage, properties); 
    } 

    //getEmailAttachments() method. 
    try { 
     //check if the email has attachments. 

     if (emailMessage.getHasAttachments()) { //returns false here 
      //get all the attachments 
      AttachmentCollection attachmentsCol = emailMessage.getAttachments();// will return the attachments 
      log.info("File Count: " +attachmentsCol.getCount()); 
      //loop over the attachments 
      for (int i = 0; i < attachmentsCol.getCount(); i++) { 
       Attachment attchment = attachmentsCol.getPropertyAtIndex(i); 

       if (attchment.getIsInline()) { 
        log.info("There is an inline attachment."); 
       } 
       //FileAttachment - Represents a file that is attached to an email item 
       if (attchment instanceof FileAttachment) { 
        //my code here 
       } else if (attchment instanceof ItemAttachment) { //ItemAttachment - Represents an Exchange item that is attached to another Exchange item. 
        //my code here 
       } 
      } 

답변

2

HasAttachments는 다른 소품을 기반으로하는 계산 된 속성입니다. Outlook이 설정할 수있는 속성 중 하나는 메시지에 서명과 같은 인라인 첨부 파일이 있고 실제 첨부 파일이없는 Outlook에서 Paperclip을 효과적으로 숨기는 SmartNoAttach 속성 (Mapi 편집기에서이 소품의 값을 볼 수 있음)입니다. 하지만 EWS의 속성 값에도 영향을 미칩니다.

+1

고마워 글렌, 추가 체크를 추가하여 문제를 해결했습니다. if (emailMessage.getHasAttachments() || emailMessage.getAttachments(). getItems(). size()> 0) { – Lucky

+0

@ 완벽하게이 기능이 저에게 도움이되었습니다! 감사합니다 – Jake

+0

@ 제이크 - 듣기 좋게. – Lucky