Inline attachment check logic has stopped working since 17.4

Hi,

We were using logic suggested in following article to identify whether an attachment is an inline attachment or not while processing an email file

https://docs.aspose.com/display/emailjava/Differentiate+between+Inline+and+Regular+Attachments

This has stopped working since 17.4, it has even stopped compiling due to apparent changes in contains() API.

Please let us know the new way of identifying inline attachments asap.

Thanks,
Rajiv

Hi Rajiv,


Thank you for contacting Aspose support team.

You may please use containsKey function instead of contains function as shown in the sample code below:

<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:navy”>public static void
<span style=“font-size: 9pt; font-family: “Courier New”;”>Email_844365()

{

String fileName = (<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Sample.msg”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

MapiMessage message = MapiMessage.fromFile(fileName);

MapiAttachmentCollection attachments
= message.getAttachments();



<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>for
<span style=“font-size: 9pt; font-family: “Courier New”;”>(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>int
<span style=“font-size: 9pt; font-family: “Courier New”;”>i = <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0<span style=“font-size: 9pt; font-family: “Courier New”;”>; i <
attachments.size(); i++) {

MapiAttachment attachment =
(MapiAttachment) attachments.get_Item(i);

<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if
<span style=“font-size: 9pt; font-family: “Courier New”;”>(IsInlineAttachment(attachment,
message.getBodyType())) {

System.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>out
<span style=“font-size: 9pt; font-family: “Courier New”;”>.println(attachment.getLongFileName()

  • <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
    “Times New Roman”;color:green”>" is inline attachment"
    <span style=“font-size: 9pt; font-family: “Courier New”;”>);

    } <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:navy”>else
    <span style=“font-size: 9pt; font-family: “Courier New”;”>{

    System.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:#660E7A”>out
    <span style=“font-size: 9pt; font-family: “Courier New”;”>.println(attachment.getLongFileName()
  • <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
    “Times New Roman”;color:green”>" is regular attachment"
    <span style=“font-size: 9pt; font-family: “Courier New”;”>);

    }

    }

    }

    <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
    “Times New Roman”;color:navy”>public static boolean
    <span style=“font-size: 9pt; font-family: “Courier New”;”>IsInlineAttachment(MapiAttachment att, <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:navy”>int
    <span style=“font-size: 9pt; font-family: “Courier New”;”>messageBodyType)

    {

    <span style=“font-size:
    9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:navy”>if
    <span style=“font-size: 9pt; font-family: “Courier New”;”>(messageBodyType ==
    BodyContentType.<span style=“font-size:9.0pt;font-family:“Courier New”;
    mso-fareast-font-family:“Times New Roman”;color:#660E7A”>PlainText
    <span style=“font-size: 9pt; font-family: “Courier New”;”>)

    <span style=“font-size:
    9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:gray”>// ignore indications for plain text messages

    <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:navy”>return false
    <span style=“font-size: 9pt; font-family: “Courier New”;”>;



    <span style=“font-size:
    9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:navy”>else if
    <span style=“font-size: 9pt; font-family: “Courier New”;”>(messageBodyType ==
    BodyContentType.<span style=“font-size:9.0pt;font-family:“Courier New”;
    mso-fareast-font-family:“Times New Roman”;color:#660E7A”>Html
    <span style=“font-size: 9pt; font-family: “Courier New”;”>)

    {

    <span style=“font-size:
    9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:gray”>// check the PidTagAttachFlags property

    <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:navy”>if
    <span style=“font-size: 9pt; font-family: “Courier New”;”>(att.getProperties().containsKey(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:blue”>0x37140003<span style=“font-size: 9pt; font-family: “Courier New”;”>))

    {

    <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:navy”>long
    <span style=“font-size: 9pt; font-family: “Courier New”;”>attachFlagsValue =
    att.getPropertyLong(<span style=“font-size:9.0pt;font-family:“Courier New”;
    mso-fareast-font-family:“Times New Roman”;color:blue”>0x37140003<span style=“font-size: 9pt; font-family: “Courier New”;”>);

    <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:navy”>if
    <span style=“font-size: 9pt; font-family: “Courier New”;”>((attachFlagsValue &
    <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
    “Times New Roman”;color:blue”>0x00000004<span style=“font-size: 9pt; font-family: “Courier New”;”>)
    == <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
    “Times New Roman”;color:blue”>0x00000004<span style=“font-size: 9pt; font-family: “Courier New”;”>)

    {

    <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:gray”>// check PidTagAttachContentId property

    <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:navy”>if
    <span style=“font-size: 9pt; font-family: “Courier New”;”>(att.getProperties().containsKey(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
    color:#660E7A”>PR_ATTACH_CONTENT_ID
    <span style=“font-size: 9pt; font-family: “Courier New”;”>)
    ||

att.getProperties().containsKey(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_CONTENT_ID_W
<span style=“font-size: 9pt; font-family: “Courier New”;”>))

{

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return true
<span style=“font-size: 9pt; font-family: “Courier New”;”>;

}



<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// check PidTagAttachContentId property

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if
<span style=“font-size: 9pt; font-family: “Courier New”;”>(att.getProperties().containsKey(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_CONTENT_ID
<span style=“font-size: 9pt; font-family: “Courier New”;”>)
||

att.getProperties().containsKey(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_CONTENT_ID_W
<span style=“font-size: 9pt; font-family: “Courier New”;”>))

{

<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:navy”>return
true
<span style=“font-size: 9pt; font-family: “Courier New”;”>;

}



<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// check PidTagAttachContentLocation property

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if
<span style=“font-size: 9pt; font-family: “Courier New”;”>(att.getProperties().containsKey(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x3713001E<span style=“font-size: 9pt; font-family: “Courier New”;”>) ||

att.getProperties().containsKey(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:blue”>0x3713001F<span style=“font-size: 9pt; font-family: “Courier New”;”>))

{

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return true
<span style=“font-size: 9pt; font-family: “Courier New”;”>;

}

}

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>else if
<span style=“font-size: 9pt; font-family: “Courier New”;”>((att.getProperties().containsKey(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x3716001F<span style=“font-size: 9pt; font-family: “Courier New”;”>) &&
att.getPropertyString(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>0x3716001F<span style=“font-size: 9pt; font-family: “Courier New”;”>).equalsIgnoreCase(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:green”>“inline”
<span style=“font-size: 9pt; font-family: “Courier New”;”>))

||
(att.getProperties().containsKey(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:blue”>0x3716001E<span style=“font-size: 9pt; font-family: “Courier New”;”>) && att.getPropertyString(<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x3716001E<span style=“font-size: 9pt; font-family: “Courier New”;”>).equalsIgnoreCase(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“inline”
<span style=“font-size: 9pt; font-family: “Courier New”;”>)))

{

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return true
<span style=“font-size: 9pt; font-family: “Courier New”;”>;

}



}

<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>else if
<span style=“font-size: 9pt; font-family: “Courier New”;”>((att.getProperties().containsKey(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x3716001F<span style=“font-size: 9pt; font-family: “Courier New”;”>) &&
att.getPropertyString(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>0x3716001F<span style=“font-size: 9pt; font-family: “Courier New”;”>).equalsIgnoreCase(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:green”>“inline”
<span style=“font-size: 9pt; font-family: “Courier New”;”>))

||
(att.getProperties().containsKey(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:blue”>0x3716001E<span style=“font-size: 9pt; font-family: “Courier New”;”>) && att.getPropertyString(<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0x3716001E<span style=“font-size: 9pt; font-family: “Courier New”;”>).equalsIgnoreCase(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“inline”
<span style=“font-size: 9pt; font-family: “Courier New”;”>)))

{

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return true
<span style=“font-size: 9pt; font-family: “Courier New”;”>;

}

<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return false
<span style=“font-size: 9pt; font-family: “Courier New”;”>;

}



<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>else if
<span style=“font-size: 9pt; font-family: “Courier New”;”>(messageBodyType ==
BodyContentType.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>Rtf
<span style=“font-size: 9pt; font-family: “Courier New”;”>)

{

<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// If the body is RTF, then all OLE attachments are inline
attachments.

// OLE attachments have
0x00000006 for the value of the PidTagAttachMethod property

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>if
<span style=“font-size: 9pt; font-family: “Courier New”;”>(att.getProperties().containsKey(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_METHOD
<span style=“font-size: 9pt; font-family: “Courier New”;”>))

{

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return
<span style=“font-size: 9pt; font-family: “Courier New”;”>att.getPropertyLong(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_ATTACH_METHOD
<span style=“font-size: 9pt; font-family: “Courier New”;”>)
== <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:blue”>0x00000006<span style=“font-size: 9pt; font-family: “Courier New”;”>;

}

<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>return false
<span style=“font-size: 9pt; font-family: “Courier New”;”>;

}

<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>else

throw new
<span style=“font-size: 9pt; font-family: “Courier New”;”>ArgumentOutOfRangeException();

}

Thanks Kashif.


So contains() has just been renamed with containsKey() is it ? Or there is some change in its internal implementation as well ??

And what’s the purpose of the other variant of that method - contains(com.aspose.ms.System.Collections.Generic.KeyValuePair<Long,MapiProperty> item)

Regards,
Rajiv

Hi Rajiv,


There are no differences in terms of functionality of MapiPropertyCollection behavior. The difference came to being due to some refactoring of MapiPropertyCollection in equivalent .NET as a result of which it was necessary to implement the Contains(T) and ContainsKey(TKey) methods. The contains method determines whether the collection contains a specific MapiProperty value. And the ContainsKey() method determines whether the collection contains a property with the specified tag.

Thanks !


Regards,
Rajiv

You are welcome.