Free Support Forum - aspose.com

How do I know Attachment is a msg/eml without its extension?

Hi,

How I can know attachment is msg/eml without the use of its extension property.

mapiMsg = MapiMessage.fromStream(inputStream);
final MapiAttachmentCollection collAttchmnt = mapiMsg.getAttachments();
logger.debug("[0MS001] Attachment Size : ["+collAttchmnt.size()+"]");

for (int temp = 0; temp < collAttchmnt.size(); temp++) {

final MapiAttachment attchmnt = (MapiAttachment) collAttchmnt
.get(temp);

//attchmnt object is type of eml/msg?

}




Thanks,

Hi sachin,


We are sorry for the delayed response.

We are analyzing the issue and will let you know soon about our findings.

Your patience and understanding is highly appreciated.

Hi Sachin,


I am afraid to inform that MapiMessage does not provide identification for attachments.

However if you load the mail message using MailMessage then attachment’s “media type” can be used the identify the MSG attachment. Media type contains string value “message/rfc822” for the MSG type attachments.

Please give a try to the following code and let us know your feedback.

MailMessage mailMsg = MailMessage.load(“SampleWithAttachments.msg”);
final AttachmentCollection collAttchmnt = mailMsg.getAttachments();
for (int temp = 0; temp < collAttchmnt.size(); temp++)
{
final Attachment attchmnt = (Attachment)collAttchmnt.get(temp);
if(attchmnt.getContentType().getMediaType().equals(“message/rfc822”))
{
System.out.print(“MSG file”);
}
else
{
System.out.print(“Not a MSG file”);
}
System.out.print(attchmnt.getName());
}