OUT-277: Process all items in Items.ItemAdd that are not being copied
authorThomas
Thu, 22 Jun 2017 08:57:05 +0200
changeset 17171bf7ab2fe080
parent 1716 2debca377bf9
child 1718 58aa0058d282
OUT-277: Process all items in Items.ItemAdd that are not being copied
ThisAddIn.cs
     1.1 --- a/ThisAddIn.cs	Wed Jun 21 13:02:40 2017 +0200
     1.2 +++ b/ThisAddIn.cs	Thu Jun 22 08:57:05 2017 +0200
     1.3 @@ -4141,7 +4141,7 @@
     1.4  
     1.5                      if (omi != null)
     1.6                      {
     1.7 -                        // Check, if message is a beacon or keysync message and delete it in this case
     1.8 +                        // Check, if message is a beacon or keysync message
     1.9                          omi.GetPEPProperty(MailItemExtensions.PEPProperty.AutoConsume, out propValue, null);
    1.10                          if (propValue != null)
    1.11                          {
    1.12 @@ -4156,14 +4156,19 @@
    1.13                                  process = true;
    1.14                              }
    1.15                          }
    1.16 -                        // In Outlook 2010, process items on untrusted servers in order to make sure the
    1.17 -                        // unencrypted preview is shown correctly.
    1.18 -                        else if ((Globals.GetOutlookVersion() == Globals.Version.Outlook2010) &&
    1.19 -                                 (CryptableMailItem.IsInCopiedItemsList(omi?.EntryID) == false) &&
    1.20 -                                 (omi.GetIsSecurelyStored()))
    1.21 +                        /* Else, process the mail item and decrypt it. This is needed especially for Sent folders as sent mails are normally
    1.22 +                         * not read and therefore remain encrypted and not searchable in this folder.
    1.23 +                         * 
    1.24 +                         * NOTE: Via debugging, it could be determined that the Copy() method called during the creation of a mirror item on
    1.25 +                         * untrusted servers most likely raises internally the Items.ItemAdd event. Therefore, we add the copied item's EntryID
    1.26 +                         * to a list of copied items during its processing and check here if the newly added mail item is in this list. If yes,
    1.27 +                         * do not process it. However, if for whatever reason, the ItemAdd event for one of those copied items was to be raised 
    1.28 +                         * at a later stage, we might run into problems with a loop of copied items that will be processed, copied during creation
    1.29 +                         * of the mirror, raise an ItemAdd event for the new copy and so on.
    1.30 +                         */
    1.31 +                        else if (CryptableMailItem.IsInCopiedItemsList(omi?.EntryID) == false)
    1.32                          {
    1.33 -                            MapiHelper.SetProperty(omi, MapiProperty.PidTagMessageClass, MapiPropertyValue.PidTagMessageClassSecurePEP);
    1.34 -                            omi.Save();
    1.35 +                            process = true;
    1.36                          }
    1.37  
    1.38                          if (process)