Search code examples
c#emailoutlookemail-attachments

How Outlook shows the PaperClip icon for any attachment other than embedded images?


For my use case, I need to find out if a mail item in outlook has any embedded image as an attachment. I am working on Outlook 2013+ version. It is my understanding that for all other embedded attachments, they can only be added in Rich Text format and Outlook marks them as attachment (Marked as PaperClip icon). But if the mail contains only a embedded image in HTML format then the PaperClip icon does not appear. Please feel free me to point me if I am wrong with this observation.

My question however is, how is outlook itself deciding and showing the paperclip icon? I used Outlook Spy but the PR_HasAttach is set to true for these mails. I have also read other solutions where people have pointed out that you can try to find tag in the HTML Mail body which mostly works. But has any body ever wondered about the PaperClip icon?

I am having this doubt because when I apply the DASL filter urn:schemas:httpmail:hasattachment = true, such mails are filtered out by the query. Same thing happens if you use has attachments filter in outlook itself. But if I select the same mail item, and try to explore this property either by code or by Outlook Spy, it comes as true. That is why I am thinking that it might have to do with the icon Or atleast If I can find the property which sets the icon.

Edit 1: When I use the following code it does not work for embedded or hidden attachments. For others it works.

IEnumerator eNum = listOfSearchedOutlookItems.GetEnumerator();
while (eNum.MoveNext())
{
      Outlook.MailItem mailItem;
      try
      {
          mailItem = (Outlook.MailItem)eNum.Current;
          bool b = mailItem.PropertyAccessor.GetProperty(@"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B");
       }
       catch
       {
          continue;
       }
  }

However strangely the following works for all the cases (As many as I have tested). So in a way this problem is solved thanks to Dmitry's answer. But still wondering why is the previous one not working.

Outlook.Table table = MyFolder.GetTable(SomeFilterIfNeeded);
table.Columns.RemoveAll();
table.Columns.Add(@"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B");

while (!table.EndOfTable)
{
     Outlook.Row nextRow = table.GetNextRow();
     bool b = (bool)nextRow[@"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B"];
 }

Solution

  • To hide the paperclip icon, Outlook sets SmartNoAttach named MAPI property (DASL name http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B).