From Msg- embedded images are treating as a attachment by MapiMessage Api

Hi,

I am using MapiMessage api for getting attachment from MSG email

It is removing embedded icon as a attachment.
I am also attaching the sample mail

Please provide some solution for that.

Thanks.

Hi Sachin,

Thank you for writing to us.

Can you please explain to us what you actually want to mention by the following statement?
lucaro:

It is removing embedded icon as a attachment.

We will try to assist you as soon as possible.

Hi

When I get the attachment of the given mail

It is also giving me the embedded icon.

Thanks

Hi Sachin,


Thank you for the clarification.

While using MapiMessage, the inline images are also considered as attachments and will be part of the attachment collection. To ignore the inline images included in the attachments collection, please have a look at the following code for your reference. Please let us know if we can be of additional help to you.

JAVA Code Sample

MapiMessage mapi = MapiMessage.fromFile(“Untitled.msg”);

MapiAttachmentCollection attCol = mapi.getAttachments();

for (int i=0; i<attCol.size(); i++)
{
MapiAttachment attachment = (MapiAttachment)attCol.get(i);

//check if the attachment is some inline

if (attachment.getProperties().contains(MapiPropertyTag.PR_ATTACHMENT_FLAGS) && attachment.getProperties().get(MapiPropertyTag.PR_ATTACHMENT_FLAGS).getInt32() == 8)
{
System.out.println(“Inline attachment…Ignore it”);
}
else
{
//save the attachment as a regular attachment
}
}


Hi Kashif,

Your given code for getting embedded attachment is not working
I am also attaching the sample mail

Code used

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

final MapiAttachment attchmnt = (MapiAttachment) collAttchmnt
.get(temp);
//check if the attachment is some inline
if(attchmnt.getProperties().contains(MapiPropertyTag.PR_ATTACHMENT_FLAGS) &&attchmnt.getProperties().get(MapiPropertyTag.PR_ATTACHMENT_FLAGS).getInt32() == 8){
System.out.println(“Inline attachment…Ignore it”);
}else if (attchmnt.getProperties().contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID_A) ||attchmnt.getProperties().contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W)){
System.out.println(“Embedded attachment…”);
}else{

extractMore(attchmnt, request, level);
}

}

apart from this, I also want to remove only non embedded file from original mail

Please help…

Thanks,
luca

Hi Luca,

Thank you for notifying about the issue you are facing.

Please use the following method to determine the type of attachment in a message. It takes into account the Body type of the message and attachment flag to determine the type of attachment.

public static boolean IsInlineAttachment(MapiAttachment att, int messageBodyType)
{
    if (messageBodyType == BodyContentType.PlainText)
        // ignore indications for plain text messages
        return false;
    else if (messageBodyType == BodyContentType.Html)
    {
        // check the PidTagAttachFlags property
        if (att.getProperties().contains(0x37140003))
        {
            long attachFlagsValue = att.getPropertyLong(0x37140003);
            if ((attachFlagsValue & 0x00000004) == 0x00000004)
            {
                // check PidTagAttachContentId property
                if (att.getProperties().contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID) ||
                    att.getProperties().contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W))
                {
                    return true;
                }
                // check PidTagAttachContentLocation property
                if (att.getProperties().contains(0x3713001E) ||
                    att.getProperties().contains(0x3713001F))
                {
                    return true;
                }
            }
        }
        return false;
    }
    else if (messageBodyType == BodyContentType.Rtf)
    {
        // If the body is RTF, then all OLE attachments are inline attachments.
        // OLE attachments have 0x00000006 for the value of the PidTagAttachMethod property
        if (att.getProperties().contains(MapiPropertyTag.PR_ATTACH_METHOD))
        {
            return att.getPropertyLong(MapiPropertyTag.PR_ATTACH_METHOD) == 0x00000006;
        }
        return false;
    }
    else
        throw new ArgumentOutOfRangeException();
}

Example usage:

String fileName = ("Stationery Issued.msg");
MapiMessage message = MapiMessage.fromFile(fileName);
MapiAttachmentCollection attachments = message.getAttachments();
for (int i = 0; i < attachments.size(); i++)
{
    MapiAttachment attachment = (MapiAttachment)attachments.get(i);
    if (IsInlineAttachment(attachment,message.getBodyType()))
    {
        System.out.println(attachment.getLongFileName() + " is inline attachment");
    }
    else
    {
        System.out.println(attachment.getLongFileName() + " is regular attachment");
    }
}

Hi,

I also want to know
How can I remove only regular attachment not inline/embedded?

Thanks,

Hi Luca,


Thanks for writing to Aspose.Email support team again.

MapiMessage does not differentiate attachments as regular or inline so we need additional code for testing attachment type. In the earlier example, after differentiating regular attachment using IsInlineAttachment( ) we can remove it by using MapiAttachmentCollection.remove ( ) function. Please give a try to the following code where regular attachments are removed from the message. If it does not fulfill your requirement, please provide more details about the issue. It will help us to assist you as soon as possible.


import java.io.FileInputStream;
import com.aspose.email.BodyContentType;
import com.aspose.email.License;
import com.aspose.email.MapiAttachment;
import com.aspose.email.MapiAttachmentCollection;
import com.aspose.email.MapiMessage;
import com.aspose.email.MapiPropertyTag;
import com.aspose.email.ms.System.ArgumentOutOfRangeException;

public class TestMain {

/**
* @param args
*/
public static void main(String[] args)
{
try
{
//Create a stream object containing the license file
FileInputStream fstream=new FileInputStream(“E:\Aspose.Total.Java.lic”);

//Instantiate the License class
License license=new License();

//Set the license through the stream object
license.setLicense(fstream);
}
catch(Exception ex)
{
//Printing the exception, if it occurs
System.out.println(ex.toString());
}

// TODO Auto-generated method stub
String fileName = (“Stationery Issued.msg”);
MapiMessage message = MapiMessage.fromFile(fileName);
MapiAttachmentCollection attachments = message.getAttachments();
for (int i = 0; i < attachments.size(); i++)
{
MapiAttachment attachment = (MapiAttachment)attachments.get(i);
if (IsInlineAttachment(attachment,message.getBodyType()))
{
System.out.println(attachment.getLongFileName() + " is inline attachment");
}
else
{
System.out.println(attachment.getLongFileName() + " is regular attachment");

//Removing Attachment
attachments.remove(i);
}
}
message.save(“OutputFile.msg”);
}
public static boolean IsInlineAttachment(MapiAttachment att, int messageBodyType)
{
if (messageBodyType == BodyContentType.PlainText)
// ignore indications for plain text messages
return false;

else if (messageBodyType == BodyContentType.Html)
{
// check the PidTagAttachFlags property
if (att.getProperties().contains(0x37140003))
{
long attachFlagsValue = att.getPropertyLong(0x37140003);
if ((attachFlagsValue & 0x00000004) == 0x00000004)
{
// check PidTagAttachContentId property
if (att.getProperties().contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID) ||
att.getProperties().contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W))
{
return true;
}

// check PidTagAttachContentLocation property
if (att.getProperties().contains(0x3713001E) ||
att.getProperties().contains(0x3713001F))
{
return true;
}
}
}
return false;
}
else if (messageBodyType == BodyContentType.Rtf)
{
// If the body is RTF, then all OLE attachments are inline attachments.
// OLE attachments have 0x00000006 for the value of the PidTagAttachMethod property
if (att.getProperties().contains(MapiPropertyTag.PR_ATTACH_METHOD))
{
return att.getPropertyLong(MapiPropertyTag.PR_ATTACH_METHOD) == 0x00000006;
}
return false;
}
else
throw new ArgumentOutOfRangeException();
}
}



Hi,

Your given code for getting inline attachment is not working with the attach mail.

Please provide solution, its urgent

Thanks.

Hi,

Your given code for getting inline attachment is not working with the attached mail.

Please provide solution, its urgent

Thanks.

Hi Luca,

Thank you for reaching out to us and reporting this case.

After analyzing the file for various properties, it seems to add another condition for the PR_ATTACH_DISPOSITION (0x3716001F or 0x3716001E) property to your code. Please modify the BodyContentType.Html if Condition of your code as follow:

if (att.getProperties().contains(0x37140003))
{
    long attachFlagsValue = att.getPropertyLong(0x37140003);
    //existing code remains here
}
// This is new condition - START
else if((att.getProperties().contains(0x3716001F) && att.getPropertyString(0x3716001F).equalsIgnoreCase("inline"))
|| (att.getProperties().contains(0x3716001E) && att.getPropertyString(0x3716001E).equalsIgnoreCase("inline")))
{
    return true;
}
// This is new condition - END
return false;

Hi,

Your given code is not able split xls attachment
Please look into it on urgent basis.

Mail you can see in the attachment.


Thanks.

Hi Luca,

lucaro:

Your given code is not able split xls attachment

Can you please elaborate what you mean by “split xls attachment”?

I have tested it using the above code and it recognizes the attachments as regular attachments as the message body is RTF type and it doesn’t fulfil the condition specified. The attachments are saved properly by the following code sample:

MapiMessage mapi = MapiMessage.fromFile("embedded attachments- pls test this .msg");

for (int i=0; i<mapi.getAttachments().size();i++)
{
    MapiAttachment mapiAtt = (MapiAttachment) mapi.getAttachments().get(i);
    System.out.println(mapiAtt.getFileName());
    mapiAtt.save(mapiAtt.getFileName());
}

Hi,

Xls is the regular attachment, so it shouldn’t come as inline.

And one more problem, with the attached mail embedded attachments are also not coming as inline attachment.

Thanks.

Hi Luca,


We are sorry for the delayed response.

Please spare us little time as we are investigating the issue and will share our findings soon with you.

Your cooperation is highly appreciated in this regard.

Hi Luca,


Thank you for your patience.

After investigation this issue further, I found that for the mentioned attached file, the body type is HTML, and it contains the PR_ATTACH_DISPOSITION (0x3716001F or 0x3716001E) property for the the inline attachments, while at the same time missing the condition:

if ((attachFlagsValue & 0x00000004) == 0x00000004)

Please modify the BodyContentType.Html part of your code as follow to accomodate this condition as well:


else if (messageBodyType == BodyContentType.Html)

{

// check the PidTagAttachFlags property

if (att.getProperties().contains(0x37140003))

{

long attachFlagsValue = att.getPropertyLong(0x37140003);

if ((attachFlagsValue & 0x00000004) == 0x00000004)

{
// existing code goes as it is
}

else if((att.getProperties().contains(0x3716001F) && att.getPropertyString(0x3716001F).equalsIgnoreCase(“inline”))

|| (att.getProperties().contains(0x3716001E) && att.getPropertyString(0x3716001E).equalsIgnoreCase(“inline”)))

{

return true;

}

}

else if((att.getProperties().contains(0x3716001F) && att.getPropertyString(0x3716001F).equalsIgnoreCase(“inline”))

|| (att.getProperties().contains(0x3716001E) && att.getPropertyString(0x3716001E).equalsIgnoreCase(“inline”)))

{

return true;

}

return false;

}

Hi,

Each time I am giving you a new mail and you are providing me a new condition for inline attachment.

Please provide me at one shot, what all condition I need to apply for knowing inline attachment.

Your given snippet is not clear for me

Please provide me complete .html condition.

Hi Luca,


We are very sorry for the inconvenience caused to you.

I would like to share with you that we provide code snippets based on the API documentation and in light of the implementation of these according to Microsoft documentation. In my earliest sample that I provided, the CONTENT-DISPOSITION part was not mentioned in the MS documentation. The sample files you provided helped us investigate these cases and provide you code snippet.

Please try the code from the attached file and if you hit another similar issue, I will raise an investigation ticket in this regard to sought help from development team.


Hi

Any update on this issue.

Basically our requirement is that we don't want anything present in email signature should be splitted as an attachment.

Please provide the response urgently.