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.
lucaro:
It is removing embedded icon as a attachment.
Hi
When I get the attachment of the given mail
It is also giving me the embedded icon.
Thanks
Hi Sachin,
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,
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");
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,
Hi Luca,
else if (messageBodyType == BodyContentType.Html)
{
// check the PidTagAttachFlags property
if (att.getProperties().contains(0x37140003))
{
long attachFlagsValue = att.getPropertyLong(0x37140003);
if ((attachFlagsValue & 0x00000004) == 0x00000004)
{
}
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,
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.