RTF olarak biçimlendirilmiş MSG dosyasından Gömülü Eki Tanımlama ve Çıkarma
Contents
[
Hide
]
RTF biçiminde gövdeye sahip e-posta mesajları, tüm nesne olarak ya da bir simge olarak gömülmüş satır içi ekler içerebilir. Bu iki ek tipini ayırt edebilmek için, ekin bazı özellikleri öncelikle incelenmelidir. Ek özelliklerine dayalı belirli kriterler karşılandıktan sonra, ek ObjectData’sından çıkarılarak kaydedilebilir.
Bu makale, RTF biçiminde formatlanmış MSG dosyasından gömülü eki tanımlar ve çıkarır.
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();
}
}
}
}