Only hide messages if not on IMAP OUT-507
authorThomas
Thu, 13 Dec 2018 17:10:18 +0100
branchOUT-507
changeset 25058a26c367dfe8
parent 2504 624b9e04235e
child 2506 4b7924035021
Only hide messages if not on IMAP
CryptableMailItem.cs
DecryptionStack.cs
Mapi.cs
ThisAddIn.cs
     1.1 --- a/CryptableMailItem.cs	Thu Dec 13 09:01:33 2018 +0100
     1.2 +++ b/CryptableMailItem.cs	Thu Dec 13 17:10:18 2018 +0100
     1.3 @@ -1367,9 +1367,15 @@
     1.4                          if (saveError)
     1.5                          {
     1.6                              try
     1.7 -                            {
     1.8 -                                int sts = Mapi.ForceSave(this.internalMailItem);
     1.9 -                                Log.Verbose("ProcessAndGetRating: ForceSave returned " + sts.ToString("X"));
    1.10 +                            {                               
    1.11 +                                int sts = Mapi.Save(this.internalMailItem, Mapi.SaveOption.KEEP_OPEN_READWRITE);
    1.12 +                                Log.Verbose("ProcessAndGetRating: Saving using backup method. Return status is " + sts.ToString("X"));
    1.13 +
    1.14 +                                if (sts != Mapi.HResult.S_OK)
    1.15 +                                {
    1.16 +                                    sts = Mapi.Save(this.internalMailItem, Mapi.SaveOption.FORCE_SAVE);
    1.17 +                                    Log.Verbose("ProcessAndGetRating: Saving with FORCE_SAVE flag returned " + sts.ToString("X"));
    1.18 +                                }
    1.19                              }
    1.20                              catch (Exception ex)
    1.21                              {
    1.22 @@ -1825,9 +1831,7 @@
    1.23                  }
    1.24              }
    1.25  
    1.26 -            // Note: no native resources to free
    1.27 -
    1.28 -            return;
    1.29 +            this.internalMailItem = null;
    1.30          }
    1.31  
    1.32          /// <summary>
     2.1 --- a/DecryptionStack.cs	Thu Dec 13 09:01:33 2018 +0100
     2.2 +++ b/DecryptionStack.cs	Thu Dec 13 17:10:18 2018 +0100
     2.3 @@ -199,12 +199,11 @@
     2.4                  }
     2.5              }
     2.6  
     2.7 -            // If item was pushed, enable timer and start decryption
     2.8 +            // If item was pushed, enable timer
     2.9              if (pushed &&
    2.10                  this.decryptionTimer.Enabled == false)
    2.11              {
    2.12                  this.decryptionTimer.Start();
    2.13 -                this.DecryptionTimer_Tick(null, null);
    2.14                  Log.Verbose("DecryptionStack.TryPush: decryptionTimer started");
    2.15              }
    2.16  
    2.17 @@ -317,9 +316,6 @@
    2.18                          _ = cmi.StartProcessing(false, true);
    2.19                          Log.Verbose("DecryptionStack.DecryptionTimer_Tick: started decryption of item with entryId " + omi?.EntryID);
    2.20                      }
    2.21 -
    2.22 -                    omi = null;
    2.23 -                    omiCopy = null;
    2.24                  }
    2.25                  else
    2.26                  {
     3.1 --- a/Mapi.cs	Thu Dec 13 09:01:33 2018 +0100
     3.2 +++ b/Mapi.cs	Thu Dec 13 17:10:18 2018 +0100
     3.3 @@ -103,11 +103,11 @@
     3.4          /// <summary>
     3.5          /// Save options for the IMAPIProp.SaveChanges method.
     3.6          /// </summary>
     3.7 -        internal static class SaveOptions
     3.8 +        internal enum SaveOption
     3.9          {
    3.10 -            public const int KEEP_OPEN_READONLY     = 0x00000001;
    3.11 -            public const int KEEP_OPEN_READWRITE    = 0x00000002;
    3.12 -            public const int FORCE_SAVE             = 0x00000004;
    3.13 +            KEEP_OPEN_READONLY = 0x00000001,
    3.14 +            KEEP_OPEN_READWRITE = 0x00000002,
    3.15 +            FORCE_SAVE = 0x00000004
    3.16          }
    3.17          #endregion
    3.18  
    3.19 @@ -675,7 +675,7 @@
    3.20                  IntPtr problems = IntPtr.Zero;
    3.21                  if (IMAPIProp.SetProps((uint)propCount, propArray, problems) == Mapi.HResult.S_OK)
    3.22                  {
    3.23 -                    success = (IMAPIProp.SaveChanges(Mapi.SaveOptions.KEEP_OPEN_READWRITE) == Mapi.HResult.S_OK);
    3.24 +                    success = (IMAPIProp.SaveChanges((uint)Mapi.SaveOption.KEEP_OPEN_READWRITE) == Mapi.HResult.S_OK);
    3.25                  }
    3.26              }
    3.27              catch (Exception ex)
    3.28 @@ -934,7 +934,7 @@
    3.29  
    3.30                  // Save changes
    3.31                  Mapi.IMAPIProp mapiProp = (Mapi.IMAPIProp)Marshal.GetTypedObjectForIUnknown(IUnknown, typeof(Mapi.IMAPIProp));
    3.32 -                success = (mapiProp.SaveChanges(Mapi.SaveOptions.KEEP_OPEN_READWRITE) == Mapi.HResult.S_OK);
    3.33 +                success = (mapiProp.SaveChanges((uint)Mapi.SaveOption.KEEP_OPEN_READWRITE) == Mapi.HResult.S_OK);
    3.34              }
    3.35              catch (Exception ex)
    3.36              {
    3.37 @@ -972,11 +972,12 @@
    3.38          }
    3.39  
    3.40          /// <summary>
    3.41 -        /// Calls SaveChanges() with the FORCE_SAVE flag.
    3.42 +        /// Calls SaveChanges() with the given flag.
    3.43          /// </summary>
    3.44          /// <param name="omi">The Outlook mail item to save.</param>
    3.45 +        /// <param name="saveOption">The save flag to pass.</param>
    3.46          /// <returns>The status of this method.</returns>
    3.47 -        public static int ForceSave(Outlook.MailItem omi)
    3.48 +        public static int Save(Outlook.MailItem omi, Mapi.SaveOption saveOption)
    3.49          {
    3.50              int status = (int)Mapi.HResult.S_FALSE;
    3.51  
    3.52 @@ -1004,7 +1005,7 @@
    3.53  
    3.54                  // Save changes
    3.55                  Mapi.IMAPIProp mapiProp = (Mapi.IMAPIProp)Marshal.GetTypedObjectForIUnknown(IUnknown, typeof(Mapi.IMAPIProp));
    3.56 -                status = mapiProp.SaveChanges(Mapi.SaveOptions.FORCE_SAVE);
    3.57 +                status = mapiProp.SaveChanges((uint)saveOption);
    3.58              }
    3.59              catch (Exception ex)
    3.60              {
     4.1 --- a/ThisAddIn.cs	Thu Dec 13 09:01:33 2018 +0100
     4.2 +++ b/ThisAddIn.cs	Thu Dec 13 17:10:18 2018 +0100
     4.3 @@ -3877,8 +3877,13 @@
     4.4                          // If this item is to be processed, add to decryption stack
     4.5                          if (process)
     4.6                          {
     4.7 -                            // If potentially encrypted message, hide during processing
     4.8 -                            if (omi?.Attachments?.Count == 2)
     4.9 +                            /* If potentially encrypted message, hide during processing.
    4.10 +                             * Note: on IMAP, there seems to be some race condition that leads to a failure during the Save() method when removing
    4.11 +                             * the 'pEp Processing' category. As this means that in those environments, this category doesn't get removed correctly
    4.12 +                             * and the mail item remains hidden until a restart of Outlook. Therefore, don't hide messages on IMAP.
    4.13 +                             */ 
    4.14 +                            if ((omi?.Attachments?.Count == 2) &&
    4.15 +                                (omi.GetAccountType() != Outlook.OlAccountType.olImap))
    4.16                              {
    4.17                                  omi.AddPEPProcessingCategory();
    4.18                                  omi.Save();