【问题标题】:Java EWS- how to identify if attachment is sender signature imageJava EWS-如何识别附件是否是发件人签名图像
【发布时间】:2017-03-17 17:27:56
【问题描述】:

我需要确定附件是否是发件人的签名图像并忽略它,因为我想跳过此类附件,但我无法确定该特定附件是否是签名图像。

或者用户可以在添加签名图像的同时添加自定义属性,以便我可以在程序中查找该属性?

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
}

}

【问题讨论】:

    标签: java outlook exchangewebservices ewsjavaapi


    【解决方案1】:

    我想出了一个办法。运行代码一次,确定要忽略的附件的哈希,然后制作此哈希的本地字符串。然后,您处理的每个附件,将其与此本地哈希字符串进行比较,如果它们匹配,您可以忽略它并移至下一个(如果您像我一样在循环中处理附件)。

                // 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;
                }
    

    【讨论】:

      猜你喜欢
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 2017-05-07
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多