Major restructuration: OUT-497
authorThomas
Thu, 06 Sep 2018 09:29:19 +0200
branchOUT-497
changeset 23590e6191d039e4
parent 2358 5d193f09df27
child 2360 f01523e581fa
Major restructuration:
- Remove FormRegionPrivacyStatus
- Create new WatchedWindow as base class for WatchedExplorers and WatchedInspectors
- Move all logic from FormRegionPrivacy to WatchedWindow
- Use Explorer.SelectionChanged and Inspectors.Newinspector events instead of FormRegionPrivacyStatus.FormRegionShowing to detect opening of mail item.
- Rework of RibbonCustomizations. State of pEp button now stored in WatchedWindow instead of FormRegionPrivacyStatus
Extensions/MailItemExtensions.cs
FPPMessage.cs
ThisAddIn.cs
UI/FormControlPreviewMessage.xaml.cs
UI/FormRegionPreviewUnencrypted.cs
UI/RibbonCustomizations.cs
Wrappers/WatchedExplorer.cs
Wrappers/WatchedInspector.cs
Wrappers/WatchedWindow.cs
pEpForOutlook.csproj
     1.1 --- a/Extensions/MailItemExtensions.cs	Tue Sep 04 11:14:15 2018 +0200
     1.2 +++ b/Extensions/MailItemExtensions.cs	Thu Sep 06 09:29:19 2018 +0200
     1.3 @@ -2392,6 +2392,16 @@
     1.4          }
     1.5  
     1.6          /// <summary>
     1.7 +        /// Gets the WatchedExplorer or WatchedInspector in which the mail item resides.
     1.8 +        /// </summary>
     1.9 +        /// <param name="omi">The Outlook mail item to process with.</param>
    1.10 +        /// <returns>The WatchedExplorer or WatchedInspector the mail item resides in or null if an error occured.</returns>
    1.11 +        public static WatchedWindow GetWatchedParentWindow(this Outlook.MailItem omi)
    1.12 +        {
    1.13 +            return Globals.ThisAddIn.GetWatchedParentWindow(omi);
    1.14 +        }
    1.15 +
    1.16 +        /// <summary>
    1.17          /// Gets the parsed transport message headers (MIME headers) of the given Outlook mail item.
    1.18          /// This will internally use the MAPI property PidTagTransportMessageHeaders.
    1.19          /// Warning: This can return null.
     2.1 --- a/FPPMessage.cs	Tue Sep 04 11:14:15 2018 +0200
     2.2 +++ b/FPPMessage.cs	Thu Sep 06 09:29:19 2018 +0200
     2.3 @@ -270,6 +270,9 @@
     2.4                              // Save the EntryId
     2.5                              PEPDatabase.StoreFPPEntryId(this.CurrentMessage.ForceProtectionId, this.CurrentEntryId);
     2.6  
     2.7 +                            // Define a mail item
     2.8 +                            Outlook.MailItem omi = null;
     2.9 +
    2.10                              // Modify body
    2.11                              if (this.CurrentMessage?.LongMsg?.Contains(Globals.PEP_WEBSITE_READER_LINK) == true)
    2.12                              {
    2.13 @@ -277,7 +280,6 @@
    2.14                                  this.CurrentMessage.LongMsg = FPPMessage.PEP_FPP_MESSAGE_BODY_PLAIN_PEP_INSTALLED;
    2.15  
    2.16                                  // Get mail item
    2.17 -                                Outlook.MailItem omi = null;
    2.18                                  try
    2.19                                  {
    2.20                                      omi = Globals.ThisAddIn.Application.Session.GetItemFromID(this.CurrentEntryId);
    2.21 @@ -359,10 +361,6 @@
    2.22                                      {
    2.23                                          Log.Error("ContinueProcessing: Error saving modified Initial Message. " + ex.ToString());
    2.24                                      }
    2.25 -                                    finally
    2.26 -                                    {
    2.27 -                                        omi = null;
    2.28 -                                    }
    2.29                                  }
    2.30                              }
    2.31  
    2.32 @@ -370,21 +368,36 @@
    2.33                              status = this.CreateAndSendNextFPPMessage(MessageType.AnswerMessage);
    2.34  
    2.35                              // Set form regions
    2.36 -                            WindowFormRegionCollection formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveWindow()];
    2.37 +                            try
    2.38 +                            {
    2.39 +                                if (omi == null)
    2.40 +                                {
    2.41 +                                    omi = Globals.ThisAddIn.Application.Session.GetItemFromID(this.CurrentEntryId);
    2.42 +                                }
    2.43 +                                WatchedWindow window = omi.GetWatchedParentWindow();
    2.44 +                                WindowFormRegionCollection formRegions = Globals.FormRegions[window.Window];
    2.45  
    2.46 -                            // Set unencrypted preview if necessary
    2.47 -                            if (formRegions?.FormRegionPreviewUnencrypted?.Visible == true)
    2.48 +                                // Set unencrypted preview if necessary
    2.49 +                                if (formRegions?.FormRegionPreviewUnencrypted?.Visible == true)
    2.50 +                                {
    2.51 +                                    formRegions.FormRegionPreviewUnencrypted.DisplayState.SetMessage(this.CurrentMessage);
    2.52 +                                    Log.Verbose("FPPMessage.ContinueProcessing: Mirror displayed.");
    2.53 +                                }
    2.54 +
    2.55 +                                // Update rating if necessary
    2.56 +                                if (manuallyTriggered)
    2.57 +                                {
    2.58 +                                    var rating = AdapterExtensions.ReevaluateFPPMessageRating(this.CurrentMessage);
    2.59 +                                    window.SetRating(rating);
    2.60 +                                }
    2.61 +                            }
    2.62 +                            catch (Exception ex)
    2.63                              {
    2.64 -                                formRegions.FormRegionPreviewUnencrypted.DisplayState.SetMessage(this.CurrentMessage);
    2.65 -                                Log.Verbose("ContinueProcessing: Mirror displayed.");
    2.66 +                                Log.Error("FPPMessage.ContinueProcessing: Error during setting form region and rating. " + ex.ToString());
    2.67                              }
    2.68 -
    2.69 -                            // Update rating if necessary
    2.70 -                            if (manuallyTriggered &&
    2.71 -                                (formRegions?.FormRegionPrivacyStatus?.Visible == true))
    2.72 +                            finally
    2.73                              {
    2.74 -                                var rating = AdapterExtensions.ReevaluateFPPMessageRating(this.CurrentMessage);
    2.75 -                                formRegions.FormRegionPrivacyStatus.SetRating(rating);
    2.76 +                                omi = null;
    2.77                              }
    2.78                          }
    2.79                      }
    2.80 @@ -750,7 +763,7 @@
    2.81                              Log.Verbose("DecryptMessage: FormRegionPreviewUnencrypted not visible.");
    2.82                          }
    2.83  
    2.84 -                        formRegions.FormRegionPrivacyStatus?.UpdateFormRegion(true);
    2.85 +                        omi.GetWatchedParentWindow()?.UpdateFormRegion(true);
    2.86                      }
    2.87  
    2.88                      status = Globals.ReturnStatus.Success;
     3.1 --- a/ThisAddIn.cs	Tue Sep 04 11:14:15 2018 +0200
     3.2 +++ b/ThisAddIn.cs	Thu Sep 06 09:29:19 2018 +0200
     3.3 @@ -3,7 +3,6 @@
     3.4  using System;
     3.5  using System.Collections.Generic;
     3.6  using System.ComponentModel;
     3.7 -using System.Diagnostics;
     3.8  using System.Globalization;
     3.9  using System.IO;
    3.10  using System.Runtime.InteropServices;
    3.11 @@ -55,8 +54,11 @@
    3.12          private System.Windows.Forms.Timer  inboxCleaner                = null;
    3.13  
    3.14          private List<WatchedExplorer>       watchedExplorers            = new List<WatchedExplorer>();
    3.15 +        private List<WatchedInspector>      watchedInspectors           = new List<WatchedInspector>();
    3.16          private object                      mutexWatchedExplorers       = new object();
    3.17 +        private object                      mutexWatchedInspectors      = new object();
    3.18          private Outlook.Explorers           explorers                   = null;
    3.19 +        private Outlook.Inspectors          inspectors                  = null;
    3.20  
    3.21          /**************************************************************
    3.22           * 
    3.23 @@ -221,6 +223,18 @@
    3.24          }
    3.25  
    3.26          /// <summary>
    3.27 +        /// Adds a new WatchedInspector to the list of watched inspectors.
    3.28 +        /// </summary>
    3.29 +        /// <param name="watchedInspector">The WatchedInspector to add.</param>
    3.30 +        internal void AddToWatchedInspectors(WatchedInspector watchedInspector)
    3.31 +        {
    3.32 +            lock (mutexWatchedInspectors)
    3.33 +            {
    3.34 +                this.watchedInspectors.Add(watchedInspector);
    3.35 +            }
    3.36 +        }
    3.37 +
    3.38 +        /// <summary>
    3.39          /// Removes a WatchedExplorer from the list of watched explorers.
    3.40          /// </summary>
    3.41          /// <param name="watchedExplorer">The WatchedExplorer to remove.</param>
    3.42 @@ -233,6 +247,124 @@
    3.43          }
    3.44  
    3.45          /// <summary>
    3.46 +        /// Removes a WatchedInspector from the list of watched inspectors.
    3.47 +        /// </summary>
    3.48 +        /// <param name="WatchedInspector">The WatchedInspector to remove.</param>
    3.49 +        internal void RemoveFromWatchedInspectors(WatchedInspector watchedInspector)
    3.50 +        {
    3.51 +            lock (mutexWatchedInspectors)
    3.52 +            {
    3.53 +                this.watchedInspectors.Remove(watchedInspector);
    3.54 +            }
    3.55 +        }
    3.56 +
    3.57 +        /// <summary>
    3.58 +        /// Gets the WatchedExplorer or WatchedInspector in which the given mail item resides.
    3.59 +        /// </summary>
    3.60 +        /// <param name="omi">The Outlook mail item to process with.</param>
    3.61 +        /// <returns>The WatchedExplorer or WatchedInspector the mail item resides in or null if an error occured.</returns>
    3.62 +        internal WatchedWindow GetWatchedParentWindow(Outlook.MailItem omi)
    3.63 +        {
    3.64 +            try
    3.65 +            {
    3.66 +                // First, check all watched explorers
    3.67 +                foreach (var watchedExplorer in this.watchedExplorers)
    3.68 +                {
    3.69 +                    if (watchedExplorer?.CurrentMailItem?.Equals(omi) == true)
    3.70 +                    {
    3.71 +                        return watchedExplorer;
    3.72 +                    }
    3.73 +                }
    3.74 +
    3.75 +                // If window hasn't been found yet, check inspectors
    3.76 +                foreach (var watchedInspector in this.watchedInspectors)
    3.77 +                {
    3.78 +                    if (watchedInspector?.CurrentMailItem?.Equals(omi) == true)
    3.79 +                    {
    3.80 +                        return watchedInspector;
    3.81 +                    }
    3.82 +                }
    3.83 +            }
    3.84 +            catch (Exception ex)
    3.85 +            {
    3.86 +                Log.Error("GetWatchedParentWindow: Error getting window. " + ex.ToString());
    3.87 +            }
    3.88 +
    3.89 +            // If no window has been found, return null
    3.90 +            return null;
    3.91 +        }
    3.92 +
    3.93 +        /// <summary>
    3.94 +        /// Gets the watched window for an Inspector or Explorer object.
    3.95 +        /// </summary>
    3.96 +        /// <param name="window">The Inspector or Explorer window to get its WatchedWindow for.</param>
    3.97 +        /// <returns>The watched window or null if not found.</returns>
    3.98 +        internal WatchedWindow GetWatchedWindow(dynamic window)
    3.99 +        {
   3.100 +            Outlook.Explorer explorer = null;
   3.101 +            Outlook.Inspector inspector = null;
   3.102 +            WatchedWindow watchedWindow = null;
   3.103 +
   3.104 +            try
   3.105 +            {
   3.106 +                // First, try if window is an explorer
   3.107 +                explorer = window as Outlook.Explorer;
   3.108 +                if (explorer != null)
   3.109 +                {
   3.110 +                    if (this.watchedExplorers.Count == 1)
   3.111 +                    {
   3.112 +                        watchedWindow = this.watchedExplorers[0];
   3.113 +                    }
   3.114 +                    else
   3.115 +                    {
   3.116 +                        foreach (var watchedExplorer in this.watchedExplorers)
   3.117 +                        {
   3.118 +                            if (watchedExplorer?.Explorer?.Equals(explorer) == true)
   3.119 +                            {
   3.120 +                                watchedWindow = watchedExplorer;
   3.121 +                                break;
   3.122 +                            }
   3.123 +                        }
   3.124 +                    }
   3.125 +                }
   3.126 +                else
   3.127 +                {
   3.128 +                    // If window is no explorer, try if it is an inspector
   3.129 +                    inspector = window as Outlook.Inspector;
   3.130 +                    if (inspector != null)
   3.131 +                    {
   3.132 +                        if (this.watchedInspectors.Count == 1)
   3.133 +                        {
   3.134 +                            watchedWindow = this.watchedInspectors[0];
   3.135 +                        }
   3.136 +                        else
   3.137 +                        {
   3.138 +                            foreach (var watchedInspector in this.watchedInspectors)
   3.139 +                            {
   3.140 +                                if (watchedInspector?.Inspector?.Equals(inspector) == true)
   3.141 +                                {
   3.142 +                                    watchedWindow = watchedInspector;
   3.143 +                                    break;
   3.144 +                                }
   3.145 +                            }
   3.146 +                        }
   3.147 +                    }
   3.148 +                }
   3.149 +            }
   3.150 +            catch (Exception ex)
   3.151 +            {
   3.152 +                Log.Error("GetWatchedWindow: Error occured. " + ex.ToString());
   3.153 +            }
   3.154 +            finally
   3.155 +            {
   3.156 +                explorer = null;
   3.157 +                inspector = null;
   3.158 +            }
   3.159 +
   3.160 +            return watchedWindow;
   3.161 +        }
   3.162 +        
   3.163 +        /// <summary>
   3.164          /// This updates the accounts list in pEp settings with the ones found in Outlook, adding new accounts and removing
   3.165          /// all accounts that are not there anymore.
   3.166          /// </summary>
   3.167 @@ -513,6 +645,29 @@
   3.168          }
   3.169  
   3.170          /// <summary>
   3.171 +        /// Sends a request to recalculate the message rating of all open windows (except one) again.
   3.172 +        /// </summary>
   3.173 +        /// <param name="windowToExclude">The window to not calculate its rating for</param>
   3.174 +        internal void RecalculateAllWindows(WatchedWindow windowToExclude)
   3.175 +        {
   3.176 +            for (int i = 0; i < this.watchedExplorers.Count; i++)
   3.177 +            {
   3.178 +                if ((windowToExclude as WatchedExplorer)?.Equals(this.watchedExplorers[i]) != true)
   3.179 +                {
   3.180 +                    this.watchedExplorers[i].RequestRatingAndUIUpdate();
   3.181 +                }
   3.182 +            }
   3.183 +
   3.184 +            for (int i = 0; i < this.watchedInspectors.Count; i++)
   3.185 +            {
   3.186 +                if ((windowToExclude as WatchedInspector)?.Equals(this.watchedInspectors[i]) != true)
   3.187 +                {
   3.188 +                    this.watchedInspectors[i].RequestRatingAndUIUpdate();
   3.189 +                }
   3.190 +            }
   3.191 +        }
   3.192 +
   3.193 +        /// <summary>
   3.194          /// Registers each own identity in the pEp engine.
   3.195          /// An own identity represents each account in Outlook.
   3.196          /// </summary>
   3.197 @@ -2515,13 +2670,11 @@
   3.198                      this._OutlookOptions.ReadOptionsFromRegistry();
   3.199                      this._OutlookOptions.SetRegistryValues();
   3.200  
   3.201 -                    // Connect watched folders
   3.202 -                    Log.Info("ThisAddIn_Startup: Connect Watched folders");
   3.203 +                    // Connect watched objects
   3.204 +                    Log.Info("ThisAddIn_Startup: Connect Watched objects");
   3.205                      this.ConnectWatchedFolders();
   3.206 -
   3.207 -                    // Connect watched explorers
   3.208 -                    Log.Info("ThisAddIn_Startup: Connect Watched explorers");
   3.209                      this.ConnectWatchedExplorers(true);
   3.210 +                    this.ConnectWatchedInspectors(true);
   3.211  
   3.212                      // Connect application events
   3.213                      Log.Info("ThisAddIn_Startup: Connect Application Events");
   3.214 @@ -2618,25 +2771,65 @@
   3.215          }
   3.216  
   3.217          /// <summary>
   3.218 -        /// Disconnects all explorer events.
   3.219 -        /// </summary>
   3.220 -        private void DisconnectWatchedExplorers()
   3.221 -        {
   3.222 -            this.explorers.NewExplorer -= Explorers_NewExplorer;
   3.223 -            this.explorers = null;
   3.224 -        }
   3.225 -
   3.226 -        /// <summary>
   3.227          /// Event handler for when a new explorer is being opened and 
   3.228          /// added to the Explorers collection.
   3.229          /// </summary>
   3.230 -        /// <param name="Explorer">The newly opened explorer.</param>
   3.231 +        /// <param name="explorer">The newly opened explorer.</param>
   3.232          private void Explorers_NewExplorer(Outlook.Explorer explorer)
   3.233          {
   3.234              this.AddToWatchedExplorers(new WatchedExplorer(explorer));
   3.235          }
   3.236  
   3.237          /// <summary>
   3.238 +        /// Connects all inspectors with their respective events and the Inspectors collection
   3.239 +        /// with the Newinspector event.
   3.240 +        /// <param name="connect">Whether to connect or disconnect the inspectors.</param>
   3.241 +        /// </summary>
   3.242 +        private void ConnectWatchedInspectors(bool connect)
   3.243 +        {
   3.244 +            try
   3.245 +            {
   3.246 +                if (connect)
   3.247 +                {
   3.248 +                    this.inspectors = this.Application.Inspectors;
   3.249 +
   3.250 +                    for (int i = 1; i <= this.inspectors.Count; i++)
   3.251 +                    {
   3.252 +                        this.watchedInspectors.Add(new WatchedInspector(this.inspectors[i]));
   3.253 +                    }
   3.254 +
   3.255 +                    this.inspectors.NewInspector += Explorers_NewInspector;
   3.256 +                }
   3.257 +                else
   3.258 +                {
   3.259 +                    this.inspectors.NewInspector -= Explorers_NewInspector;
   3.260 +
   3.261 +                    for (int i = 0; i < this.watchedInspectors.Count; i++)
   3.262 +                    {
   3.263 +                        this.RemoveFromWatchedInspectors(this.watchedInspectors[i]);
   3.264 +                        this.watchedInspectors[i].Dispose();
   3.265 +                    }
   3.266 +
   3.267 +                    this.inspectors = null;
   3.268 +                }
   3.269 +            }
   3.270 +            catch (Exception ex)
   3.271 +            {
   3.272 +                Log.Error("ConnectWatchedInspectors: Error occured. " + ex.ToString());
   3.273 +            }
   3.274 +        }
   3.275 +
   3.276 +        /// <summary>
   3.277 +        /// Event handler for when a new inspector is being opened and 
   3.278 +        /// added to the Inspectors collection.
   3.279 +        /// </summary>
   3.280 +        /// <param name="inspector">The newly opened inspector.</param>
   3.281 +        private void Explorers_NewInspector(Outlook.Inspector inspector)
   3.282 +        {
   3.283 +            this.AddToWatchedInspectors(new WatchedInspector(inspector));
   3.284 +        }
   3.285 +
   3.286 +        /// <summary>
   3.287          /// Enables or disables the automatic deletion of old autoconsume messages.
   3.288          /// This gets automatically disabled again if no autoconsume messages are found in the inbox.
   3.289          /// <param name="enable">Whether to enable or disable the automatic cleaning.</param>
   3.290 @@ -2876,6 +3069,7 @@
   3.291  
   3.292              // Disconnect watched items
   3.293              this.ConnectWatchedExplorers(false);
   3.294 +            this.ConnectWatchedInspectors(false);
   3.295  
   3.296              // Save configuration
   3.297              this._Settings.SaveToRegistry();
     4.1 --- a/UI/FormControlPreviewMessage.xaml.cs	Tue Sep 04 11:14:15 2018 +0200
     4.2 +++ b/UI/FormControlPreviewMessage.xaml.cs	Thu Sep 06 09:29:19 2018 +0200
     4.3 @@ -352,8 +352,8 @@
     4.4                              // Update UI
     4.5                              try
     4.6                              {
     4.7 -                                WindowFormRegionCollection formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveWindow()];
     4.8 -                                formRegions?.FormRegionPrivacyStatus?.SetRating(pEpCOMServerAdapterLib.pEpRating.pEpRatingUnencrypted);
     4.9 +                                WatchedWindow watchedWindow = Globals.ThisAddIn.GetWatchedWindow(Globals.ThisAddIn.Application.ActiveWindow());
    4.10 +                                watchedWindow.SetRating(pEpCOMServerAdapterLib.pEpRating.pEpRatingUndefined);
    4.11                              }
    4.12                              catch (Exception ex)
    4.13                              {
     5.1 --- a/UI/FormRegionPreviewUnencrypted.cs	Tue Sep 04 11:14:15 2018 +0200
     5.2 +++ b/UI/FormRegionPreviewUnencrypted.cs	Thu Sep 06 09:29:19 2018 +0200
     5.3 @@ -337,24 +337,8 @@
     5.4                  // Decrypt the current mail item
     5.5                  omi = this.OutlookItem as Outlook.MailItem;
     5.6  
     5.7 -                // Try to get the mirror from the FormRegionPrivacyStatus
     5.8 -                try
     5.9 -                {
    5.10 -                    WindowFormRegionCollection formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveWindow()];
    5.11 -                    if (this.Equals(formRegions.FormRegionPreviewUnencrypted))
    5.12 -                    {
    5.13 -                        decryptedMessage = formRegions.FormRegionPrivacyStatus?.Mirror;
    5.14 -                    }                   
    5.15 -                }
    5.16 -                catch (Exception ex)
    5.17 -                {
    5.18 -                    decryptedMessage = null;
    5.19 -                    Log.Error("CreateResponseItem: Error getting mirror from FormRegionPrivacyStatus. " + ex.ToString());
    5.20 -                }
    5.21 -
    5.22                  // Use mirror or create it from original
    5.23 -                if ((decryptedMessage != null) ||
    5.24 -                    ((PEPMessage.Create(omi, out message) == Globals.ReturnStatus.Success) &&
    5.25 +                if (((PEPMessage.Create(omi, out message) == Globals.ReturnStatus.Success) &&
    5.26                       (msgProcessor.Decrypt(message, out decryptedMessage))))
    5.27                  {
    5.28                      // Create reply of current item
     6.1 --- a/UI/RibbonCustomizations.cs	Tue Sep 04 11:14:15 2018 +0200
     6.2 +++ b/UI/RibbonCustomizations.cs	Thu Sep 06 09:29:19 2018 +0200
     6.3 @@ -24,6 +24,23 @@
     6.4           */
     6.5          private static Office.IRibbonUI ribbon;
     6.6  
     6.7 +        private static bool        DISABLE_FORCE_PROTECTION_DEFAULT    = false;
     6.8 +        private static bool        FORCE_PROTECTION_DEFAULT            = false;
     6.9 +        private static bool        FORCE_UNENCRYPTED_DEFAULT           = false;
    6.10 +        private static bool        IS_DRAFT_DEFAULT                    = false;
    6.11 +        private static bool        NEVER_UNSECURE_DEFAULT              = false;
    6.12 +        private static pEpRating   RATING_DEFAULT                      = pEpRating.pEpRatingUndefined;
    6.13 +
    6.14 +        private enum MessageProperties
    6.15 +        {
    6.16 +            DisableForceProtection,
    6.17 +            ForceProtection,
    6.18 +            ForceUnencrypted,
    6.19 +            IsDraft,
    6.20 +            NeverUnsecure,
    6.21 +            Rating
    6.22 +        }
    6.23 +
    6.24          /**************************************************************
    6.25           * 
    6.26           * Constructors
    6.27 @@ -50,7 +67,7 @@
    6.28          /// <returns>True if the Force Protection option is disabled for the current mail item, otherwise false.</returns>
    6.29          internal bool GetDisableForceProtection(Office.IRibbonControl control)
    6.30          {
    6.31 -            return this.GetFormRegionPrivacyStatus(control)?.DisableForceProtection ?? false;
    6.32 +            return RibbonCustomizations.GetRibbonProperty(control, MessageProperties.DisableForceProtection);
    6.33          }
    6.34  
    6.35          /// <summary>
    6.36 @@ -62,7 +79,7 @@
    6.37          {
    6.38              try
    6.39              {
    6.40 -                this.GetFormRegionPrivacyStatus(control).DisableForceProtection = disable;
    6.41 +                RibbonCustomizations.SetRibbonProperty(control, MessageProperties.DisableForceProtection, disable);
    6.42              }
    6.43              catch (Exception ex)
    6.44              {
    6.45 @@ -77,7 +94,7 @@
    6.46          /// <returns>True if the current mail item is forcefully protected, otherwise false.</returns>
    6.47          internal bool GetForceProtection(Office.IRibbonControl control)
    6.48          {
    6.49 -            return this.GetFormRegionPrivacyStatus(control)?.ForceProtection ?? false;
    6.50 +            return RibbonCustomizations.GetRibbonProperty(control, MessageProperties.ForceProtection);
    6.51          }
    6.52  
    6.53          /// <summary>
    6.54 @@ -89,7 +106,7 @@
    6.55          {
    6.56              try
    6.57              {
    6.58 -                this.GetFormRegionPrivacyStatus(control).ForceProtection = forceProtection;
    6.59 +                RibbonCustomizations.SetRibbonProperty(control, MessageProperties.ForceProtection, forceProtection);
    6.60              }
    6.61              catch (Exception ex)
    6.62              {
    6.63 @@ -104,7 +121,7 @@
    6.64          /// <returns>True if the current mail item is forcefully unencrypted, otherwise false.</returns>
    6.65          internal bool GetForceUnencrypted(Office.IRibbonControl control)
    6.66          {
    6.67 -            return this.GetFormRegionPrivacyStatus(control)?.ForceUnencrypted ?? false;
    6.68 +            return RibbonCustomizations.GetRibbonProperty(control, MessageProperties.ForceUnencrypted);
    6.69          }
    6.70  
    6.71          /// <summary>
    6.72 @@ -116,7 +133,7 @@
    6.73          {
    6.74              try
    6.75              {
    6.76 -                this.GetFormRegionPrivacyStatus(control).ForceUnencrypted = forceUnencrypted;
    6.77 +                RibbonCustomizations.SetRibbonProperty(control, MessageProperties.ForceUnencrypted, forceUnencrypted);
    6.78              }
    6.79              catch (Exception ex)
    6.80              {
    6.81 @@ -131,19 +148,19 @@
    6.82          /// <returns>True if the current mail item has the Never Unsecure option set, otherwise false.</returns>
    6.83          internal bool GetNeverUnsecure(Office.IRibbonControl control)
    6.84          {
    6.85 -            return this.GetFormRegionPrivacyStatus(control)?.NeverUnsecure ?? false;
    6.86 +            return RibbonCustomizations.GetRibbonProperty(control, MessageProperties.NeverUnsecure);
    6.87          }
    6.88  
    6.89          /// <summary>
    6.90          /// Sets whether the current mail item should be forcefully unencrypted or not.
    6.91          /// </summary>
    6.92          /// <param name="control">The current button control.</param>
    6.93 -        /// <param name="neverUnsecure">Whether to enable Force Unencrypted or not.</param>
    6.94 +        /// <param name="neverUnsecure">Whether to enable Never Unsecure or not.</param>
    6.95          internal void SetNeverUnsecure(Office.IRibbonControl control, bool neverUnsecure)
    6.96          {
    6.97              try
    6.98              {
    6.99 -                this.GetFormRegionPrivacyStatus(control).NeverUnsecure = neverUnsecure;
   6.100 +                RibbonCustomizations.SetRibbonProperty(control, MessageProperties.NeverUnsecure, neverUnsecure);
   6.101              }
   6.102              catch (Exception ex)
   6.103              {
   6.104 @@ -158,7 +175,7 @@
   6.105          /// <returns>The pEpRating of the current message or undefined if an error occured.</returns>
   6.106          private pEpRating GetRating(Office.IRibbonControl control)
   6.107          {
   6.108 -            return this.GetFormRegionPrivacyStatus(control)?.Rating ?? pEpRating.pEpRatingUndefined;
   6.109 +            return RibbonCustomizations.GetRibbonProperty(control, MessageProperties.Rating);
   6.110          }
   6.111  
   6.112          /**************************************************************
   6.113 @@ -176,6 +193,87 @@
   6.114              RibbonCustomizations.ribbon?.Invalidate();
   6.115          }
   6.116  
   6.117 +        private static dynamic GetRibbonProperty(Office.IRibbonControl control, MessageProperties property)
   6.118 +        {
   6.119 +            WatchedWindow window = Globals.ThisAddIn?.GetWatchedWindow(control?.Context);
   6.120 +
   6.121 +            switch (property)
   6.122 +            {
   6.123 +                case MessageProperties.DisableForceProtection:
   6.124 +                    {
   6.125 +                        return window?.DisableForceProtection ?? RibbonCustomizations.DISABLE_FORCE_PROTECTION_DEFAULT;
   6.126 +                    }
   6.127 +                case MessageProperties.ForceProtection:
   6.128 +                    {
   6.129 +                        return window?.ForceProtection ?? RibbonCustomizations.FORCE_PROTECTION_DEFAULT;
   6.130 +                    }
   6.131 +                case MessageProperties.ForceUnencrypted:
   6.132 +                    {
   6.133 +                        return window?.ForceUnencrypted ?? RibbonCustomizations.FORCE_UNENCRYPTED_DEFAULT;
   6.134 +                    }
   6.135 +                case MessageProperties.IsDraft:
   6.136 +                    {
   6.137 +                        return window?.IsDraft ?? RibbonCustomizations.IS_DRAFT_DEFAULT;
   6.138 +                    }
   6.139 +                case MessageProperties.NeverUnsecure:
   6.140 +                    {
   6.141 +                        return window?.NeverUnsecure ?? RibbonCustomizations.NEVER_UNSECURE_DEFAULT;
   6.142 +                    }
   6.143 +                case MessageProperties.Rating:
   6.144 +                    {
   6.145 +                        return window?.Rating ?? RibbonCustomizations.RATING_DEFAULT;
   6.146 +                    }
   6.147 +                default:
   6.148 +                    break;
   6.149 +            }
   6.150 +
   6.151 +            return null;
   6.152 +        }
   6.153 +
   6.154 +        private static void SetRibbonProperty(Office.IRibbonControl control, MessageProperties property, dynamic value)
   6.155 +        {
   6.156 +            WatchedWindow window = Globals.ThisAddIn?.GetWatchedWindow(control.Context);
   6.157 +
   6.158 +            if (window != null)
   6.159 +            {
   6.160 +                switch (property)
   6.161 +                {
   6.162 +                    case MessageProperties.DisableForceProtection:
   6.163 +                        {
   6.164 +                            window.DisableForceProtection = (bool)value;
   6.165 +                        }
   6.166 +                        break;
   6.167 +                    case MessageProperties.ForceProtection:
   6.168 +                        {
   6.169 +                            window.ForceProtection = (bool)value;
   6.170 +                        }
   6.171 +                        break;
   6.172 +                    case MessageProperties.ForceUnencrypted:
   6.173 +                        {
   6.174 +                            window.ForceUnencrypted = (bool)value;
   6.175 +                        }
   6.176 +                        break;
   6.177 +                    case MessageProperties.IsDraft:
   6.178 +                        {
   6.179 +                            window.IsDraft = (bool)value;
   6.180 +                        }
   6.181 +                        break;
   6.182 +                    case MessageProperties.NeverUnsecure:
   6.183 +                        {
   6.184 +                            window.NeverUnsecure = (bool)value;
   6.185 +                        }
   6.186 +                        break;
   6.187 +                    case MessageProperties.Rating:
   6.188 +                        {
   6.189 +                            window.SetRating((pEpRating)value);
   6.190 +                        }
   6.191 +                        break;
   6.192 +                    default:
   6.193 +                        break;
   6.194 +                }
   6.195 +            }
   6.196 +        }
   6.197 +
   6.198          /// <summary>
   6.199          /// Gets the Outlook contact item that is associated with a given control's parent
   6.200          /// window (Inspector / Explorer). Can return null.
   6.201 @@ -252,44 +350,6 @@
   6.202          }
   6.203  
   6.204          /// <summary>
   6.205 -        /// Gets the FormRegionPrivacyStatus that is associated with a given control's parent
   6.206 -        /// window (Inspector / Explorer). Can return null.
   6.207 -        /// </summary>
   6.208 -        /// <param name="control">The control to get the associated form region for.</param>
   6.209 -        /// <returns>The associated FormRegionPrivacyStatus or null if an error occured.</returns>
   6.210 -        private FormRegionPrivacyStatus GetFormRegionPrivacyStatus(Office.IRibbonControl control)
   6.211 -        {
   6.212 -            dynamic window = null;
   6.213 -            FormRegionPrivacyStatus formRegion = null;
   6.214 -
   6.215 -            try
   6.216 -            {
   6.217 -                // Get the parent window
   6.218 -                window = control.Context as Outlook.Explorer;
   6.219 -                if (window == null)
   6.220 -                {
   6.221 -                    window = control.Context as Outlook.Inspector;
   6.222 -                }
   6.223 -
   6.224 -                if (window != null)
   6.225 -                {
   6.226 -                    formRegion = Globals.FormRegions[window].FormRegionPrivacyStatus;
   6.227 -                }
   6.228 -            }
   6.229 -            catch (Exception ex)
   6.230 -            {
   6.231 -                formRegion = null;
   6.232 -                Log.Error("GetFormRegionPrivacyStatus: Error getting form region. " + ex.ToString());
   6.233 -            }
   6.234 -            finally
   6.235 -            {
   6.236 -                window = null;
   6.237 -            }
   6.238 -
   6.239 -            return formRegion;
   6.240 -        }
   6.241 -
   6.242 -        /// <summary>
   6.243          /// Gets the Outlook mail item that is associated with a given control's parent
   6.244          /// window (Inspector / Explorer). Can return null.
   6.245          /// </summary>
   6.246 @@ -567,11 +627,11 @@
   6.247                                  // Update UI
   6.248                                  if (string.IsNullOrEmpty(value as string))
   6.249                                  {
   6.250 -                                    this.GetFormRegionPrivacyStatus(control)?.RequestRatingAndUIUpdate();
   6.251 +                                    Globals.ThisAddIn.GetWatchedWindow(control.Context)?.RequestRatingAndUIUpdate();
   6.252                                  }
   6.253                                  else
   6.254                                  {
   6.255 -                                    this.GetFormRegionPrivacyStatus(control)?.SetRating(pEpRating.pEpRatingReliable);
   6.256 +                                    Globals.ThisAddIn.GetWatchedWindow(control.Context)?.SetRating(pEpRating.pEpRatingReliable);
   6.257                                  }
   6.258                                  break;
   6.259                              }
   6.260 @@ -606,7 +666,7 @@
   6.261                                      omi.SetPEPProperty(MailItemExtensions.PEPProperty.EnableProtection, value);
   6.262  
   6.263                                      // Update UI
   6.264 -                                    this.GetFormRegionPrivacyStatus(control)?.RequestRatingAndUIUpdate();
   6.265 +                                    Globals.ThisAddIn.GetWatchedWindow(control.Context)?.RequestRatingAndUIUpdate();
   6.266                                  }
   6.267  
   6.268                                  break;
   6.269 @@ -768,7 +828,7 @@
   6.270              try
   6.271              {
   6.272                  Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
   6.273 -                this.GetFormRegionPrivacyStatus(control)?.BuildAndShowManager();
   6.274 +                Globals.ThisAddIn.GetWatchedWindow(control.Context)?.BuildAndShowManager();
   6.275              }
   6.276              catch (Exception ex)
   6.277              {
   6.278 @@ -911,7 +971,7 @@
   6.279          /// </summary>
   6.280          public string ButtonPrivacyStatus_GetScreentip(Office.IRibbonControl control)
   6.281          {
   6.282 -            return Properties.Resources.PrivacyStatus_FormText;            
   6.283 +            return Properties.Resources.PrivacyStatus_FormText;
   6.284          }
   6.285  
   6.286          /// <summary>
   6.287 @@ -946,7 +1006,7 @@
   6.288                          {
   6.289                              omi = this.GetMailItem(control);
   6.290                              visible = ((omi?.GetIsDraft() == true) ||
   6.291 -                                       (this.GetIsDecryptAlwaysEnabled(control)));                     
   6.292 +                                       (this.GetIsDecryptAlwaysEnabled(control)));
   6.293                          }
   6.294                      }
   6.295                  }
   6.296 @@ -970,7 +1030,7 @@
   6.297          public void ButtonSMIME_Clicked(Office.IRibbonControl control, bool pressed, ref bool cancel)
   6.298          {
   6.299              cancel = false;
   6.300 -            this.GetFormRegionPrivacyStatus(control)?.RequestRatingAndUIUpdate();
   6.301 +            Globals.ThisAddIn.GetWatchedWindow(control.Context)?.RequestRatingAndUIUpdate();
   6.302          }
   6.303  
   6.304          ///////////////////////////////////////////////////////////
   6.305 @@ -1002,13 +1062,13 @@
   6.306              /* The button is disabled if
   6.307               *  - Rating is lower than reliable
   6.308               *  - Force Protection or Never Unsecure are enabled and not overridden
   6.309 -             */ 
   6.310 +             */
   6.311              if (((this.GetRating(control) < pEpRating.pEpRatingReliable) ||
   6.312                   (this.GetNeverUnsecure(control))) ||
   6.313                   ((this.GetForceProtection(control)) && (this.GetDisableForceProtection(control) == false)))
   6.314              {
   6.315                  return false;
   6.316 -            }            
   6.317 +            }
   6.318              else
   6.319              {
   6.320                  return true;
   6.321 @@ -1149,7 +1209,7 @@
   6.322  
   6.323              if (this.GetIsPEPEnabled(control))
   6.324              {
   6.325 -                enabled = ((this.GetRating(control) == pEpRating.pEpRatingUnencrypted) && 
   6.326 +                enabled = ((this.GetRating(control) == pEpRating.pEpRatingUnencrypted) &&
   6.327                             (this.GetForceUnencrypted(control) == false));
   6.328              }
   6.329              else
   6.330 @@ -1174,7 +1234,7 @@
   6.331          /// </summary>
   6.332          public bool ToggleButtonForceProtection_GetPressed(Office.IRibbonControl control)
   6.333          {
   6.334 -            return ((this.GetForceProtection(control)) && 
   6.335 +            return ((this.GetForceProtection(control)) &&
   6.336                      (this.GetDisableForceProtection(control) == false));
   6.337          }
   6.338  
   6.339 @@ -1214,9 +1274,9 @@
   6.340          public bool ToggleButtonNeverUnsecure_GetEnabled(Office.IRibbonControl control)
   6.341          {
   6.342              // Enabled if not forcefully unencrypted, rating >= Reliable (or force protection), no S/MIME enabled and no BCC recipients
   6.343 -             return (((this.GetRating(control) >= pEpRating.pEpRatingReliable) || (this.GetForceProtection(control)) && (this.ToggleButtonForceProtection_GetEnabled(control))) &&
   6.344 -                     (this.GetForceUnencrypted(control) == false) &&
   6.345 -                     (this.GetIsSMIMEEnabled(control) == false));
   6.346 +            return (((this.GetRating(control) >= pEpRating.pEpRatingReliable) || (this.GetForceProtection(control)) && (this.ToggleButtonForceProtection_GetEnabled(control))) &&
   6.347 +                    (this.GetForceUnencrypted(control) == false) &&
   6.348 +                    (this.GetIsSMIMEEnabled(control) == false));
   6.349          }
   6.350  
   6.351          /// <summary>
   6.352 @@ -1491,7 +1551,7 @@
   6.353                  if (explorer != null)
   6.354                  {
   6.355                      visible = (explorer.ActiveInlineResponse == null);
   6.356 -                }                
   6.357 +                }
   6.358              }
   6.359              catch (Exception ex)
   6.360              {
   6.361 @@ -1642,7 +1702,7 @@
   6.362              switch (ribbonID)
   6.363              {
   6.364                  case "Microsoft.Outlook.Explorer":
   6.365 -                    if (Globals.OutlookVersion == Globals.Version.Outlook2010 )
   6.366 +                    if (Globals.OutlookVersion == Globals.Version.Outlook2010)
   6.367                      {
   6.368                          return GetResourceText("pEp.UI.RibbonCustomizationsExplorer2010.xml");
   6.369                      }
     7.1 --- a/Wrappers/WatchedExplorer.cs	Tue Sep 04 11:14:15 2018 +0200
     7.2 +++ b/Wrappers/WatchedExplorer.cs	Thu Sep 06 09:29:19 2018 +0200
     7.3 @@ -6,10 +6,12 @@
     7.4      /// <summary>
     7.5      /// Stores an Outlook Explorer with connected events.
     7.6      /// </summary>
     7.7 -    public class WatchedExplorer : IDisposable
     7.8 +    public class WatchedExplorer : WatchedWindow
     7.9      {
    7.10 -        private Outlook.Explorer                explorer                   = null;
    7.11 -        private CryptableMailItem               inlineResponseItem         = null;
    7.12 +        private Outlook.Explorer        _Explorer               = null;
    7.13 +
    7.14 +        private string                  lastProcessedEntryId    = null;
    7.15 +        private CryptableMailItem       inlineResponseItem      = null;
    7.16  
    7.17          /**************************************************************
    7.18           * 
    7.19 @@ -23,23 +25,36 @@
    7.20          /// <param name="explorer">The explorer to watch.</param>
    7.21          public WatchedExplorer(Outlook.Explorer explorer)
    7.22          {
    7.23 -            this.explorer = explorer;
    7.24 +            this._Explorer = explorer;
    7.25  
    7.26 -            if (this.explorer != null)
    7.27 +            if (this._Explorer != null)
    7.28              {
    7.29                  this.ConnectWatchedExplorerEvents(true);
    7.30              }
    7.31          }
    7.32  
    7.33 +        #region Properties
    7.34 +
    7.35          /// <summary>
    7.36 -        /// Destructor.
    7.37 +        /// Gets the Explorer that is wrapped by this WatchedExplorer.
    7.38          /// </summary>
    7.39 -        ~WatchedExplorer()
    7.40 +        public Outlook.Explorer Explorer
    7.41          {
    7.42 -            this.Dispose(true);
    7.43 +            get { return this._Explorer; }
    7.44          }
    7.45  
    7.46 +        /// <summary>
    7.47 +        /// Gets the Explorer that is wrapped by this WatchedExplorer.
    7.48 +        /// </summary>
    7.49 +        public override dynamic Window
    7.50 +        {
    7.51 +            get { return this.Explorer; }
    7.52 +        }
    7.53 +
    7.54 +        #endregion
    7.55 +
    7.56          #region Methods
    7.57 +
    7.58          /**************************************************************
    7.59           * 
    7.60           * Methods
    7.61 @@ -47,18 +62,10 @@
    7.62           *************************************************************/
    7.63  
    7.64          /// <summary>
    7.65 -        /// Releases all resources and disconnects internal events.
    7.66 -        /// </summary>
    7.67 -        public void Dispose()
    7.68 -        {
    7.69 -            this.Dispose(true);
    7.70 -        }
    7.71 -
    7.72 -        /// <summary>
    7.73          /// Clean up any resources being used.
    7.74          /// </summary>
    7.75          /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    7.76 -        protected virtual void Dispose(bool disposing)
    7.77 +        protected override void Dispose(bool disposing)
    7.78          {
    7.79              if (disposing)
    7.80              {
    7.81 @@ -66,9 +73,10 @@
    7.82                  this.ConnectWatchedExplorerEvents(false);
    7.83  
    7.84                  // Set Outlook objects to null
    7.85 -                this.explorer = null;
    7.86 -                this.inlineResponseItem?.Dispose();
    7.87 -                this.inlineResponseItem = null;
    7.88 +                this._Explorer = null;
    7.89 +
    7.90 +                // Dispose base class
    7.91 +                base.Dispose(disposing);
    7.92              }
    7.93          }
    7.94  
    7.95 @@ -82,13 +90,15 @@
    7.96              {
    7.97                  if (connect)
    7.98                  {
    7.99 -                    ((Outlook.ExplorerEvents_10_Event)this.explorer).Close += Explorer_Close;
   7.100 -                    ((Outlook.ExplorerEvents_10_Event)this.explorer).InlineResponseClose += Explorer_InlineResponseClose;
   7.101 +                    ((Outlook.ExplorerEvents_10_Event)this._Explorer).Close += Explorer_Close;
   7.102 +                    ((Outlook.ExplorerEvents_10_Event)this._Explorer).InlineResponseClose += Explorer_InlineResponseClose;
   7.103 +                    ((Outlook.ExplorerEvents_10_Event)this._Explorer).SelectionChange += Explorer_SelectionChange;
   7.104                  }
   7.105                  else
   7.106                  {
   7.107 -                    ((Outlook.ExplorerEvents_10_Event)this.explorer).Close -= Explorer_Close;
   7.108 -                    ((Outlook.ExplorerEvents_10_Event)this.explorer).InlineResponseClose -= Explorer_InlineResponseClose;
   7.109 +                    ((Outlook.ExplorerEvents_10_Event)this._Explorer).Close -= Explorer_Close;
   7.110 +                    ((Outlook.ExplorerEvents_10_Event)this._Explorer).InlineResponseClose -= Explorer_InlineResponseClose;
   7.111 +                    ((Outlook.ExplorerEvents_10_Event)this._Explorer).SelectionChange -= Explorer_SelectionChange;
   7.112                  }
   7.113              }
   7.114              catch (Exception ex)
   7.115 @@ -96,7 +106,6 @@
   7.116                  Log.Error("ConnectWatchedExplorerEvents: Error occured. " + ex.ToString());
   7.117              }
   7.118          }
   7.119 -
   7.120          #endregion
   7.121  
   7.122          #region Event Handling
   7.123 @@ -127,10 +136,10 @@
   7.124               * securely instead of to the server's draft folder.
   7.125               * Note: the form region's CMI is already disposed at this point,
   7.126               * so that its Write event will never be called.
   7.127 -             */ 
   7.128 +             */
   7.129              try
   7.130              {
   7.131 -                omi = this.explorer?.ActiveInlineResponse as Outlook.MailItem;
   7.132 +                omi = this._Explorer?.ActiveInlineResponse as Outlook.MailItem;
   7.133  
   7.134                  if (omi != null)
   7.135                  {
   7.136 @@ -148,6 +157,77 @@
   7.137              }
   7.138          }
   7.139  
   7.140 +        private void Explorer_SelectionChange()
   7.141 +        {
   7.142 +            Outlook.Selection selection = null;
   7.143 +            try
   7.144 +            {
   7.145 +                // Process the newly selected item
   7.146 +                selection = this._Explorer.Selection;
   7.147 +
   7.148 +                /* Do only process the item if one individual item is selected.
   7.149 +                 * Do not process a selected range of items.
   7.150 +                 */
   7.151 +                if (selection.Count == 1)
   7.152 +                {
   7.153 +                    this.CurrentMailItem = selection[1] as Outlook.MailItem;
   7.154 +                    if (this.CurrentMailItem != null)
   7.155 +                    {
   7.156 +                        // Check if inline response
   7.157 +                        Outlook.MailItem inlineResponse = null;
   7.158 +                        bool isInlineResponse = false;
   7.159 +                        try
   7.160 +                        {
   7.161 +                            inlineResponse = this._Explorer?.ActiveInlineResponse as Outlook.MailItem;
   7.162 +                            if (inlineResponse != null)
   7.163 +                            {
   7.164 +                                isInlineResponse = true;
   7.165 +                                this.CurrentMailItem = inlineResponse;
   7.166 +                            }
   7.167 +                        }
   7.168 +                        catch (Exception ex)
   7.169 +                        {
   7.170 +                            Log.Error("Explorer_SelectionChange: Error determining whether it is an inline response. " + ex.ToString());
   7.171 +                        }
   7.172 +                        finally
   7.173 +                        {
   7.174 +                            inlineResponse = null;
   7.175 +                        }
   7.176 +
   7.177 +                        /* If a different mail is clicked in an Window, the SelectionChange
   7.178 +                         * event is always called twice. To prevent a double processing, we only
   7.179 +                         * process a mail item if it is different from the last one that has been
   7.180 +                         * processed.
   7.181 +                         */
   7.182 +                        string entryId = isInlineResponse ? null : this.CurrentMailItem?.EntryID;
   7.183 +                        if (entryId?.Equals(lastProcessedEntryId, StringComparison.InvariantCultureIgnoreCase) == true)
   7.184 +                        {
   7.185 +                            Log.Verbose("Explorer_SelectionChange: Same EntryId as last item. Skipped processing of item with EntryId " + entryId);
   7.186 +                            return;
   7.187 +                        }
   7.188 +                        else
   7.189 +                        {
   7.190 +                            this.lastProcessedEntryId = entryId;
   7.191 +                        }
   7.192 +
   7.193 +                        // Initialize mail item
   7.194 +                        this.InitializeMailItem(isInlineResponse);
   7.195 +                    }
   7.196 +                    else
   7.197 +                    {
   7.198 +                        Log.Error("Explorer_SelectionChange: Error getting current mail item.");
   7.199 +                    }
   7.200 +                }
   7.201 +            }
   7.202 +            catch (Exception e)
   7.203 +            {
   7.204 +                Log.Error("Explorer_SelectionChange: Error. " + e.Message);
   7.205 +            }
   7.206 +            finally
   7.207 +            {
   7.208 +                selection = null;
   7.209 +            }
   7.210 +        }
   7.211          #endregion
   7.212      }
   7.213  }
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/Wrappers/WatchedInspector.cs	Thu Sep 06 09:29:19 2018 +0200
     8.3 @@ -0,0 +1,142 @@
     8.4 +´╗┐using System;
     8.5 +using Outlook = Microsoft.Office.Interop.Outlook;
     8.6 +
     8.7 +namespace pEp
     8.8 +{
     8.9 +    /// <summary>
    8.10 +    /// Stores an Outlook Explorer with connected events.
    8.11 +    /// </summary>
    8.12 +    public class WatchedInspector : WatchedWindow
    8.13 +    {
    8.14 +        private Outlook.Inspector   _Inspector      = null;
    8.15 +
    8.16 +        /**************************************************************
    8.17 +         * 
    8.18 +         * Constructors/Destructors
    8.19 +         * 
    8.20 +         *************************************************************/
    8.21 +
    8.22 +        /// <summary>
    8.23 +        /// Primary constructor.
    8.24 +        /// </summary>
    8.25 +        /// <param name="inspector">The inspector to watch.</param>
    8.26 +        public WatchedInspector(Outlook.Inspector inspector)
    8.27 +        {
    8.28 +            this._Inspector = inspector;
    8.29 +
    8.30 +            if (this._Inspector != null)
    8.31 +            {
    8.32 +                this.ConnectWatchedInspectorEvents();
    8.33 +
    8.34 +                // Set mail item
    8.35 +                this.CurrentMailItem = this._Inspector.CurrentItem as Outlook.MailItem;
    8.36 +
    8.37 +                if (this.CurrentMailItem != null)
    8.38 +                {
    8.39 +                    this.InitializeMailItem();
    8.40 +                }
    8.41 +                else
    8.42 +                {
    8.43 +                    Log.Error("WatchedInspector: Error getting current mail item.");
    8.44 +                }
    8.45 +            }
    8.46 +        }
    8.47 +
    8.48 +        #region Properties
    8.49 +        /// <summary>
    8.50 +        /// Gets the Inspector that is wrapped by this WatchedInspector
    8.51 +        /// </summary>
    8.52 +        public Outlook.Inspector Inspector
    8.53 +        {
    8.54 +            get { return this._Inspector; }
    8.55 +        }
    8.56 +
    8.57 +        /// <summary>
    8.58 +        /// Gets the Explorer that is wrapped by this WatchedExplorer.
    8.59 +        /// </summary>
    8.60 +        public override dynamic Window
    8.61 +        {
    8.62 +            get { return this.Inspector; }
    8.63 +        }
    8.64 +        #endregion
    8.65 +
    8.66 +        #region Methods
    8.67 +        /**************************************************************
    8.68 +         * 
    8.69 +         * Methods
    8.70 +         * 
    8.71 +         *************************************************************/
    8.72 +
    8.73 +        /// <summary>
    8.74 +        /// Clean up any resources being used.
    8.75 +        /// </summary>
    8.76 +        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    8.77 +        protected override void Dispose(bool disposing)
    8.78 +        {
    8.79 +            if (disposing &&
    8.80 +                this._Inspector != null)
    8.81 +            {
    8.82 +                // Disconnect all events
    8.83 +                this.DisconnectWatchedInspectorEvents();
    8.84 +
    8.85 +                // Set Outlook objects to null
    8.86 +                this._Inspector = null;
    8.87 +
    8.88 +                // Dispose base class
    8.89 +                base.Dispose();
    8.90 +            }
    8.91 +        }
    8.92 +
    8.93 +        /// <summary>
    8.94 +        /// Connects the events for this watched explorer
    8.95 +        /// </summary>
    8.96 +        private void ConnectWatchedInspectorEvents()
    8.97 +        {
    8.98 +            if (this._Inspector != null)
    8.99 +            {
   8.100 +                ((Outlook.InspectorEvents_10_Event)this._Inspector).Close += WatchedInspector_Close;
   8.101 +            }
   8.102 +        }
   8.103 +
   8.104 +        /// <summary>
   8.105 +        /// Disconnects the events from this watched explorer
   8.106 +        /// </summary>
   8.107 +        private void DisconnectWatchedInspectorEvents()
   8.108 +        {
   8.109 +            if (this._Inspector != null)
   8.110 +            {
   8.111 +                ((Outlook.InspectorEvents_10_Event)this._Inspector).Close -= WatchedInspector_Close;
   8.112 +
   8.113 +            }
   8.114 +        }
   8.115 +
   8.116 +        #endregion
   8.117 +
   8.118 +        #region Event Handling
   8.119 +        /**************************************************************
   8.120 +         * 
   8.121 +         * Event Handling
   8.122 +         * 
   8.123 +         *************************************************************/
   8.124 +
   8.125 +        /// <summary>
   8.126 +        /// Event handler for when a watched inspector is being closed.
   8.127 +        /// </summary>
   8.128 +        private void WatchedInspector_Close()
   8.129 +        {
   8.130 +            Globals.ThisAddIn.RemoveFromWatchedInspectors(this);
   8.131 +
   8.132 +            this.Dispose();
   8.133 +        }
   8.134 +
   8.135 +        /// <summary>
   8.136 +        /// Event handler for when the processing of an item in the WatchedInspector has finished.
   8.137 +        /// </summary>
   8.138 +        private void Inspector_ProcessingCompleted(object sender, MsgProcessor.ProcessingCompletedEventArgs e)
   8.139 +        {
   8.140 +            throw new NotImplementedException();
   8.141 +        }
   8.142 +
   8.143 +        #endregion
   8.144 +    }
   8.145 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/Wrappers/WatchedWindow.cs	Thu Sep 06 09:29:19 2018 +0200
     9.3 @@ -0,0 +1,1428 @@
     9.4 +´╗┐using pEp.UI;
     9.5 +using pEpCOMServerAdapterLib;
     9.6 +using System;
     9.7 +using System.ComponentModel;
     9.8 +using System.Windows.Forms;
     9.9 +using Outlook = Microsoft.Office.Interop.Outlook;
    9.10 +
    9.11 +namespace pEp
    9.12 +{
    9.13 +    /// <summary>
    9.14 +    /// Stores an Outlook Window with connected events.
    9.15 +    /// </summary>
    9.16 +    public abstract class WatchedWindow : IDisposable
    9.17 +    {
    9.18 +        private CryptableMailItem               cryptableMailItem           = null;
    9.19 +        private bool                            displayMirrorRequested      = false;
    9.20 +        private HandshakeDialog                 handshakeDialog             = null;
    9.21 +        private bool                            isEnabled                   = true;
    9.22 +        private bool                            isStarted                   = false;
    9.23 +        private bool                            processingOngoing           = false;
    9.24 +        private bool                            refreshOngoing              = false;
    9.25 +        private bool                            repeatProcessing            = false;
    9.26 +        private int                             repeatCounter               = 0;
    9.27 +        private const int                       maxRepeatCount              = 5;
    9.28 +
    9.29 +        private Outlook.MailItem                _CurrentMailItem            = null;
    9.30 +
    9.31 +        public enum WindowTypes
    9.32 +        {
    9.33 +            Undefined,
    9.34 +            Inspector,
    9.35 +            Explorer
    9.36 +        }
    9.37 +
    9.38 +        #region Properties
    9.39 +        /// <summary>
    9.40 +        /// The rating of the currently selected message.
    9.41 +        /// </summary>
    9.42 +        private pEpRating _Rating = pEpRating.pEpRatingUndefined;
    9.43 +
    9.44 +        /// <summary>
    9.45 +        /// The mail item that is connected to this Inspector/Explorer window.
    9.46 +        /// </summary>
    9.47 +        public Outlook.MailItem CurrentMailItem
    9.48 +        {
    9.49 +            get
    9.50 +            {
    9.51 +                return this._CurrentMailItem;
    9.52 +            }
    9.53 +            protected set
    9.54 +            {
    9.55 +                this._CurrentMailItem = value;
    9.56 +            }
    9.57 +        }
    9.58 +
    9.59 +        /// <summary>
    9.60 +        /// Gets or sets whether to disable the Force Protection option.
    9.61 +        /// </summary>
    9.62 +        public bool DisableForceProtection { get; set; } = false;
    9.63 +
    9.64 +        /// <summary>
    9.65 +        /// Gets or sets whether to send this message forcefully protected.
    9.66 +        /// </summary>
    9.67 +        public bool ForceProtection { get; set; } = false;
    9.68 +
    9.69 +        /// <summary>
    9.70 +        /// Gets or sets whether to send this message forcefully unencrypted.
    9.71 +        /// </summary>
    9.72 +        public bool ForceUnencrypted { get; set; } = false;
    9.73 +
    9.74 +        /// <summary>
    9.75 +        /// Gets or sets whether the message is a draft message.
    9.76 +        /// </summary>
    9.77 +        public bool IsDraft { get; set; } = false;
    9.78 +
    9.79 +        /// <summary>
    9.80 +        /// Gets or sets whether to always store this message as if on an untrusted server.
    9.81 +        /// </summary>
    9.82 +        public bool NeverUnsecure { get; set; } = false;
    9.83 +
    9.84 +        /// <summary>
    9.85 +        /// Gets the rating of this message.
    9.86 +        /// </summary>
    9.87 +        public pEpRating Rating
    9.88 +        {
    9.89 +            get { return this._Rating; }
    9.90 +        }
    9.91 +
    9.92 +        /// <summary>
    9.93 +        /// Gets the associated Explorer/Inspector window. To be overwritten by child class.
    9.94 +        /// </summary>
    9.95 +        public abstract dynamic Window { get; }
    9.96 +
    9.97 +        /// <summary>
    9.98 +        /// Sets the rating of this message and updates the UI.
    9.99 +        /// </summary>
   9.100 +        /// <param name="rating">The message rating.</param>
   9.101 +        public void SetRating(pEpRating rating)
   9.102 +        {
   9.103 +            this._Rating = rating;
   9.104 +            RibbonCustomizations.Invalidate();
   9.105 +        }
   9.106 +
   9.107 +        /// <summary>
   9.108 +        /// The timer that schedules the updates of this window.
   9.109 +        /// </summary>
   9.110 +        public System.Windows.Forms.Timer TimerRefresh { get; set; } = new System.Windows.Forms.Timer();
   9.111 +        #endregion
   9.112 +
   9.113 +        #region Constructors / Destructors
   9.114 +
   9.115 +        /// <summary>
   9.116 +        /// Destructor.
   9.117 +        /// </summary>
   9.118 +        ~WatchedWindow()
   9.119 +        {
   9.120 +            this.Dispose(true);
   9.121 +        }
   9.122 +        #endregion
   9.123 +
   9.124 +        #region Methods
   9.125 +        /**************************************************************
   9.126 +         * 
   9.127 +         * Methods
   9.128 +         * 
   9.129 +         *************************************************************/
   9.130 +
   9.131 +        /// <summary>
   9.132 +        /// Releases all resources and disconnects internal events.
   9.133 +        /// </summary>
   9.134 +        public void Dispose()
   9.135 +        {
   9.136 +            this.Dispose(true);
   9.137 +        }
   9.138 +
   9.139 +        /// <summary>
   9.140 +        /// Clean up any resources being used.
   9.141 +        /// </summary>
   9.142 +        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
   9.143 +        protected virtual void Dispose(bool disposing)
   9.144 +        {
   9.145 +            if (disposing)
   9.146 +            {
   9.147 +                // Set Outlook objects to null
   9.148 +                this._CurrentMailItem = null;
   9.149 +            }
   9.150 +        }
   9.151 +              
   9.152 +        /// <summary>
   9.153 +        /// Builds the latest state of the encryption status manager then shows the UI.
   9.154 +        /// </summary>
   9.155 +        public void BuildAndShowManager()
   9.156 +        {
   9.157 +            /* Resolve all recipients -- this ensures the identities list is correctly populated
   9.158 +             * 
   9.159 +             * Note: The PropertyChanged changed event must be disconnected before trying to resolve.
   9.160 +             * This is because the resolve process can modify the contents of the mail item which triggers an event.
   9.161 +             * The PropertyChanged event would then trigger a UI refresh cycle. However, because the GetManagerState itself 
   9.162 +             * is called within the UI refresh, an infinite loop could occur trying to resolve a recipient that
   9.163 +             * cannot be resolved (no address).
   9.164 +             */
   9.165 +            try
   9.166 +            {
   9.167 +                this.ResolveAllRecipients();
   9.168 +            }
   9.169 +            catch (Exception ex)
   9.170 +            {
   9.171 +                Log.Verbose("BuildAndShowManager: Error resolving recipients. " + ex.ToString());
   9.172 +            }
   9.173 +
   9.174 +            // Build the dialog
   9.175 +            try
   9.176 +            {
   9.177 +                // The PEPMessage to build the dialog with
   9.178 +                PEPMessage message = null;
   9.179 +
   9.180 +                // The own identity to build the dialog with
   9.181 +                PEPIdentity myself = this.cryptableMailItem?.Myself;
   9.182 +
   9.183 +                // If message is a draft, create it directly from the Outlook mail item
   9.184 +                if (this.IsDraft)
   9.185 +                {
   9.186 +                    Log.Verbose("BuildAndShowManager: Creating PEPMessage from draft.");
   9.187 +
   9.188 +                    if (PEPMessage.Create(this._CurrentMailItem, out message) != Globals.ReturnStatus.Success)
   9.189 +                    {
   9.190 +                        Log.Error("BuildAndShowManager: Error creating PEPMessage from draft.");
   9.191 +                        message = null;
   9.192 +                    }
   9.193 +                    else
   9.194 +                    {
   9.195 +                        // Calculate rating
   9.196 +                        message.Rating = message.GetOutgoingRating();
   9.197 +
   9.198 +                        // If Force Protection is set, assign a random GUID
   9.199 +                        if ((this.ForceProtection) &&
   9.200 +                            (this.DisableForceProtection == false))
   9.201 +                        {
   9.202 +                            message.ForceProtectionId = Guid.NewGuid().ToString();
   9.203 +                        }
   9.204 +
   9.205 +                        // If message is Force Unencrypted, assign it
   9.206 +                        message.ForceUnencrypted = this.ForceUnencrypted;
   9.207 +                    }
   9.208 +                }
   9.209 +                else
   9.210 +                {
   9.211 +                    // Else, use either the cryptable mail item's associated mirror or message
   9.212 +                    message = this.cryptableMailItem?.Mirror ?? this.cryptableMailItem?.Message;
   9.213 +                    Log.Verbose(string.Format("BuildAndShowManager: Message {0} retrieved from CryptableMailItem", ((message != null) ? "successfully" : "could not be")));
   9.214 +
   9.215 +                    // As fallback, if we don't have a message yet, create it
   9.216 +                    if (message == null)
   9.217 +                    {
   9.218 +                        Log.Verbose("BuildAndShowManager: Using fallback method to get message.");
   9.219 +
   9.220 +                        Outlook.MailItem mirror = null;
   9.221 +
   9.222 +                        try
   9.223 +                        {
   9.224 +                            // For securely stored mails, try to look up mirror
   9.225 +                            if (this._CurrentMailItem?.GetIsSecurelyStored() == true)
   9.226 +                            {
   9.227 +                                mirror = this._CurrentMailItem?.GetMirror();
   9.228 +
   9.229 +                                if (mirror != null)
   9.230 +                                {
   9.231 +                                    // If mirror is found, use it to create PEPMessage
   9.232 +                                    Log.Verbose("BuildAndShowManager: Mirror found.");
   9.233 +
   9.234 +                                    if (PEPMessage.Create(mirror, out message) != Globals.ReturnStatus.Success)
   9.235 +                                    {
   9.236 +                                        message = null;
   9.237 +                                        Log.Error("BuildAndShowManager: Error creating PEPMessage.");
   9.238 +                                    }
   9.239 +                                    else
   9.240 +                                    {
   9.241 +                                        message.Rating = AdapterExtensions.ReevaluateMessageRating(message);
   9.242 +                                    }
   9.243 +                                }
   9.244 +                                else
   9.245 +                                {
   9.246 +                                    // If no mirror is found, decrypt message and use decrypted one (do not 
   9.247 +                                    // decrypt forcefully protected messages).
   9.248 +                                    if ((PEPMessage.Create(this._CurrentMailItem, out message) == Globals.ReturnStatus.Success) &&
   9.249 +                                        (string.IsNullOrEmpty(message.ForceProtectionId)))
   9.250 +                                    {
   9.251 +                                        var msgProcessor = new MsgProcessor();
   9.252 +                                        PEPMessage decryptedMsg = null;
   9.253 +                                        string[] keyList;
   9.254 +                                        pEpDecryptFlags flags = pEpDecryptFlags.pEpDecryptFlagsNone;
   9.255 +                                        pEpRating rating = msgProcessor.Decrypt(ref message, out decryptedMsg, out keyList, ref flags);
   9.256 +                                        if (decryptedMsg != null)
   9.257 +                                        {
   9.258 +                                            message = decryptedMsg;
   9.259 +                                        }
   9.260 +                                        message.Rating = rating;
   9.261 +                                    }
   9.262 +                                    else
   9.263 +                                    {
   9.264 +                                        message = null;
   9.265 +                                        Log.Error("BuildAndShowManager: Error creating PEPMessage from mirror.");
   9.266 +                                    }
   9.267 +                                }
   9.268 +                            }
   9.269 +
   9.270 +                            // If we don't have a PEPMessage yet, create it
   9.271 +                            if (message == null)
   9.272 +                            {
   9.273 +                                Log.Verbose("BuildAndShowManager: Creating PEPMessage.");
   9.274 +
   9.275 +                                if (PEPMessage.Create(this._CurrentMailItem, out message) != Globals.ReturnStatus.Success)
   9.276 +                                {
   9.277 +                                    message = null;
   9.278 +                                    Log.Error("BuildAndShowManager: Error creating PEPMessage.");
   9.279 +                                }
   9.280 +                                else
   9.281 +                                {
   9.282 +                                    message.Rating = AdapterExtensions.ReevaluateMessageRating(message);
   9.283 +                                }
   9.284 +                            }
   9.285 +
   9.286 +                            // Get myself identiy if we don't have it yet
   9.287 +                            if (myself == null)
   9.288 +                            {
   9.289 +                                myself = this._CurrentMailItem.GetMyselfIdentity();
   9.290 +                            }
   9.291 +                        }
   9.292 +                        catch (Exception ex)
   9.293 +                        {
   9.294 +                            Log.Error("FormRegionPrivacyStatus.Message: Error converting message. " + ex.ToString());
   9.295 +                        }
   9.296 +                        finally
   9.297 +                        {
   9.298 +                            mirror = null;
   9.299 +                        }
   9.300 +                    }
   9.301 +                }
   9.302 +
   9.303 +                // Build dialog
   9.304 +                if (message != null)
   9.305 +                {
   9.306 +                    handshakeDialog = new HandshakeDialog(message, myself, this.IsDraft);
   9.307 +                    handshakeDialog.OnUpdateStatus += HandshakeDialog_Updated;
   9.308 +                    handshakeDialog.Closed += HandshakeDialog_Closed;
   9.309 +                    handshakeDialog.Show();
   9.310 +                }
   9.311 +                else
   9.312 +                {
   9.313 +                    throw new Exception("Could not build handshake dialog. Message is null.");
   9.314 +                }
   9.315 +            }
   9.316 +            catch (Exception ex)
   9.317 +            {
   9.318 +                Globals.StopAndSendCrashReport(ex);
   9.319 +            }
   9.320 +        }
   9.321 +
   9.322 +        /// <summary>
   9.323 +        /// Schedules for the pEp rating and UI (including displayed mirror) to be updated.
   9.324 +        /// This can be called many times with no issue as the update is only run every n milliseconds.
   9.325 +        /// </summary>
   9.326 +        public void RequestRatingAndUIUpdate()
   9.327 +        {
   9.328 +            if (this.isEnabled)
   9.329 +            {
   9.330 +                this.TimerRefresh.Enabled = true;
   9.331 +            }
   9.332 +        }
   9.333 +
   9.334 +        /// <summary>
   9.335 +        /// Immediately starts the update of UI rating based on the associated mail item.
   9.336 +        /// This will start decryption as necessary and also will update the displayed mirror.
   9.337 +        /// This method by-passes the refresh timer completely.
   9.338 +        /// WARNING: This method assumes the message is fully downloaded already.
   9.339 +        /// </summary>
   9.340 +        private void ImmediateRatingAndUIUpdate()
   9.341 +        {
   9.342 +            if ((this.isEnabled) &&
   9.343 +                (this.cryptableMailItem != null))
   9.344 +            {
   9.345 +                Log.Verbose("ImmediateRatingAndUIUpdate: Starting processing.");
   9.346 +
   9.347 +                // Start the rating calculation/decryption process
   9.348 +                this.cryptableMailItem.StartProcessing();
   9.349 +                this.processingOngoing = true;
   9.350 +            }
   9.351 +        }
   9.352 +
   9.353 +        /// <summary>
   9.354 +        /// Resets the Enabled status of this form region and recalculates the rating if necessary.
   9.355 +        /// </summary>
   9.356 +        /// <param name="enable">Whether to enable the form region.</param>
   9.357 +        public void UpdateFormRegion(bool enable)
   9.358 +        {
   9.359 +            this.SetIsEnabled(enable);
   9.360 +
   9.361 +            // Refresh the UI
   9.362 +            if (enable)
   9.363 +            {
   9.364 +                this.ResolveAllRecipients();
   9.365 +                this.RequestRatingAndUIUpdate();
   9.366 +            }
   9.367 +        }
   9.368 +
   9.369 +        /// <summary>
   9.370 +        /// Workaround method to update the current inspector window. This is done by moving the mail item
   9.371 +        /// to a temporary folder first and then back to the current folder. Both folders CANNOT be the same.
   9.372 +        /// As a fallback, the mail item stays in the temporary folder if moving back to the current folder
   9.373 +        /// fails.
   9.374 +        /// </summary>
   9.375 +        private void UpdateInspector()
   9.376 +        {
   9.377 +            Outlook.Application application = null;
   9.378 +            Outlook.Folder currentFolder = null;
   9.379 +            Outlook.Folder tempFolder = null;
   9.380 +            Outlook.Inspector currentInspector = null;
   9.381 +            Outlook.Inspector newInspector = null;
   9.382 +            Outlook.MailItem tempMailItem = null;
   9.383 +            Outlook.Store store = null;
   9.384 +            Outlook.MailItem omi = this.CurrentMailItem;
   9.385 +
   9.386 +            if (omi != null)
   9.387 +            {
   9.388 +                try
   9.389 +                {
   9.390 +                    application = omi.Application;
   9.391 +                    currentInspector = omi.GetInspector;
   9.392 +                    currentFolder = omi.Parent as Outlook.Folder;
   9.393 +
   9.394 +                    if ((currentInspector != null) &&
   9.395 +                        (application != null) &&
   9.396 +                        (currentFolder != null))
   9.397 +                    {
   9.398 +                        var left = currentInspector.Left;
   9.399 +                        var top = currentInspector.Top;
   9.400 +                        var width = currentInspector.Width;
   9.401 +                        var height = currentInspector.Height;
   9.402 +                        var windowState = currentInspector.WindowState;
   9.403 +
   9.404 +                        /* Check, if in trusted store. In that case, use the default drafts folder
   9.405 +                         * as temporary folder. If the store is untrusted, use the pEp drafts folder.
   9.406 +                         */
   9.407 +                        store = currentFolder.Store;
   9.408 +                        if (store?.GetIsSecureStorageEnabled() ?? false)
   9.409 +                        {
   9.410 +                            tempFolder = Globals.ThisAddIn.GetPEPStoreDraftsFolder();
   9.411 +                        }
   9.412 +                        else
   9.413 +                        {
   9.414 +                            tempFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
   9.415 +                        }
   9.416 +
   9.417 +                        if (tempFolder != null)
   9.418 +                        {
   9.419 +                            tempMailItem = omi.Move(tempFolder) as Outlook.MailItem;
   9.420 +
   9.421 +                            if (tempMailItem != null)
   9.422 +                            {
   9.423 +                                try
   9.424 +                                {
   9.425 +                                    omi = tempMailItem.Move(currentFolder) as Outlook.MailItem;
   9.426 +                                }
   9.427 +                                catch
   9.428 +                                {
   9.429 +                                    omi = tempMailItem.Copy();
   9.430 +                                }
   9.431 +
   9.432 +                                newInspector = application.Inspectors.Add(omi);
   9.433 +
   9.434 +                                if (windowState == Outlook.OlWindowState.olNormalWindow)
   9.435 +                                {
   9.436 +                                    newInspector.Left = left;
   9.437 +                                    newInspector.Top = top;
   9.438 +                                    newInspector.Width = width;
   9.439 +                                    newInspector.Height = height;
   9.440 +                                }
   9.441 +
   9.442 +                                newInspector.Display();
   9.443 +                                newInspector.WindowState = windowState;
   9.444 +
   9.445 +                                repeatProcessing = false;
   9.446 +                            }
   9.447 +                        }
   9.448 +                        else
   9.449 +                        {
   9.450 +                            Log.Error("UpdateInspector: Cannot get temporary folder.");
   9.451 +                        }
   9.452 +                    }
   9.453 +                    else
   9.454 +                    {
   9.455 +                        Log.Verbose("UpdateInspector: Error retrieving inspector window or application.");
   9.456 +                    }
   9.457 +                }
   9.458 +                catch (Exception ex)
   9.459 +                {
   9.460 +                    Log.Verbose("UpdateInspector: Error updating inspector window. " + ex.ToString());
   9.461 +                }
   9.462 +                finally
   9.463 +                {
   9.464 +                    application = null;
   9.465 +                    currentInspector = null;
   9.466 +                    newInspector = null;
   9.467 +                    omi = null;
   9.468 +                    tempMailItem = null;
   9.469 +                }
   9.470 +            }
   9.471 +        }
   9.472 +
   9.473 +        /// <summary>
   9.474 +        /// Clears the associated unencrypted preview and displays the given note (if any).
   9.475 +        /// </summary>
   9.476 +        /// <param name="note">The note to display.</param>
   9.477 +        private void SetNote(string note = null)
   9.478 +        {
   9.479 +            WindowFormRegionCollection formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveWindow()];
   9.480 +
   9.481 +            if ((formRegions != null) &&
   9.482 +                (string.IsNullOrEmpty(note) == false))
   9.483 +            {
   9.484 +                if ((formRegions.FormRegionPreviewUnencrypted != null) &&
   9.485 +                    (formRegions.FormRegionPreviewUnencrypted.Visible))
   9.486 +                {
   9.487 +                    formRegions.FormRegionPreviewUnencrypted.DisplayState.SetNote(note);
   9.488 +                }
   9.489 +            }
   9.490 +        }
   9.491 +
   9.492 +        /// <summary>
   9.493 +        /// Sets whether processing of the mail item is enabled.
   9.494 +        /// This should commonly be set from the .GetIsPEPEnabled() value.
   9.495 +        /// </summary>
   9.496 +        private void SetIsEnabled(bool enabled)
   9.497 +        {
   9.498 +            PEPIdentity currIdent;
   9.499 +            Globals.ReturnStatus sts;
   9.500 +            Outlook.Recipient currUser = null;
   9.501 +            Outlook.Account currAccount = null;
   9.502 +            Outlook.Account sendingAccount = null;
   9.503 +            Outlook.NameSpace ns = null;
   9.504 +
   9.505 +            this.isEnabled = enabled;
   9.506 +
   9.507 +            if (enabled)
   9.508 +            {
   9.509 +                // Do not allow initialization more than once
   9.510 +                if (this.isStarted == false)
   9.511 +                {
   9.512 +                    /* It's possible for new draft MailItems to be created outside the context of an account.
   9.513 +                     * In this situation the SendUsingAccount will always be null which of course breaks several pEp operations.
   9.514 +                     * The operations themselves cannot make the assumption about what account information to use.
   9.515 +                     * Therefore, the situation is detected here and for draft mail items a null SendUsingAccount will be 
   9.516 +                     * set with the session's default account.
   9.517 +                     */
   9.518 +                    try
   9.519 +                    {
   9.520 +                        ns = Globals.ThisAddIn.Application.Session;
   9.521 +
   9.522 +                        if (this.IsDraft)
   9.523 +                        {
   9.524 +                            sendingAccount = this._CurrentMailItem.SendUsingAccount;
   9.525 +                            currUser = ns.CurrentUser;
   9.526 +
   9.527 +                            if (sendingAccount == null)
   9.528 +                            {
   9.529 +                                sts = PEPIdentity.Create(currUser, out currIdent);
   9.530 +
   9.531 +                                if (sts == Globals.ReturnStatus.Success)
   9.532 +                                {
   9.533 +                                    sendingAccount = AccountExtensions.GetDefaultAccount(Outlook.OlDefaultFolders.olFolderDrafts);
   9.534 +                                    if (sendingAccount != null)
   9.535 +                                    {
   9.536 +                                        this._CurrentMailItem.SendUsingAccount = currAccount;
   9.537 +                                    }
   9.538 +                                }
   9.539 +                            }
   9.540 +
   9.541 +                            // Check if account is already registered in pEp list and add it if necessary
   9.542 +                            var acctSettings = Globals.ThisAddIn.Settings.GetAccountSettings(sendingAccount?.SmtpAddress);
   9.543 +                            if (acctSettings == null)
   9.544 +                            {
   9.545 +                                Log.Verbose("SetIsEnabled: New account detected. Creating pEp settings.");
   9.546 +
   9.547 +                                // Create pEp settings for the new account
   9.548 +                                acctSettings = sendingAccount.CreatePEPSettings();
   9.549 +
   9.550 +                                // Add account to list
   9.551 +                                Globals.ThisAddIn.Settings.AccountsAddedWhileRunningList.Add(acctSettings?.SmtpAddress);
   9.552 +                                Log.Verbose("SetIsEnabled: New account registered in pEp settings.");
   9.553 +
   9.554 +                                // Generate key
   9.555 +                                Globals.ThisAddIn.RegisterMyself(acctSettings);
   9.556 +                                Log.Verbose("SetIsEnabled: Myself registered.");
   9.557 +
   9.558 +                                // Set rules and view filters
   9.559 +                                Globals.ThisAddIn.SetRulesAndViewFilters(sendingAccount);
   9.560 +                            }
   9.561 +                        }
   9.562 +                    }
   9.563 +                    catch (Exception ex)
   9.564 +                    {
   9.565 +                        Log.Error("SetIsEnabled: Error occured. " + ex.ToString());
   9.566 +                    }
   9.567 +                    finally
   9.568 +                    {
   9.569 +                        currAccount = null;
   9.570 +                        currUser = null;
   9.571 +                        ns = null;
   9.572 +                        sendingAccount = null;
   9.573 +                    }
   9.574 +
   9.575 +                    // Connect refresh timer
   9.576 +                    this.TimerRefresh.Tick += TimerRefresh_Tick;
   9.577 +                    this.isStarted = true;
   9.578 +                }
   9.579 +            }
   9.580 +            else
   9.581 +            {
   9.582 +                // Stop and disconnect the refresh timer
   9.583 +                this.TimerRefresh.Stop();
   9.584 +                this.TimerRefresh.Enabled = false;
   9.585 +                this.TimerRefresh.Tick -= TimerRefresh_Tick;
   9.586 +
   9.587 +                this.isStarted = false;
   9.588 +            }
   9.589 +        }
   9.590 +
   9.591 +        /// <summary>
   9.592 +        /// Resolves all recipients of the Outlook mail item.
   9.593 +        /// </summary>
   9.594 +        private void ResolveAllRecipients()
   9.595 +        {
   9.596 +            if ((this.isEnabled) &&
   9.597 +                (this.cryptableMailItem != null))
   9.598 +            {
   9.599 +                /*
   9.600 +                 * Note: The PropertyChanged changed event must be disconnected before trying to resolve.
   9.601 +                 * This is because the resolve process can modify the contents of the mail item which triggers an event.
   9.602 +                 * The PropertyChanged event would then trigger a UI refresh cycle. However, because the GetManagerState itself 
   9.603 +                 * is called within the UI refresh, an infinite loop could occur trying to resolve a recipient that
   9.604 +                 * cannot be resolved(no address).
   9.605 +                 */
   9.606 +                try
   9.607 +                {
   9.608 +                    this.cryptableMailItem.PropertyChanged -= MailItem_PropertyChanged;
   9.609 +                    this.cryptableMailItem.ResolveAllRecipients();
   9.610 +                    this.cryptableMailItem.PropertyChanged += MailItem_PropertyChanged;
   9.611 +                }
   9.612 +                catch (Exception ex)
   9.613 +                {
   9.614 +                    Log.Error("Error resolving recipients. " + ex.ToString());
   9.615 +                }
   9.616 +            }
   9.617 +        }
   9.618 +        #endregion
   9.619 +
   9.620 +        #region Event Handling
   9.621 +        /**************************************************************
   9.622 +         * 
   9.623 +         * Event Handling
   9.624 +         * 
   9.625 +         *************************************************************/
   9.626 +
   9.627 +        protected void InitializeMailItem(bool isInlineResponse = false)
   9.628 +        {
   9.629 +            bool enableFormRegion = false;
   9.630 +            bool cancelOpenEvent = false;
   9.631 +            bool isSecureAttachedMail = false;
   9.632 +            string messageId = null;
   9.633 +
   9.634 +            try
   9.635 +            {      
   9.636 +                // Check if draft
   9.637 +                this.IsDraft = this._CurrentMailItem.GetIsDraft();
   9.638 +
   9.639 +                /* Set immediately a provisional rating in order to have a less flickery
   9.640 +                 * UI experience.
   9.641 +                 * The provisional rating is either a stored rating or, in case we have a
   9.642 +                 * reply message, the rating of the original (the item we reply to).
   9.643 +                 * This provisional rating will be replace with the real one once the full
   9.644 +                 * processing is complete.
   9.645 +                 */
   9.646 +                pEpRating provisionalRating = pEpRating.pEpRatingUndefined;
   9.647 +
   9.648 +                // Try to get an original rating (in case of reply messages)
   9.649 +                if ((this.IsDraft) &&
   9.650 +                    (this._CurrentMailItem?.Recipients?.Count > 0))
   9.651 +                {
   9.652 +                    string originalRatingString = this._CurrentMailItem.GetUserProperty(CryptableMailItem.USER_PROPERTY_KEY_ORIGINAL_RATING) as string;
   9.653 +
   9.654 +                    // If we have an original rating, parse it and set it.
   9.655 +                    if (string.IsNullOrEmpty(originalRatingString) == false)
   9.656 +                    {
   9.657 +                        provisionalRating = AdapterExtensions.ParseRatingString(originalRatingString);
   9.658 +                    }
   9.659 +                }
   9.660 +                else
   9.661 +                {
   9.662 +                    // Try to get rating from db
   9.663 +                    provisionalRating = PEPDatabase.GetRating(this._CurrentMailItem.EntryID);
   9.664 +
   9.665 +                    // If there is no rating in the db, use stored or default rating
   9.666 +                    if (provisionalRating == pEpRating.pEpRatingUndefined)
   9.667 +                    {
   9.668 +                        provisionalRating = this._CurrentMailItem.GetStoredRating() ?? pEpRating.pEpRatingUndefined;
   9.669 +                    }
   9.670 +                }
   9.671 +
   9.672 +                // Only set rating if one has been retrieved
   9.673 +                if (provisionalRating != pEpRating.pEpRatingUndefined)
   9.674 +                {
   9.675 +                    this.SetRating(provisionalRating);
   9.676 +                    Log.Verbose("FormRegionPrivacyStatus_FormRegionShowing: Provisional rating {0} shown.", Enum.GetName(typeof(pEpRating), provisionalRating));
   9.677 +                }
   9.678 +
   9.679 +
   9.680 +                // Do not process S/MIME messages
   9.681 +                if (this._CurrentMailItem.GetIsSMIMEEnabled())
   9.682 +                {
   9.683 +                    Log.Verbose("FormRegionPrivacyStatus_FormRegionShowing: S/MIME message detected. Won't be processed.");
   9.684 +
   9.685 +                    // Set unencrypted rating
   9.686 +                    this.SetRating(pEpRating.pEpRatingUnencrypted);
   9.687 +
   9.688 +                    // Set icon(s) if necessary     
   9.689 +                    if ((IsDraft == false) &&
   9.690 +                        (this._CurrentMailItem.SetEncryptionIcons()))
   9.691 +                    {
   9.692 +                        try
   9.693 +                        {
   9.694 +                            this._CurrentMailItem.Save();
   9.695 +                        }
   9.696 +                        catch (Exception ex)
   9.697 +                        {
   9.698 +                            Log.Error("FormRegionPrivacyStatus_FormRegionShowing: Error saving message after changing icon. " + ex.ToString());
   9.699 +                        }
   9.700 +                    }
   9.701 +
   9.702 +                    return;
   9.703 +                }
   9.704 +
   9.705 +                /* Check if item is attached mail. For performance reasons,
   9.706 +                 * only do the whole check if an item has been loaded to the
   9.707 +                 * cache of attached mails and if item might be secure.
   9.708 +                 */
   9.709 +                if ((PEPAttachment.AttachedMailsCache.Count > 0) &&
   9.710 +                    (this._CurrentMailItem.Attachments?.Count == 2))
   9.711 +                {
   9.712 +                    try
   9.713 +                    {
   9.714 +                        // Check if mail item is an attached mail
   9.715 +                        if (this._CurrentMailItem.GetIsAttachedMail(out messageId))
   9.716 +                        {
   9.717 +                            Outlook.MailItem mirror = null;
   9.718 +                            PEPMessage pEpMessage;
   9.719 +
   9.720 +                            // Try to get the mirror
   9.721 +                            mirror = this._CurrentMailItem.GetMirror(messageId);
   9.722 +
   9.723 +                            // If mirror was not found, decrypt and create mirror
   9.724 +                            if (mirror != null)
   9.725 +                            {
   9.726 +                                isSecureAttachedMail = true;
   9.727 +                            }
   9.728 +                            else
   9.729 +                            {
   9.730 +                                if ((PEPMessage.Create(this._CurrentMailItem, out pEpMessage) == Globals.ReturnStatus.Success) &&
   9.731 +                                    (pEpMessage.IsSecure))
   9.732 +                                {
   9.733 +                                    PEPMessage decryptedMessage;
   9.734 +                                    MsgProcessor msgProcessor = new MsgProcessor();
   9.735 +                                    if (msgProcessor.Decrypt(pEpMessage, out decryptedMessage))
   9.736 +                                    {
   9.737 +                                        isSecureAttachedMail = true;
   9.738 +                                        mirror = this._CurrentMailItem.CreateMirrorOMI(messageId);
   9.739 +                                        decryptedMessage.ApplyTo(mirror, true, false);
   9.740 +                                        mirror?.Save();
   9.741 +                                    }
   9.742 +                                    else
   9.743 +                                    {
   9.744 +                                        Log.Error("FormRegionPrivacyStatus_FormRegionShowing: Decryption of attached mail was not successful.");
   9.745 +                                    }
   9.746 +                                }
   9.747 +                            }
   9.748 +
   9.749 +                            // Check if attachment is being opened or if only the preview is needed
   9.750 +                            if (CryptableMailItem.PreviewAttachedMailId?.Equals(messageId) != true)
   9.751 +                            {
   9.752 +                                // Display mirror and cancel opening of original
   9.753 +                                cancelOpenEvent = true;
   9.754 +                                mirror?.Display();
   9.755 +                            }
   9.756 +
   9.757 +                            // Not needed anymore after this point
   9.758 +                            CryptableMailItem.PreviewAttachedMailId = null;
   9.759 +                        }
   9.760 +                    }
   9.761 +                    catch (Exception ex)
   9.762 +                    {
   9.763 +                        messageId = null;
   9.764 +                        Log.Error("FormRegionPrivacyStatus_FormRegionShowing: Error checking for attached mail. " + ex.ToString());
   9.765 +                    }
   9.766 +                }
   9.767 +
   9.768 +                this.cryptableMailItem = new CryptableMailItem(this._CurrentMailItem, provisionalRating);
   9.769 +
   9.770 +                // Set inline response property
   9.771 +                this.cryptableMailItem.IsInlineResponse = isInlineResponse;
   9.772 +
   9.773 +                // Set properties for encrypted attached mail
   9.774 +                if (isSecureAttachedMail)
   9.775 +                {
   9.776 +                    this.cryptableMailItem.MessageId = messageId;
   9.777 +                    this.cryptableMailItem.IsSecureAttachedMail = true;
   9.778 +                }
   9.779 +
   9.780 +                // Connect cryptable mail item events
   9.781 +                if (this.cryptableMailItem != null)
   9.782 +                {
   9.783 +                    // If we don't open the original, set property and return
   9.784 +                    if (cancelOpenEvent)
   9.785 +                    {
   9.786 +                        this.cryptableMailItem.Open += MailItem_Open;
   9.787 +                        this.cryptableMailItem.CancelOpen = true;
   9.788 +                        return;
   9.789 +                    }
   9.790 +                    else
   9.791 +                    {
   9.792 +                        try
   9.793 +                        {
   9.794 +                            this.cryptableMailItem.PropertyChanged += MailItem_PropertyChanged;
   9.795 +                            this.cryptableMailItem.ProcessingCompleted += MailItem_ProcessingCompleted;
   9.796 +                            this.cryptableMailItem.GetMirrorCompleted += MailItem_GetMirrorCompleted;
   9.797 +                            this.cryptableMailItem.Send += MailItem_Send;
   9.798 +
   9.799 +                            if (this.cryptableMailItem.IsSecurelyStored)
   9.800 +                            {
   9.801 +                                this.cryptableMailItem.Open += MailItem_Open;
   9.802 +                            }
   9.803 +                        }
   9.804 +                        catch (Exception ex)
   9.805 +                        {
   9.806 +                            Log.Error("FormRegionPrivacyStatus_FormRegionShowing: Error occured. " + ex.ToString());
   9.807 +                        }
   9.808 +
   9.809 +                        if (this._CurrentMailItem.GetIsPEPEnabled())
   9.810 +                        {
   9.811 +                            // If pEp is enabled, show the form region
   9.812 +                            enableFormRegion = true;
   9.813 +                        }
   9.814 +                        else
   9.815 +                        {
   9.816 +                            /* If pEp is disabled, process item and show form region in the following cases:
   9.817 +                             * 1. Incoming items: if decrypt always option is set
   9.818 +                             * 2. Outgoing items: if EnableProtection option is set
   9.819 +                             *                    Note: if this property isn't set, subscribe to originally 
   9.820 +                             *                          encrypted status update event handler in case the 
   9.821 +                             *                          current code runs before CryptableMailItem.MailItem_Reply
   9.822 +                             *                          or CryptableMailItem.MailItem_Forward.
   9.823 +                             */
   9.824 +                            if (this.IsDraft)
   9.825 +                            {
   9.826 +                                enableFormRegion = true;
   9.827 +                                this.cryptableMailItem.OriginallyEncryptedStatusUpdated += CryptableMailItem_OriginallyEncryptedStatusUpdated;
   9.828 +                            }
   9.829 +                            else
   9.830 +                            {
   9.831 +                                enableFormRegion = this._CurrentMailItem.GetIsDecryptAlwaysEnabled();
   9.832 +                            }
   9.833 +                        }
   9.834 +                    }
   9.835 +                }
   9.836 +
   9.837 +                // Update pEp enabled status
   9.838 +                this.SetIsEnabled(enableFormRegion);
   9.839 +
   9.840 +                if (this.isEnabled)
   9.841 +                {
   9.842 +                    // If forcefully protected, run dedicated decryption
   9.843 +                    if (this._CurrentMailItem.GetIsForcefullyProtected())
   9.844 +                    {
   9.845 +                        FPPMessage fppMessage = new FPPMessage(this._CurrentMailItem);
   9.846 +                        if ((fppMessage?.GetMessageType() != null) ||
   9.847 +                            (fppMessage?.CurrentMessage?.IsSecure == true))
   9.848 +                        {
   9.849 +                            fppMessage.ProcessIncoming(true);
   9.850 +                        }
   9.851 +                        else
   9.852 +                        {
   9.853 +                            this.TimerRefresh_Tick(null, new EventArgs());
   9.854 +                        }
   9.855 +                    }
   9.856 +                    else
   9.857 +                    {
   9.858 +                        // Call the timer tick method manually to refresh data with no delay
   9.859 +                        this.TimerRefresh_Tick(null, new EventArgs());
   9.860 +                    }
   9.861 +                }
   9.862 +            }
   9.863 +            catch (Exception e)
   9.864 +            {
   9.865 +                Log.Error("Window_SelectionChange: Error. " + e.Message);
   9.866 +            }
   9.867 +        }
   9.868 +
   9.869 +        /// <summary>
   9.870 +        /// Event handler for when the form region is closed.
   9.871 +        /// </summary>
   9.872 +        protected void FormRegionPrivacyStatus_FormRegionClosed(object sender, EventArgs e)
   9.873 +        {
   9.874 +            // Disconnect cryptable mail item
   9.875 +            if (this.cryptableMailItem != null)
   9.876 +            {
   9.877 +                try
   9.878 +                {
   9.879 +                    this.cryptableMailItem.PropertyChanged -= MailItem_PropertyChanged;
   9.880 +                    this.cryptableMailItem.ProcessingCompleted -= MailItem_ProcessingCompleted;
   9.881 +                    this.cryptableMailItem.GetMirrorCompleted -= MailItem_GetMirrorCompleted;
   9.882 +                    this.cryptableMailItem.Open -= MailItem_Open;
   9.883 +                    this.cryptableMailItem.Send -= MailItem_Send;
   9.884 +                    this.cryptableMailItem.OriginallyEncryptedStatusUpdated -= CryptableMailItem_OriginallyEncryptedStatusUpdated;
   9.885 +                }
   9.886 +                catch { }
   9.887 +
   9.888 +                this.cryptableMailItem.Dispose();
   9.889 +                this.cryptableMailItem = null;
   9.890 +            }
   9.891 +
   9.892 +            // Disconnect other
   9.893 +            this.SetIsEnabled(false);
   9.894 +        }
   9.895 +
   9.896 +        /// <summary>
   9.897 +        /// Event handler for when the processing is completed in the associated mail item.
   9.898 +        /// This will then update the form region UI and the privacy status window as needed.
   9.899 +        /// </summary>
   9.900 +        private void MailItem_ProcessingCompleted(object sender, MsgProcessor.ProcessingCompletedEventArgs e)
   9.901 +        {
   9.902 +            Log.Verbose("MailItem_ProcessingComplete: Decryption completed.");
   9.903 +
   9.904 +            try
   9.905 +            {
   9.906 +                // Marshal code back to UI thread as necessary
   9.907 +                KeySyncWizard.Wizard.Dispatcher.Invoke(new Action(() =>
   9.908 +                {
   9.909 +                    if (this.isEnabled)
   9.910 +                    {
   9.911 +                        try
   9.912 +                        {
   9.913 +                            this.SetRating(e.ProcessedRating);
   9.914 +
   9.915 +                            // Set MAPI properties if needed
   9.916 +                            if (e.PropertiesToSet?.Count > 0)
   9.917 +                            {
   9.918 +                                this._CurrentMailItem?.SetMAPIProperties(e.PropertiesToSet);
   9.919 +                            }
   9.920 +                            Log.Verbose("MailItem_ProcessingComplete: Status bar updated with rating " + Enum.GetName(typeof(pEpRating), e.ProcessedRating));
   9.921 +                        }
   9.922 +                        catch (Exception ex)
   9.923 +                        {
   9.924 +                            Log.Verbose("MailItem_ProcessingComplete: Error. " + ex.ToString());
   9.925 +                        }
   9.926 +
   9.927 +                        if (repeatProcessing &&
   9.928 +                            (repeatCounter++ < maxRepeatCount))
   9.929 +                        {
   9.930 +                            repeatProcessing = false;
   9.931 +                            this.RequestRatingAndUIUpdate();
   9.932 +                        }
   9.933 +                        else
   9.934 +                        {
   9.935 +                            /* Check if the mail item is in Outbox and update the inspector window if possible.
   9.936 +                             * This is the case when a submitted, but not yet sent email is opened again when working 
   9.937 +                             * offline or without internet connection. Without this update, Outlook removes the message class 
   9.938 +                             * "IPM.Note.SMIME.MultipartSigned" at the next send event and the message gets invalid and can't be
   9.939 +                             * opened again (i.e. is lost).
   9.940 +                             */
   9.941 +                            try
   9.942 +                            {
   9.943 +                                if ((this._CurrentMailItem?.GetIsSubmitted() == true) &&
   9.944 +                                    (this.IsDraft))
   9.945 +                                {
   9.946 +                                    UpdateInspector();
   9.947 +                                }
   9.948 +                            }
   9.949 +                            catch (Exception ex)
   9.950 +                            {
   9.951 +                                Log.Verbose("MailItem_ProcessingComplete: Error while checking if mail item is in outbox or updating inspector. " + ex.Message);
   9.952 +                            }
   9.953 +
   9.954 +                            /* Create the unencrypted preview if the mail item is encrypted and
   9.955 +                             * it is in an encrypted (untrusted) store
   9.956 +                             * 
   9.957 +                             * This is done here because FormRegionPrivacyStatus has the cryptable mail item and
   9.958 +                             * it also is initialized after FormRegionPreviewUnencrypted.
   9.959 +                             */
   9.960 +                            try
   9.961 +                            {
   9.962 +                                if (this.cryptableMailItem.IsSecurelyStored || this.cryptableMailItem.IsSecureAttachedMail)
   9.963 +                                {
   9.964 +                                    Log.Verbose("MailItem_ProcessingComplete: Starting mirror location.");
   9.965 +                                    this.cryptableMailItem.StartGetMirror(this.cryptableMailItem.MessageId);
   9.966 +                                }
   9.967 +                                else
   9.968 +                                {
   9.969 +                                    this.SetNote();
   9.970 +                                }
   9.971 +                            }
   9.972 +                            catch (Exception ex)
   9.973 +                            {
   9.974 +                                // Error is possible in some situations where the mail item was deleted or moved while decryption was ongoing.
   9.975 +                                // While rare, just log the issue and stop the process
   9.976 +                                Log.Warning("MailItem_ProcessingComplete: Failed to start mirror location, " + ex.ToString());
   9.977 +                            }
   9.978 +
   9.979 +                            /* OUT-470: Workaround until this is implemented in the engine:
   9.980 +                             * Only enable Force Protection if all recipients are grey
   9.981 +                             */
   9.982 +                            if (this.IsDraft)
   9.983 +                            {
   9.984 +                                bool disableForceProtection = false;
   9.985 +                                Outlook.Recipients recipients = null;
   9.986 +                                Outlook.Recipient recipient = null;
   9.987 +                                PEPIdentity pEpIdentity = null;
   9.988 +
   9.989 +                                try
   9.990 +                                {
   9.991 +                                    recipients = this._CurrentMailItem?.Recipients;
   9.992 +                                    if (recipients?.Count > 0)
   9.993 +                                    {
   9.994 +                                        for (int i = 1; i <= recipients.Count; i++)
   9.995 +                                        {
   9.996 +                                            recipient = recipients[i];
   9.997 +                                            if ((PEPIdentity.Create(recipient, out pEpIdentity, false) == Globals.ReturnStatus.Success) &&
   9.998 +                                                ((PEPIdentity.GetIsOwnIdentity(pEpIdentity.Address) ||
   9.999 +                                                 (ThisAddIn.PEPEngine.IdentityRating(pEpIdentity.ToCOMType()) >= pEpRating.pEpRatingReliable))))
  9.1000 +                                            {
  9.1001 +                                                disableForceProtection = true;
  9.1002 +                                                Log.Verbose("ToggleButtonForceProtection_GetEnabled: Secure recipient found. Disabling force protection.");
  9.1003 +                                                break;
  9.1004 +                                            }
  9.1005 +                                        }
  9.1006 +                                    }
  9.1007 +                                    else
  9.1008 +                                    {
  9.1009 +                                        // If there aren't any recipients (anymore), reset values
  9.1010 +                                        this.DisableForceProtection = false;
  9.1011 +                                        this.ForceProtection = false;
  9.1012 +                                        this.NeverUnsecure = false;
  9.1013 +                                        this.ForceUnencrypted = false;
  9.1014 +                                    }
  9.1015 +                                }
  9.1016 +                                catch (Exception ex)
  9.1017 +                                {
  9.1018 +                                    Log.Error("ToggleButtonForceProtection_GetEnabled: Error occured. " + ex.ToString());
  9.1019 +                                }
  9.1020 +                                finally
  9.1021 +                                {
  9.1022 +                                    recipient = null;
  9.1023 +                                    recipients = null;
  9.1024 +                                }
  9.1025 +
  9.1026 +                                this.DisableForceProtection = disableForceProtection;
  9.1027 +                            }
  9.1028 +                        }
  9.1029 +                    }
  9.1030 +                }));
  9.1031 +            }
  9.1032 +            catch (Exception ex)
  9.1033 +            {
  9.1034 +                Log.Error("MailItem_ProcessingComplete: Error setting UI state, " + ex.ToString());
  9.1035 +            }
  9.1036 +
  9.1037 +            this.processingOngoing = false;
  9.1038 +        }
  9.1039 +
  9.1040 +        /// <summary>
  9.1041 +        /// Event handler for when the get mirror locating process is complete for the associated mail item.
  9.1042 +        /// This will then update the unencrypted preview in the UI.
  9.1043 +        /// </summary>
  9.1044 +        private void MailItem_GetMirrorCompleted(object sender, CryptableMailItem.GetMirrorCompletedEventArgs e)
  9.1045 +        {
  9.1046 +            try
  9.1047 +            {
  9.1048 +                // Marshal code back to UI thread as necessary
  9.1049 +                KeySyncWizard.Wizard.Dispatcher.Invoke(new Action(() =>
  9.1050 +                {
  9.1051 +                    if (this.isEnabled)
  9.1052 +                    {
  9.1053 +                        WindowFormRegionCollection formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveWindow()];
  9.1054 +
  9.1055 +                        // If the message was forcefully protected, there is no mirror and we show the actual message
  9.1056 +                        if ((e.Mirror == null) &&
  9.1057 +                            (this._CurrentMailItem?.GetIsForcefullyProtected() == true))
  9.1058 +                        {
  9.1059 +                            PEPMessage mirror = null;
  9.1060 +                            if (PEPMessage.Create(this._CurrentMailItem, out mirror) == Globals.ReturnStatus.Success)
  9.1061 +                            {
  9.1062 +                                e.Mirror = mirror;
  9.1063 +                            }
  9.1064 +                        }
  9.1065 +
  9.1066 +                        if ((e.Mirror == null) &&
  9.1067 +                            (this.cryptableMailItem.LastProcessedStatus == Globals.ReturnStatus.Failure))
  9.1068 +                        {
  9.1069 +                            this.SetNote(Properties.Resources.Message_OpenError);
  9.1070 +                            Log.Verbose("MailItem_GetMirrorComplete: Cannot display mirror, failure during decryption.");
  9.1071 +                        }
  9.1072 +                        else if ((e.Mirror == null) &&
  9.1073 +                                 (this.cryptableMailItem.LastProcessedStatus == Globals.ReturnStatus.FailureNoConnection))
  9.1074 +                        {
  9.1075 +                            this.SetNote(Properties.Resources.Message_DecryptionNoConnection);
  9.1076 +                            Log.Verbose("MailItem_GetMirrorComplete: Cannot display mirror, connection failure during decryption.");
  9.1077 +                        }
  9.1078 +                        else
  9.1079 +                        {
  9.1080 +                            if (formRegions != null)
  9.1081 +                            {
  9.1082 +                                if ((formRegions.FormRegionPreviewUnencrypted != null) &&
  9.1083 +                                    (formRegions.FormRegionPreviewUnencrypted.Visible))
  9.1084 +                                {
  9.1085 +                                    formRegions.FormRegionPreviewUnencrypted.DisplayState.OriginalEntryId = this._CurrentMailItem?.EntryID;
  9.1086 +                                    formRegions.FormRegionPreviewUnencrypted.DisplayState.SetMessage(e.Mirror);
  9.1087 +                                }
  9.1088 +
  9.1089 +                                Log.Verbose("MailItem_GetMirrorComplete: Mirror found and displayed.");
  9.1090 +                            }
  9.1091 +                        }
  9.1092 +
  9.1093 +                        // Display the mirror if necessary
  9.1094 +                        if ((this.cryptableMailItem != null) &&
  9.1095 +                            (this.displayMirrorRequested))
  9.1096 +                        {
  9.1097 +                            this.cryptableMailItem.DisplayMirror();
  9.1098 +                            this.displayMirrorRequested = false;
  9.1099 +                        }
  9.1100 +                    }
  9.1101 +                }));
  9.1102 +            }
  9.1103 +            catch (Exception ex)
  9.1104 +            {
  9.1105 +                Log.Error("MailItem_GetMirrorComplete: Error displaying preview, " + ex.ToString());
  9.1106 +            }
  9.1107 +        }
  9.1108 +
  9.1109 +        /// <summary>
  9.1110 +        /// Event handler for the mail item originally encrypted status updated.
  9.1111 +        /// This event is fired after the status has been updated with parent information following a
  9.1112 +        /// forward or reply mail item event (on a different, likely parent, mail item).
  9.1113 +        /// </summary>
  9.1114 +        protected void CryptableMailItem_OriginallyEncryptedStatusUpdated(object sender, EventArgs e)
  9.1115 +        {
  9.1116 +            // Process the mail item now that the cache is updated
  9.1117 +            if (this.cryptableMailItem.IsOriginallyEncrypted)
  9.1118 +            {
  9.1119 +                this.cryptableMailItem.StartProcessing();
  9.1120 +            }
  9.1121 +        }
  9.1122 +
  9.1123 +        /// <summary>
  9.1124 +        /// Event handler for when a mail item is being opened in an inspector.
  9.1125 +        /// See: https://msdn.microsoft.com/en-us/library/office/ff865989.aspx
  9.1126 +        /// </summary>
  9.1127 +        /// <param name="cancel">Whether to cancel the event: Value is False when the event occurs. 
  9.1128 +        /// If the event procedure sets this argument to True, the open operation is not completed 
  9.1129 +        /// and the inspector is not displayed.</param>
  9.1130 +        protected void MailItem_Open(ref bool cancel)
  9.1131 +        {
  9.1132 +            bool result;
  9.1133 +
  9.1134 +            if ((this.isEnabled) &&
  9.1135 +                (this.cryptableMailItem != null))
  9.1136 +            {
  9.1137 +                // If cryptable mail item is not to be opened, cancel opening
  9.1138 +                if (this.cryptableMailItem.CancelOpen)
  9.1139 +                {
  9.1140 +                    cancel = true;
  9.1141 +                }
  9.1142 +                else if ((this.cryptableMailItem.IsSecurelyStored) &&
  9.1143 +                         (this.cryptableMailItem.IsIncoming || this.cryptableMailItem.IsOriginallyEncrypted || !this.cryptableMailItem.IsDraft))
  9.1144 +                {
  9.1145 +                    // Try to open the mirror
  9.1146 +                    result = this.cryptableMailItem.DisplayMirror();
  9.1147 +
  9.1148 +                    if (result == false)
  9.1149 +                    {
  9.1150 +                        // Set flag to open after decryption/mirror location
  9.1151 +                        this.displayMirrorRequested = true;
  9.1152 +                    }
  9.1153 +
  9.1154 +                    // Always cancel opening the original
  9.1155 +                    cancel = true;
  9.1156 +                }
  9.1157 +            }
  9.1158 +        }
  9.1159 +
  9.1160 +        /// <summary>
  9.1161 +        /// Event handler for when a mail item is sent.
  9.1162 +        /// See: https://msdn.microsoft.com/en-us/library/office/ff865379.aspx
  9.1163 +        /// </summary>
  9.1164 +        /// <param name="cancel">Whether to cancel the event: Value is False when the event occurs. 
  9.1165 +        /// If the event procedure sets this argument to True, the send operation is not completed 
  9.1166 +        /// and the inspector is left open.</param>
  9.1167 +        protected void MailItem_Send(ref bool cancel)
  9.1168 +        {
  9.1169 +            DialogResult result;
  9.1170 +
  9.1171 +            if (this.isEnabled)
  9.1172 +            {
  9.1173 +                if ((this.cryptableMailItem.IsBeingProcessed) ||
  9.1174 +                    (this.processingOngoing))
  9.1175 +                {
  9.1176 +                    Log.Verbose("MailItem_Send cancelled. Mail item still being processed.");
  9.1177 +                    cancel = true;
  9.1178 +                    return;
  9.1179 +                }
  9.1180 +
  9.1181 +                // Show warning message if needed
  9.1182 +                if ((Globals.ThisAddIn.Settings.IsSecurityLossWarningEnabled) &&
  9.1183 +                    (this.Rating < pEpRating.pEpRatingUnreliable) &&
  9.1184 +                    (this.cryptableMailItem.IsOriginallyEncrypted))
  9.1185 +                {
  9.1186 +
  9.1187 +#if READER_RELEASE_MODE
  9.1188 +                    FormReaderSplash warningMessage = new FormReaderSplash(true);
  9.1189 +                    result = warningMessage.ShowDialog();
  9.1190 +
  9.1191 +                    if (result != DialogResult.OK)
  9.1192 +                    {
  9.1193 +                        // Cancel sending
  9.1194 +                        cancel = true;
  9.1195 +                    }
  9.1196 +#else
  9.1197 +                    result = MessageBox.Show(Properties.Resources.Message_WarningSecurityLoss,
  9.1198 +                                             Properties.Resources.Message_TitleConfirmOperation,
  9.1199 +                                             MessageBoxButtons.YesNo,
  9.1200 +                                             MessageBoxIcon.Warning);
  9.1201 +
  9.1202 +                    if (result == DialogResult.No)
  9.1203 +                    {
  9.1204 +                        // Cancel sending
  9.1205 +                        cancel = true;
  9.1206 +                    }
  9.1207 +#endif
  9.1208 +                }
  9.1209 +
  9.1210 +                if (cancel == false)
  9.1211 +                {
  9.1212 +                    // Set pEp options if needed
  9.1213 +                    if ((this.ForceProtection) &&
  9.1214 +                        (this.DisableForceProtection == false))
  9.1215 +                    {
  9.1216 +                        this._CurrentMailItem?.SetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, Guid.NewGuid().ToString());
  9.1217 +                    }
  9.1218 +                    else if (this.ForceUnencrypted)
  9.1219 +                    {
  9.1220 +                        this._CurrentMailItem?.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, true);
  9.1221 +                    }
  9.1222 +
  9.1223 +                    if (this.NeverUnsecure)
  9.1224 +                    {
  9.1225 +                        this._CurrentMailItem?.SetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, true);
  9.1226 +                    }
  9.1227 +
  9.1228 +                    // Stop and disconnect the refresh timer
  9.1229 +                    // This is necessary so an ongoing refresh doesn't try to access a mail item as it's being moved
  9.1230 +                    this.TimerRefresh.Stop();
  9.1231 +                    this.TimerRefresh.Enabled = false;
  9.1232 +                    this.TimerRefresh.Tick -= TimerRefresh_Tick;
  9.1233 +                }
  9.1234 +            }
  9.1235 +        }
  9.1236 +
  9.1237 +        /// <summary>
  9.1238 +        /// Event handler for when a mail item property is changed.
  9.1239 +        /// See: https://msdn.microsoft.com/en-us/library/office/ff866739.aspx
  9.1240 +        /// </summary>
  9.1241 +        /// <param name="propertyName">The name of the property that was changed.</param>
  9.1242 +        protected void MailItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
  9.1243 +        {
  9.1244 +            switch (e.PropertyName.ToUpperInvariant())
  9.1245 +            {
  9.1246 +                case "BCC":
  9.1247 +                    {
  9.1248 +                        // Outlook always fires Bcc, Cc and To together so only "TO" is used
  9.1249 +                        break;
  9.1250 +                    }
  9.1251 +                case "CC":
  9.1252 +                    {
  9.1253 +                        // Outlook always fires Bcc, Cc and To together so only "TO" is used
  9.1254 +                        break;
  9.1255 +                    }
  9.1256 +                case "SENTONBEHALFOFNAME":
  9.1257 +                    {
  9.1258 +                        // Always fired with "SENDUSINGACCOUNT" so is ignored
  9.1259 +                        break;
  9.1260 +                    }
  9.1261 +                case "SENDUSINGACCOUNT":
  9.1262 +                    {
  9.1263 +                        // Update pEp enabled status
  9.1264 +                        this.isStarted = false;
  9.1265 +                        this.SetIsEnabled((this.CurrentMailItem)?.GetEnableFormRegion() ?? false);
  9.1266 +
  9.1267 +                        // Refresh the UI
  9.1268 +                        this.ResolveAllRecipients();
  9.1269 +                        this.RequestRatingAndUIUpdate();
  9.1270 +                        RibbonCustomizations.Invalidate();
  9.1271 +
  9.1272 +                        break;
  9.1273 +                    }
  9.1274 +                case "TO":
  9.1275 +                    {
  9.1276 +                        if (this.isEnabled)
  9.1277 +                        {
  9.1278 +                            this.RequestRatingAndUIUpdate();
  9.1279 +                        }
  9.1280 +                        break;
  9.1281 +                    }
  9.1282 +            }
  9.1283 +        }
  9.1284 +
  9.1285 +        /// <summary>
  9.1286 +        /// Event handler for when a handshake dialog was updated.
  9.1287 +        /// </summary>
  9.1288 +        protected void HandshakeDialog_Updated(object sender, EventArgs e)
  9.1289 +        {
  9.1290 +            // Update current form region
  9.1291 +            this.RequestRatingAndUIUpdate();
  9.1292 +            
  9.1293 +            /* If a handshake is performed while having the same message open both in an inspector
  9.1294 +             * and an Window window, the one that didn't trigger the handshake won't get updated
  9.1295 +             * automatically. Therefore, after a handshake, we also update all other open windows.
  9.1296 +             */
  9.1297 +            try
  9.1298 +            {
  9.1299 +                Globals.ThisAddIn.RecalculateAllWindows(this);                
  9.1300 +            }
  9.1301 +            catch (Exception ex)
  9.1302 +            {
  9.1303 +                Log.Error("HandshakeDialog_Updated: Error updating other windows. " + ex.Message);
  9.1304 +            }
  9.1305 +        }
  9.1306 +
  9.1307 +        /// <summary>
  9.1308 +        /// Event handler for when a handshake dialog was closed.
  9.1309 +        /// </summary>
  9.1310 +        protected void HandshakeDialog_Closed(object sender, EventArgs e)
  9.1311 +        {
  9.1312 +            if (this.handshakeDialog != null)
  9.1313 +            {
  9.1314 +                this.handshakeDialog.OnUpdateStatus -= HandshakeDialog_Updated;
  9.1315 +                this.handshakeDialog.Closed -= HandshakeDialog_Closed;
  9.1316 +                this.handshakeDialog = null;
  9.1317 +            }
  9.1318 +        }
  9.1319 +
  9.1320 +        /// <summary>
  9.1321 +        /// Event handler called after the refresh timer has elapsed.
  9.1322 +        /// </summary>
  9.1323 +        private void TimerRefresh_Tick(object sender, EventArgs e)
  9.1324 +        {
  9.1325 +            bool tryAgain = false;
  9.1326 +#pragma warning disable 219
  9.1327 +            bool markForDownload = false;
  9.1328 +#pragma warning restore 219
  9.1329 +            this.TimerRefresh.Enabled = false; // Only once
  9.1330 +            Outlook.OlDownloadState dlState;
  9.1331 +
  9.1332 +            /* The Refresh/UI_Update process:
  9.1333 +             * There are the following components:
  9.1334 +             *   1. TimerRefresh_Tick
  9.1335 +             *        This is the main timer tick event handler called any time
  9.1336 +             *        a refresh was requested (RequestRatingAndUIUpdate) and hasn't been run yet. 
  9.1337 +             *        A refresh is requested either at initialization or when a property changes
  9.1338 +             *        (such as MailItem_PropertyChanged). It is on a timer as many 
  9.1339 +             *        property change events could occur rapidy, but only one refresh should
  9.1340 +             *        occur for performance reasons.
  9.1341 +             * 
  9.1342 +             *   2. ImmediateRatingAndUIUpdate
  9.1343 +             *        This will re-calculate the mail item's rating.
  9.1344 +             *        This internally just calls CryptableMailItem.StartProcessing.
  9.1345 +             * 
  9.1346 +             *   3. MailItem_ProcessingCompleted
  9.1347 +             *        When processing of the mail item is complete, this even handler will be called.
  9.1348 +             *        This will update the UI with the latest rating then call StartGetMirror.
  9.1349 +             *        The CopyStateToUI method is used which means any open privacy status form will also
  9.1350 +             *        be updated.
  9.1351 +             * 
  9.1352 +             *   4. MailItem_GetMirrorComplete
  9.1353 +             *        This is the final step in updating the UI, after a mirror is located, it's contents
  9.1354 +             *        will be shown in the unencrypted preview.
  9.1355 +             * 
  9.1356 +             * The general calling sequence is as shown above 1->4 with each component calling the next.
  9.1357 +             * However, for methods that update the mail item directly, commonly only 2->4 is needed.
  9.1358 +             */
  9.1359 +
  9.1360 +            // Ensure the tick method is not called more than once
  9.1361 +            if ((this.isEnabled) &&
  9.1362 +                (refreshOngoing == false))
  9.1363 +            {
  9.1364 +                this.refreshOngoing = true;
  9.1365 +
  9.1366 +                if ((this.cryptableMailItem != null) &&
  9.1367 +                    (this.cryptableMailItem.IsBeingProcessed == false))
  9.1368 +                {
  9.1369 +                    // Attempt to get the download state
  9.1370 +                    try
  9.1371 +                    {
  9.1372 +                        dlState = this.cryptableMailItem.DownloadState;
  9.1373 +                    }
  9.1374 +                    catch (Exception ex)
  9.1375 +                    {
  9.1376 +                        Log.Warning("TimerRefresh_Tick: Get DownloadState failed, " + ex.ToString());
  9.1377 +
  9.1378 +                        // Assume everything is downloaded, but try to download again as well
  9.1379 +                        dlState = Outlook.OlDownloadState.olFullItem;
  9.1380 +                        markForDownload = true;
  9.1381 +                    }
  9.1382 +
  9.1383 +                    if (dlState == Outlook.OlDownloadState.olFullItem)
  9.1384 +                    {
  9.1385 +                        this.ImmediateRatingAndUIUpdate();
  9.1386 +                    }
  9.1387 +                    else
  9.1388 +                    {
  9.1389 +                        markForDownload = true;
  9.1390 +                    }
  9.1391 +
  9.1392 +                    /* 12/16/2016: It could be verified via testing that setting the MarkForDownload property
  9.1393 +                     * can be a way to crash Outlook under certain circumstances (e.g. with IMAP on Outlook 2010 or on Windows 7). 
  9.1394 +                     * This then is not caught by a try/catch block and therefore has to be considered an Outlook bug.
  9.1395 +                     * It seems that in newer versions of Outlook/Windows, they fixed it, causing exceptions, if at all.
  9.1396 +                     * For now, the following is commented out to prevent a crash. If at any point we see that header-only
  9.1397 +                     * messages cause bigger issues, this decision has to be reevaluated.
  9.1398 +                     */
  9.1399 +                    //if (markForDownload)
  9.1400 +                    //{
  9.1401 +                    //    // Try to mark the message for full download
  9.1402 +                    //    try
  9.1403 +                    //    {
  9.1404 +                    //        this.cryptableMailItem.MarkForDownload = Outlook.OlRemoteStatus.olMarkedForDownload;
  9.1405 +                    //        tryAgain = true;
  9.1406 +                    //    }
  9.1407 +                    //    catch (Exception ex)
  9.1408 +                    //    {
  9.1409 +                    //        Log.Warning("TimerRefresh_Tick: MarkForDownload failed, " + ex.ToString());
  9.1410 +                    //    }
  9.1411 +                    //}
  9.1412 +                }
  9.1413 +                else
  9.1414 +                {
  9.1415 +                    repeatProcessing = true;
  9.1416 +                }
  9.1417 +
  9.1418 +                // Set the timer to refresh again later automatically
  9.1419 +                if (tryAgain)
  9.1420 +                {
  9.1421 +                    this.TimerRefresh.Interval = 100;
  9.1422 +                    this.TimerRefresh.Enabled = true;
  9.1423 +                }
  9.1424 +
  9.1425 +                this.refreshOngoing = false;
  9.1426 +            }
  9.1427 +        }
  9.1428 +
  9.1429 +        #endregion
  9.1430 +    }
  9.1431 +}
    10.1 --- a/pEpForOutlook.csproj	Tue Sep 04 11:14:15 2018 +0200
    10.2 +++ b/pEpForOutlook.csproj	Thu Sep 06 09:29:19 2018 +0200
    10.3 @@ -411,12 +411,6 @@
    10.4      <Compile Include="UI\FormRegionPreviewUnencrypted.Designer.cs">
    10.5        <DependentUpon>FormRegionPreviewUnencrypted.cs</DependentUpon>
    10.6      </Compile>
    10.7 -    <Compile Include="UI\FormRegionPrivacyStatus.cs">
    10.8 -      <SubType>UserControl</SubType>
    10.9 -    </Compile>
   10.10 -    <Compile Include="UI\FormRegionPrivacyStatus.Designer.cs">
   10.11 -      <DependentUpon>FormRegionPrivacyStatus.cs</DependentUpon>
   10.12 -    </Compile>
   10.13      <Compile Include="CryptableMailItem.cs" />
   10.14      <Compile Include="Properties\AssemblyInfo.cs">
   10.15        <SubType>Code</SubType>
   10.16 @@ -430,6 +424,8 @@
   10.17      </Compile>
   10.18      <Compile Include="UI\ValueConverters.cs" />
   10.19      <Compile Include="Wrappers\WatchedExplorer.cs" />
   10.20 +    <Compile Include="Wrappers\WatchedInspector.cs" />
   10.21 +    <Compile Include="Wrappers\WatchedWindow.cs" />
   10.22      <EmbeddedResource Include="Properties\Resources.hi.resx">
   10.23        <Generator>PublicResXFileCodeGenerator</Generator>
   10.24        <LastGenOutput>Resources.hi.Designer.cs</LastGenOutput>