Hi,
I have a requirement to remove all genuine attachments from .msg files in order to save the original email.
I need to detect inline images (embedded attachments) and not remove this from the original email as they are not genuine attachments. By inline images I mean things like email signatures and email footers etc.
I have been using the following code to detect inline images for .msg files however its not working for a particular sample file that I have attached to this post.
The picture at the bottom of the email (which comes as an email signature) is not being detected as an inline image, also its LongFileName is null. Please treat the attached sample file as confidential.
Following is the code that I am using to detect inline images as advised in https://forum.aspose.com/t/40704.
NOTE: I’m using Aspose Email for Java 2.8.0.
MapiMessage origMessage = MapiMessage.fromFile(“inline image test.msg”);
MapiAttachmentCollection attachments = origMessage.getAttachments();
int count = attachments.size();
System.out.println("Total attachments " + count);
for (int i = count - 1; i >= 0; --i)
{
MapiAttachment attachment = (MapiAttachment) attachments.get(i);
//check if attachment is inline
if (attachment.getMyProperties().contains(MapiPropertyTag.PR_ATTACHMENT_FLAGS) && attachment.getMyProperties().get(MapiPropertyTag.PR_ATTACHMENT_FLAGS).getInt32() == 8)
{
//Save inline/embedded attachments
System.out.println("Preserved " + attachment.getLongFileName());
}
else
{
//delete regular attachments
attachments.remove(attachment);
System.out.println("Deleted " + attachment.getLongFileName());
}
}
FileOutputStream fileOut = new FileOutputStream(“output.msg”);
origMessage.save(fileOut);
Regards,
CH