1
votes

I am developing an Outlook-AddIn that automatically decrypts emails. So basically, the AddIn changes some MailItem properties (subject, body, attachments) when new mail arrives. The problem is that when I save the item then the decrypted message is synchronized with the server, which is really bad for end-to-end-encryption... If I don't save the item, then the explorer pane still shows the encrypted message and searching for emails (decrypted subject or body) does not work.

My question is: How can I display and (locally) store the decrypted mailItem, so that all the usual features like email searching still work? Is there a way to stop synchronization for specific emails in .ost?

One solution that I came up with is to store a copy of the MailItem in a local .pst store. But in that case the user has to handle the messages in two different stores (.ost and .pst), which is not very user friendly. The requirement is that the user has to change his usual behaviour as little as possible when reading emails.

private void Outlook_NewMailEx(object Item)
    {
        Outlook.MailItem mailItem = Application.Session.GetItemFromID((string)Item);

        if (mailItem != null)
        {
            // decrypt the mailItem
            mailItem.Subject = "decrypted subject";
            mailItem.Body = "decrypted body";

            // save mailItem LOCALLY
            // (don't synchronize the decrypted message with the server)
            mailItem.Save();
        }                    
    }

I would be grateful for any help!

1

1 Answers

1
votes

One solution that I came up with is to store a copy of the MailItem in a local .pst store.

That was my first thought of possible implementations.

Also you may consider the following scenarious:

  1. Keep a decrypted copy of the item in a hidden folder. The GetStorage method of the Folder class returns a StorageItem object on the parent Folder to store data for an Outlook solution. A StorageItem object is stored at the folder level, allowing it to roam with the account and be available online or offline. The Outlook object model does not provide any collection object for StorageItem objects. However, you can use Folder.GetTable to obtain a Table with all the hidden items in a Folder, when you specify the TableContents parameter as olHiddenItems.

Once you have obtained a StorageItem object, you can do the following to store solution data:

  • Add attachments to the item for storage.
  • Use explicit built-in properties of the item such as Body to store custom data.
  • Add custom properties to the item using UserProperties.Add method. Note that in this case, the optional AddToFolderFields and DisplayFormat arguments of the UserProperties.Add method will be ignored.
  • Use the PropertyAccessor object to get or set custom properties.

See Storing Data for Solutions for more information.

  1. Add custom properties to Outlook items with a decrypted content. So, when the item is going to be shown you can replace the content of built-in properties on the fly.
  2. And the other solution is to store the decrypted information in the database. Note, you develop a managed add-in, so you can use all features of the .net framework.