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
}

}

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

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

最新更新