I have many .msg files which has encrypted attachment. I currently use apache poi library. Currently, I have code that giving a path of a .docx, .xls, .xlsx file, I can have the decrypted content. The problem is I want to get the attachment of msg file decrypted.
public static void decryptMSG(String path,String[] password) throws IOException {
MAPIMessage msg = new MAPIMessage(path);
AttachmentChunks attachments[] = msg.getAttachmentFiles();
if(attachments.length > 0) {
for (AttachmentChunks a : attachments) {
String attachname=a.attachLongFileName.toString();
ByteArrayInputStream fileIn = new ByteArrayInputStream(a.attachData.getValue());
File f = new File(path+"_decrypted"+ a.attachLongFileName.toString()); // output
OutputStream fileOut = null;
try {
fileOut = new FileOutputStream(f);
byte[] buffer = new byte[2048];
int bNum = fileIn.read(buffer);
while(bNum > 0) {
fileOut.write(buffer);
bNum = fileIn.read(buffer);
}
}
finally{
.....
}
This is the normal code to read .msg attachments which are not encrypted.
Q1: could sb kindly tell me where I can set the password?
Q2: if it's not support by the library to set the password, is it possible to copy the AttachmentChunks to a path? I mean give each Attachmentchunk a physical path where the Attachemntchunk is stored?
Q3: or if you know any lib in java or python could solve decrypting .msg file, please tell me. Thanks,