2017-03-17 15 views
0

添付ファイルが送信者の署名イメージであるかどうかを特定し、その種類の添付ファイルをスキップしたいので無視する必要があります。その特定の添付ファイルは署名画像です。Java EWS-添付ファイルが送信者の署名イメージであるかどうかを確認する方法

また、署名イメージを追加している間にユーザーがカスタムプロパティを追加できるので、そのプロパティをプログラムで探すことができますか?

if (emailMessage.getHasAttachments() || emailMessage.getAttachments().getItems().size() > 0) { 

//get all the attachments 
AttachmentCollection attachmentsCol = emailMessage.getAttachments(); 

log.info("File Count: " + attachmentsCol.getCount()); 

    Attachment attachment = attachmentsCol.getPropertyAtIndex(i); 
    //log.debug("Starting to process attachment "+ attachment.getName()); 

    //do we need to skip this attachment 

     FileAttachment fileAttachment = (FileAttachment) attachment; 
     // if we don't call this, the Content property may be null. 
     fileAttachment.load(); 
     booelan isSignatureImage = fileAttachment.isContactPhoto(); // this is false 
} 

}

答えて

0

私はこれを行う方法を考え出しました。コードを一度実行し、無視する添付ファイルのハッシュを決定し、このハッシュのローカル文字列を作成します。そして、処理している各添付ファイルをこのローカルハッシュ文字列と比較し、一致すればそれを無視して次のファイルに移動します(私のようにループ内の添付ファイルを処理している場合)。

  // you must first load your attachment to be able to call .getContent() on it 
      fileAttachment.load(); 

      // load content 
      byte[] b = fileAttachment.getContent(); 

      // get the hash of your attachment 
      byte[] hash = MessageDigest.getInstance("MD5").digest(b); 

      // after you run this on the attachment you do not want, take the string from 'actual' below and put it here 
      String expected = "YOUR HASHED STRING"; 

      String actual = DatatypeConverter.printHexBinary(hash); 
      System.out.println(actual); 

      // some conditional to check if your current hash matches expected 
      if(actual.equals(expected)){ 
       continue; 
      } 
関連する問題