RTF के रूप में फॉर्मेट किए गए MSG से एम्बेडेड अटैचमेंट की पहचान और निष्कर्षण
Contents
[
Hide
]
RTF फॉर्मेटेड बॉडी वाले ईमेल संदेशों में इनलाइन अटैचमेंट हो सकते हैं जो या तो पूरे ऑब्जेक्ट के रूप में एम्बेडेड होते हैं या आइकन के रूप में। इन दो प्रकार के अटैचमेंट्स के बीच अंतर करने के लिए पहले अटैचमेंट की कुछ प्रॉपर्टी की जांच करनी होती है। अटैचमेंट प्रॉपर्टी के आधार पर कुछ मानदंडों को पूरा करने के बाद, अटैचमेंट को उसके ObjectData से निकालकर सहेजा जा सकता है।
यह लेख RTF फ़ॉर्मेट किए गए MSG फ़ाइल से एम्बेडेड अटैचमेंट की पहचान करता है और उसे निकालता है।
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();
}
}
}
}