I'm trying to validate the attachment is password protected or not, is there a property that I can check. I don't want to process the attachment if it's password protected.
Below is the code I tried:
FileAttachment fileAttachment = (FileAttachment) attachment;
// if we don't call this, the Content property may be null.
fileAttachment.load();
// I was hoping this should not give me content of the file if it's password protected
attachmentContent = fileAttachment.getContent(); //but I get the content without error.
if (attachmentContent != null && attachmentContent.length > 0) {
//check the size, I get the length as well
int attachmentSize = attachmentContent.length;
Again I check if I can Decode the content, I get the decoded content as well.
byte[] decodedFile;
try {
String base64Encoded = Base64.encodeBase64String(attachmentContent);
decodedFile = Base64.decodeBase64(base64Encoded);
} catch (Exception e) {
throw e);
}