التعرف على المرفق المدمج واستخراجه من ملف MSG بتنسيق RTF
Contents
[
Hide
]
قد تحتوي رسائل البريد الإلكتروني التي تحتوي على نص بتنسيق RTF على مرفقات مضمّنة إما ككائن كامل أو كأيقونة. للتمييز بين هذين النوعين من المرفقات، يجب فحص بعض خصائص المرفق أولاً. بعد استيفاء معايير معينة بناءً على خصائص المرفق، يمكن حفظ المرفق عن طريق استخراجه من ObjectData الخاص به.
تحدد هذه المقالة وتستخرج المرفق المدمج من ملف MSG بتنسيق RTF.
Java
static void ExtractInlineAttachments()
{
MapiMessage message = MapiMessage.fromFile("Test.msg");
MapiAttachmentCollection attachments = message.getAttachments();
for (Object untypedAttachment : attachments)
{
MapiAttachment attachment = (MapiAttachment) untypedAttachment;
if(IsAttachmentInline(attachment))
{
try
{
SaveAttachment(attachment, UUID.randomUUID().toString());
}
catch (IOException | FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
static boolean IsAttachmentInline(MapiAttachment attachment)
{
MapiObjectProperty objectData = attachment.getObjectData();
if (objectData == null)
return false;
for (Object prop : attachment.getObjectData().getProperties().getValues())
{
MapiProperty property = (MapiProperty)prop;
if ("\u0003ObjInfo".equals(property.getName()))
{
byte[] data = property.getData();
int odtPersist1 = data[1] << 8 | data[0];
return (odtPersist1 & 0x40) == 0;
}
}
return false;
}
static void SaveAttachment(MapiAttachment attachment, String fileName) throws IOException, FileNotFoundException
{
for (Object prop : attachment.getObjectData().getProperties().getValues())
{
MapiProperty property = (MapiProperty)prop;
if ("Package".equals(property.getName()))
{
FileOutputStream fs;
try
{
fs = new FileOutputStream(fileName);
fs.write(property.getData(), 0, property.getData().length);
}
catch (java.io.IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}