0

I need to identify if an attachment is signature image of the sender and ignore it as I want to skip that kind of attachments, but I'm not able to identify if that particular attachment is signature image.

Or can a user add a custom property while adding the signature image, so I can look for that property in the program?

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
}

}

Lucky
  • 783
  • 2
  • 10
  • 28

1 Answers1

0

I figured out a way to do this. Run the code once, determine a hash of the attachment you want to ignore and then make a local string of this hash. Then, each attachment you process, compare it to this local hash string and if they match, you can just ignore it and move to the next (if you are processing attachments in a loop like I am).

            // 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;
            }
paul
  • 135
  • 1
  • 10