Merge with OUT-222
authorThomas
Fri, 20 Jul 2018 13:22:30 +0200
changeset 2310 10c244c9dbd2
parent 2296 8be60b97b838 (current diff)
parent 2309 38bfaf04483e (diff)
child 2311 d97ef018698b
Merge with OUT-222
--- a/CryptableMailItem.cs	Mon Jul 16 12:26:12 2018 +0200
+++ b/CryptableMailItem.cs	Fri Jul 20 13:22:30 2018 +0200
@@ -504,8 +504,9 @@
                         // Save to pEp folder if not already there
                         if (pEpDraftsFolder?.FullFolderPath?.Equals(parentFolder?.FullFolderPath) == false)
                         {
-                            omi = this.internalMailItem.Move(pEpDraftsFolder);
                             currentInspector = this.internalMailItem.GetInspector;
+                            omi = this.internalMailItem.Copy();
+                            omi = omi.Move(pEpDraftsFolder);
 
                             if (currentInspector != null)
                             {
@@ -523,27 +524,24 @@
                                 /* In some circumstances (e.g. ForceProtection on Exchange), the Sender information 
                                  * may be missing. If this is the case, try to add it from the internal mail item.
                                  */
-                                Outlook.MailItem inspectorItem = null;
                                 try
                                 {
-                                    inspectorItem = newInspector.CurrentItem as Outlook.MailItem;
-
                                     // Check if there really is no useful Sender information
-                                    if ((inspectorItem != null) &&
-                                        (inspectorItem.Sender == null) &&
-                                        (string.IsNullOrEmpty(inspectorItem.SenderEmailAddress)) &&
-                                        (inspectorItem.SendUsingAccount == null))
+                                    if ((omi != null) &&
+                                        (omi.Sender == null) &&
+                                        (string.IsNullOrEmpty(omi.SenderEmailAddress)) &&
+                                        (omi.SendUsingAccount == null))
                                     {
                                         // Try to add SendUsingAccount
                                         if (this.internalMailItem.SendUsingAccount != null)
                                         {
-                                            inspectorItem.SendUsingAccount = this.internalMailItem.SendUsingAccount;
+                                            omi.SendUsingAccount = this.internalMailItem.SendUsingAccount;
                                         }
 
                                         // Try to add the Sender directly
                                         if (this.internalMailItem.Sender != null)
                                         {
-                                            inspectorItem.Sender = this.internalMailItem.Sender;
+                                            omi.Sender = this.internalMailItem.Sender;
                                         }
                                     }
                                 }
@@ -551,10 +549,6 @@
                                 {
                                     Log.Error("MailItem_Write: Error determining/setting sender information of new Inspector. " + ex.ToString());
                                 }
-                                finally
-                                {
-                                    inspectorItem = null;
-                                }
 
                                 newInspector.Display();
                                 newInspector.WindowState = windowState;
@@ -652,9 +646,9 @@
                                 draftFileName = sfd.FileName;
                                 this.internalMailItem.SaveAs(draftFileName, Outlook.OlSaveAsType.olMSGUnicode);
                             }
+                        }
 
-                            cancel = true;
-                        }
+                        cancel = true;
                     }
                     else
                     {
@@ -1122,14 +1116,6 @@
         }
 
         /// <summary>
-        /// Gets the outgoing pEp rating of the cryptable mail item.
-        /// </summary>
-        public pEpRating OutgoingRating
-        {
-            get { return this.internalMailItem?.GetOutgoingRating() ?? pEpRating.pEpRatingUndefined; }
-        }
-
-        /// <summary>
         /// Returns a String representing the EntryID for the true recipient as set by the transport provider delivering the mail message.
         /// This forwards the call to the internal mail item.
         /// See: https://msdn.microsoft.com/en-us/library/office/ff869438.aspx
@@ -1420,7 +1406,7 @@
                 {
                     Log.Verbose("ProcessAndGetRating: Draft detected, using outgoing rating.");
 
-                    result = this.OutgoingRating;
+                    result = this.internalMailItem.GetOutgoingRating(true);
                     fullCalculation = false;
                 }
 
@@ -1494,7 +1480,8 @@
                      * which then leads to the form region not being properly displayed at the first click (OUT-68).
                      */
                     if ((isPEPInternal == false) &&
-                         (Globals.OutlookVersion == Globals.Version.Outlook2010 && (this.internalMailItem.GetIsInSecureStore() || this.internalMailItem.DownloadState == Outlook.OlDownloadState.olHeaderOnly)))
+                         ((Globals.OutlookVersion == Globals.Version.Outlook2010) && 
+                          (this.internalMailItem.GetIsInSecureStore() || this.internalMailItem.GetNeverUnsecure())))
                     {
                         try
                         {
--- a/Extensions/MailItemExtensions.cs	Mon Jul 16 12:26:12 2018 +0200
+++ b/Extensions/MailItemExtensions.cs	Fri Jul 20 13:22:30 2018 +0200
@@ -2214,8 +2214,11 @@
         /// Gets the outgoing rating for this mail item.
         /// </summary>
         /// <param name="omi">The Outlook mail item to process with.</param>
+        /// <param name="ignoreOptions">Ignore user settings like ForceProtection or
+        /// ForceUnencrypted and return always calculated engine rating.</param>
         /// <returns>The outgoing rating for the mail item.</returns>
-        public static pEpRating GetOutgoingRating(this Outlook.MailItem omi)
+        public static pEpRating GetOutgoingRating(this Outlook.MailItem omi,
+                                                  bool ignoreOptions = false)
         {
             pEpRating rating = pEpRating.pEpRatingUndefined;
 
@@ -2241,23 +2244,33 @@
                 return pEpRating.pEpRatingUnencrypted;
             }
 
-            // If mail is forcefully protected, return reliable
-            if (omi?.GetIsForcefullyProtected() == true)
+            // If pEp is disabled, return unencrypted
+            if ((omi?.GetIsPEPEnabled() == false) &&
+                (omi.GetEnableProtection() == false))
             {
-                return pEpRating.pEpRatingReliable;
+                return pEpRating.pEpRatingUnencrypted;
             }
 
-            // If mail is forcefully unencrypted, return unencrypted
-            if (omi?.GetIsForceUnencrypted() == true)
+            if (ignoreOptions == false)
             {
-                return pEpRating.pEpRatingUnencrypted;
+                /* If message is forcefully unencrypted, return Unencrypted.
+                 * If message is forcefully encrypted, return Reliable.
+                 */
+                if (omi?.GetIsForcefullyProtected() == true)
+                {
+                    return pEpRating.pEpRatingReliable;
+                }             
+                else if (omi?.GetIsForceUnencrypted() == true)
+                {
+                    return pEpRating.pEpRatingUnencrypted;
+                }
             }
 
             // Else calculate it
             PEPMessage message;
             if (PEPMessage.Create(omi, out message, true, false) == Globals.ReturnStatus.Success)
             {
-                rating = message?.OutgoingRating ?? pEpRating.pEpRatingUndefined;
+                rating = message?.GetOutgoingRating(ignoreOptions) ?? pEpRating.pEpRatingUndefined;
             }
             else
             {
--- a/MsgProcessor.cs	Mon Jul 16 12:26:12 2018 +0200
+++ b/MsgProcessor.cs	Fri Jul 20 13:22:30 2018 +0200
@@ -444,7 +444,7 @@
 
             // Check that message is encrypted if outgoing rating was reliable or more
             if ((processedMessage == null) ||
-                ((sourceMessage.OutgoingRating >= pEpRating.pEpRatingReliable) &&
+                ((sourceMessage.GetOutgoingRating() >= pEpRating.pEpRatingReliable) &&
                 ((processedMessage.IsSecure == false) && string.IsNullOrEmpty(processedMessage.ForceProtectionId))))
             {
                 status = Globals.ReturnStatus.Failure;
@@ -481,7 +481,7 @@
                     contactRating = message.GetOutgoingRatingByRecipients();
 
                     // Engine rating
-                    engineRating = message.OutgoingRating;
+                    engineRating = message.GetOutgoingRating();
 
                     // Merge ratings
                     if (contactRating == pEpRating.pEpRatingUnencrypted)
--- a/PEPMessage.cs	Mon Jul 16 12:26:12 2018 +0200
+++ b/PEPMessage.cs	Fri Jul 20 13:22:30 2018 +0200
@@ -450,50 +450,55 @@
 
         /// <summary>
         /// Gets the outgoing rating of this message.
+        /// <param name="ignoreOptions">Ignore user settings like ForceProtection or
+        /// ForceUnencrypted and return always calculated engine rating.</param>
         /// </summary>
-        public pEpRating OutgoingRating
+        public pEpRating GetOutgoingRating(bool ignoreOptions = false)
         {
-            get
-            {
-                pEpRating rating = pEpRating.pEpRatingUndefined;
+            pEpRating rating = pEpRating.pEpRatingUndefined;
 
 #if READER_RELEASE_MODE
-                // If reader mode, always unencrypted
-                rating = pEpRating.pEpRatingUnencrypted;
+            // If reader mode, always unencrypted
+            rating = pEpRating.pEpRatingUnencrypted;
 #else
-                /* If message is forcefully unencrypted or has BCC recipients,
-                 * always return Unencrypted.
+            // If message has BCC recipients, always return unencrypted
+            if (this.Bcc?.Count > 0)
+            {
+                return pEpRating.pEpRatingUnencrypted;
+            }
+
+            if (ignoreOptions == false)
+            {
+                /* If message is forcefully unencrypted, return Unencrypted.
                  * If message is forcefully encrypted, return Reliable.
-                 * Else, calculate through engine.
-                 */ 
-                if ((this.ForceUnencrypted) ||
-                    (this.Bcc?.Count > 0))
+                 */
+                if (this.ForceUnencrypted)
                 {
-                    rating = pEpRating.pEpRatingUnencrypted;
+                    return pEpRating.pEpRatingUnencrypted;
                 }
                 else if (string.IsNullOrEmpty(this.ForceProtectionId) == false)
                 {
-                    rating = pEpRating.pEpRatingReliable;
+                    return pEpRating.pEpRatingReliable;
                 }
-                else
-                {
-                    PEPMessage workingMessage = this.Copy(true);
-                    workingMessage.FlattenAllRecipientIdentities();
-                    workingMessage.Direction = pEpMsgDirection.pEpDirOutgoing;
-
-                    try
-                    {
-                        rating = ThisAddIn.PEPEngine.OutgoingMessageRating(workingMessage.ToCOMType());
-                    }
-                    catch (Exception ex)
-                    {
-                        rating = pEpRating.pEpRatingUndefined;
-                        Log.Error("OutgoingRating: Error getting outgoing rating from engine. " + ex.ToString());
-                    }
-                }
+            }
+
+            // If we have no rating at this point, calculate it
+            PEPMessage workingMessage = this.Copy(true);
+            workingMessage.FlattenAllRecipientIdentities();
+            workingMessage.Direction = pEpMsgDirection.pEpDirOutgoing;
+
+            try
+            {
+                rating = ThisAddIn.PEPEngine.OutgoingMessageRating(workingMessage.ToCOMType());
+            }
+            catch (Exception ex)
+            {
+                rating = pEpRating.pEpRatingUndefined;
+                Log.Error("GetOutgoingRating: Error getting outgoing rating from engine. " + ex.ToString());
+            }
+
 #endif
-                return rating;
-            }
+            return rating;
         }
 
         /// <summary>
@@ -2213,7 +2218,7 @@
                      *        at least reliable.
                      */
                     if ((accountSettings?.AddDisclaimer == PEPSettings.Disclaimer.AllMessages) ||
-                        ((accountSettings?.AddDisclaimer == PEPSettings.Disclaimer.OnlyEncryptedMessages) && this.OutgoingRating >= pEpRating.pEpRatingReliable))
+                        ((accountSettings?.AddDisclaimer == PEPSettings.Disclaimer.OnlyEncryptedMessages) && this.GetOutgoingRating() >= pEpRating.pEpRatingReliable))
                     {
                         // Add to plain text
                         if (string.IsNullOrEmpty(this._LongMsg) == false)
--- a/Properties/Resources.Designer.cs	Mon Jul 16 12:26:12 2018 +0200
+++ b/Properties/Resources.Designer.cs	Fri Jul 20 13:22:30 2018 +0200
@@ -653,6 +653,16 @@
         /// <summary>
         ///   Looks up a localized resource of type System.Drawing.Bitmap.
         /// </summary>
+        public static System.Drawing.Bitmap ImagePrivacyStatusGreenProtectionDisabled {
+            get {
+                object obj = ResourceManager.GetObject("ImagePrivacyStatusGreenProtectionDisabled", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
         public static System.Drawing.Bitmap ImagePrivacyStatusNoColor {
             get {
                 object obj = ResourceManager.GetObject("ImagePrivacyStatusNoColor", resourceCulture);
@@ -683,6 +693,46 @@
         /// <summary>
         ///   Looks up a localized resource of type System.Drawing.Bitmap.
         /// </summary>
+        public static System.Drawing.Bitmap ImagePrivacyStatusYellowProtectionDisabled {
+            get {
+                object obj = ResourceManager.GetObject("ImagePrivacyStatusYellowProtectionDisabled", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        public static System.Drawing.Bitmap ImageRatingGreen {
+            get {
+                object obj = ResourceManager.GetObject("ImageRatingGreen", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        public static System.Drawing.Bitmap ImageRatingRed {
+            get {
+                object obj = ResourceManager.GetObject("ImageRatingRed", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        public static System.Drawing.Bitmap ImageRatingYellow {
+            get {
+                object obj = ResourceManager.GetObject("ImageRatingYellow", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
         public static System.Drawing.Bitmap ImageReaderSplash {
             get {
                 object obj = ResourceManager.GetObject("ImageReaderSplash", resourceCulture);
--- a/Properties/Resources.resx	Mon Jul 16 12:26:12 2018 +0200
+++ b/Properties/Resources.resx	Fri Jul 20 13:22:30 2018 +0200
@@ -910,4 +910,19 @@
   <data name="KeySyncWizard_PGPPrivateKeyMessageBody" xml:space="preserve">
     <value>Please find attached the private key from your p≡p device. You can now import it into your keychain.</value>
   </data>
+  <data name="ImageRatingGreen" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\resources\imageratinggreen.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="ImageRatingRed" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\resources\imageratingred.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="ImageRatingYellow" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\resources\imageratingyellow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="ImagePrivacyStatusGreenProtectionDisabled" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\ImagePrivacyStatusGreenProtectionDisabled.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="ImagePrivacyStatusYellowProtectionDisabled" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\ImagePrivacyStatusYellowProtectionDisabled.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
 </root>
\ No newline at end of file
Binary file Resources/ImageRatingGreen.png has changed
Binary file Resources/ImageRatingRed.png has changed
Binary file Resources/ImageRatingYellow.png has changed
--- a/UI/FormControlPreviewMessage.xaml.cs	Mon Jul 16 12:26:12 2018 +0200
+++ b/UI/FormControlPreviewMessage.xaml.cs	Fri Jul 20 13:22:30 2018 +0200
@@ -824,8 +824,6 @@
                 this.RaisePropertyChangedEvent(nameof(this.Message));
 
                 this.CalcDependentProperties();
-
-                return;
             }
         }
     }
--- a/UI/FormControlPrivacyStatus.xaml	Mon Jul 16 12:26:12 2018 +0200
+++ b/UI/FormControlPrivacyStatus.xaml	Fri Jul 20 13:22:30 2018 +0200
@@ -9,81 +9,6 @@
              mc:Ignorable="d"
              d:DesignHeight="40"
              d:DesignWidth="600">
-    <UserControl.Resources>
-        <ResourceDictionary>
-            <BooleanToVisibilityConverter x:Key="BoolToVisibility" />
-            <ResourceDictionary.MergedDictionaries>
-                <ResourceDictionary Source="pack://application:,,,/pEp;component/Resources/Dictionary.xaml" />
-            </ResourceDictionary.MergedDictionaries>
-        </ResourceDictionary>
-    </UserControl.Resources>
     <Grid>
-        <Grid.ColumnDefinitions>
-            <ColumnDefinition Width="Auto" />
-            <ColumnDefinition Width="*" />
-            <ColumnDefinition Width="Auto" />
-        </Grid.ColumnDefinitions>
-
-        <!-- Privacy view / button -->
-        <local:PrivacyView x:Name="PrivacyViewRating"
-                           Grid.Column="0"
-                           Mode="Button"
-                           VerticalAlignment="Center"
-                           Rating="{Binding Path=Rating}"
-                           Click="PrivacyViewRating_Click">
-            <local:PrivacyView.Margin>
-                <Thickness Bottom="0"
-                           Left="{StaticResource Spacing}"
-                           Right="{StaticResource Spacing}"
-                           Top="0" />
-            </local:PrivacyView.Margin>
-        </local:PrivacyView>
-
-        <!-- Upgrade link -->
-        <TextBlock Grid.Column="1"
-                   HorizontalAlignment="Left"
-                   VerticalAlignment="Center"
-                   Visibility="{Binding Path=UpgradeLinkIsVisible, Converter={StaticResource BoolToVisibility}, FallbackValue=Collapsed}">
-            <Hyperlink Name="HyperlinkUpgrade"
-                       Click="HyperlinkUpgrade_Click">
-                <TextBlock Text="{Binding Path=UpgradeLinkText, FallbackValue='Upgrade p≡p to send secure messages'}"
-                           FontSize="14" />
-            </Hyperlink>
-        </TextBlock>
-
-        <!-- Logo -->
-        <Image Grid.Column="2"
-               Stretch="Uniform"
-               HorizontalAlignment="Center"
-               VerticalAlignment="Center"
-               MouseLeftButtonUp="Image_MouseLeftButtonUp">
-            <Image.Margin>
-                <Thickness Bottom="1"
-                           Left="{StaticResource Spacing}"
-                           Right="{StaticResource Spacing}"
-                           Top="1" />
-            </Image.Margin>
-            <Image.Style>
-                <Style TargetType="Image">
-                    <Style.Triggers>
-                        <DataTrigger Binding="{Binding ReleaseMode}"
-                                     Value="Standard">
-                            <Setter Property="Source"
-                                    Value="pack://application:,,,/pEp;component/Resources/ImageLogoMedium.png" />
-                            <Setter Property="Cursor"
-                                    Value="Arrow" />
-                        </DataTrigger >
-                        <DataTrigger Binding="{Binding ReleaseMode}"
-                                     Value="Reader">
-                            <Setter Property="Source"
-                                    Value="pack://application:,,,/pEp;component/Resources/ImageLogoBuyMedium.png" />
-                            <Setter Property="Cursor"
-                                    Value="Hand" />
-                        </DataTrigger >
-                    </Style.Triggers>
-                </Style>
-            </Image.Style>
-        </Image>
-
     </Grid>
 </UserControl>
--- a/UI/FormRegionPrivacyStatus.Designer.cs	Mon Jul 16 12:26:12 2018 +0200
+++ b/UI/FormRegionPrivacyStatus.Designer.cs	Fri Jul 20 13:22:30 2018 +0200
@@ -43,48 +43,25 @@
         {
             this.components = new System.ComponentModel.Container();
             this.TimerRefresh = new System.Windows.Forms.Timer(this.components);
-            this.PanelPrivacyStatus = new System.Windows.Forms.Panel();
             this.ElementHostFormControl = new System.Windows.Forms.Integration.ElementHost();
-            this.FormControlPrivacyStatusChild = new pEp.UI.FormControlPrivacyStatus();
-            this.TimerMonitor = new System.Windows.Forms.Timer(this.components);
-            this.PanelPrivacyStatus.SuspendLayout();
             this.SuspendLayout();
             // 
-            // PanelPrivacyStatus
-            // 
-            this.PanelPrivacyStatus.BackColor = System.Drawing.Color.Transparent;
-            this.PanelPrivacyStatus.Controls.Add(this.ElementHostFormControl);
-            this.PanelPrivacyStatus.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.PanelPrivacyStatus.Location = new System.Drawing.Point(0, 0);
-            this.PanelPrivacyStatus.Name = "PanelPrivacyStatus";
-            this.PanelPrivacyStatus.Size = new System.Drawing.Size(500, 36);
-            this.PanelPrivacyStatus.TabIndex = 0;
-            // 
             // ElementHostFormControl
             // 
-            this.ElementHostFormControl.Dock = System.Windows.Forms.DockStyle.Fill;
             this.ElementHostFormControl.Location = new System.Drawing.Point(0, 0);
             this.ElementHostFormControl.Name = "ElementHostFormControl";
-            this.ElementHostFormControl.Size = new System.Drawing.Size(500, 36);
+            this.ElementHostFormControl.Size = new System.Drawing.Size(200, 100);
             this.ElementHostFormControl.TabIndex = 0;
-            this.ElementHostFormControl.Child = this.FormControlPrivacyStatusChild;
-            // 
-            // TimerMonitor
-            // 
-            this.TimerMonitor.Enabled = true;
-            this.TimerMonitor.Interval = 10;
-            this.TimerMonitor.Tick += new System.EventHandler(this.TimerMonitor_Tick);
+            this.ElementHostFormControl.Child = null;
             // 
             // FormRegionPrivacyStatus
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.Controls.Add(this.PanelPrivacyStatus);
             this.Name = "FormRegionPrivacyStatus";
             this.Size = new System.Drawing.Size(500, 36);
             this.FormRegionShowing += new System.EventHandler(this.FormRegionPrivacyStatus_FormRegionShowing);
             this.FormRegionClosed += new System.EventHandler(this.FormRegionPrivacyStatus_FormRegionClosed);
-            this.PanelPrivacyStatus.ResumeLayout(false);
             this.ResumeLayout(false);
 
         }
@@ -108,10 +85,7 @@
         #endregion
 
         private System.Windows.Forms.Timer TimerRefresh;
-        private System.Windows.Forms.Panel PanelPrivacyStatus;
         private System.Windows.Forms.Integration.ElementHost ElementHostFormControl;
-        private UI.FormControlPrivacyStatus FormControlPrivacyStatusChild;
-        private System.Windows.Forms.Timer TimerMonitor;
 
         public partial class FormRegionPrivacyStatusFactory : Microsoft.Office.Tools.Outlook.IFormRegionFactory
         {
--- a/UI/FormRegionPrivacyStatus.cs	Mon Jul 16 12:26:12 2018 +0200
+++ b/UI/FormRegionPrivacyStatus.cs	Fri Jul 20 13:22:30 2018 +0200
@@ -1,11 +1,9 @@
-using MimeKit;
-using pEp.UI;
+using pEp.UI;
 using pEpCOMServerAdapterLib;
 using System;
 using System.ComponentModel;
 using System.Diagnostics;
 using System.Windows.Forms;
-using System.Windows.Input;
 using Outlook = Microsoft.Office.Interop.Outlook;
 
 namespace pEp
@@ -38,6 +36,10 @@
                     e.Cancel = true;
                     return;
                 }
+                finally
+                {
+                    omi = null;
+                }
 
                 //WindowFormRegionCollection formRegions;
 
@@ -66,8 +68,6 @@
                 }
                 catch { }
                 */
-
-                return;
             }
         }
 
@@ -88,24 +88,17 @@
          * The separate privacy status manager form state is also managed here.
          */
 
-        /// <summary>
-        /// Event for when the form region is expanded or collapsed.
-        /// </summary>
-        public event EventHandler Expanded;
-
-        private CryptableMailItem       cryptableMailItem      = null;
-        private bool                    displayMirrorRequested = false;
-        private HandshakeDialog         handshakeDialog        = null;
-        private bool                    isEnabled              = true;
-        private bool?                   isExpandedPrevious     = null;
-        private bool                    isManagerFormEnabled   = true;
-        private bool                    isStarted              = false;
-        private FormManagePrivacyStatus managerForm            = null;
-        private bool                    processingOngoing      = false;
-        private bool                    refreshOngoing         = false;
-        private bool                    repeatProcessing       = false;
-        private int                     repeatCounter          = 0;
-        private const int               maxRepeatCount         = 5;
+        private CryptableMailItem       cryptableMailItem       = null;
+        private bool                    displayMirrorRequested  = false;
+        private HandshakeDialog         handshakeDialog         = null;
+        private bool                    isEnabled               = true;
+        private bool                    isManagerFormEnabled    = true;
+        private bool                    isStarted               = false;
+        private bool                    processingOngoing       = false;
+        private bool                    refreshOngoing          = false;
+        private bool                    repeatProcessing        = false;
+        private int                     repeatCounter           = 0;
+        private const int               maxRepeatCount          = 5;
 
         /**************************************************************
          * 
@@ -114,12 +107,46 @@
          *************************************************************/
 
         /// <summary>
-        /// Gets or sets the displayed state.
+        /// The rating of this message.
+        /// </summary>
+        private pEpRating _Rating = pEpRating.pEpRatingUndefined;
+
+        /// <summary>
+        /// Gets or sets whether to disable the Force Protection option.
+        /// </summary>
+        public bool DisableForceProtection { get; set; } = false;
+
+        /// <summary>
+        /// Gets or sets whether to send this message forcefully protected.
+        /// </summary>
+        public bool ForceProtection { get; set; } = false;
+
+        /// <summary>
+        /// Gets or sets whether to send this message forcefully unencrypted.
         /// </summary>
-        public FormControlPrivacyStatus.State DisplayState
+        public bool ForceUnencrypted { get; set; } = false;
+
+        /// <summary>
+        /// Gets or sets whether to always store this message as if on an untrusted server.
+        /// </summary>
+        public bool NeverUnsecure { get; set; } = false;
+
+        /// <summary>
+        /// Gets the rating of this message.
+        /// </summary>
+        public pEpRating Rating
         {
-            get { return (this.FormControlPrivacyStatusChild.DisplayState); }
-            set { this.FormControlPrivacyStatusChild.DisplayState = value; }
+            get { return this._Rating; }
+        }
+
+        /// <summary>
+        /// Sets the rating of this message and updates the UI.
+        /// </summary>
+        /// <param name="rating">The message rating.</param>
+        public void SetRating(pEpRating rating)
+        {
+            this._Rating = rating;
+            RibbonCustomizations.Invalidate();
         }
 
         /**************************************************************
@@ -129,50 +156,9 @@
          *************************************************************/
 
         /// <summary>
-        /// Determines if this form region is running in an inspector window.
-        /// If not true, it is assumed to be within an explorer window.
-        /// </summary>
-        /// <returns>True if an inspector window, false if within an explorer.</returns>
-        private bool IsWithinInspector()
-        {
-            bool isWithinInspector = false;
-            Outlook.Inspector insp = null;
-
-            try
-            {
-                /* There are two potential methods to determine if the item is within an inspector.
-                 * (1) Use this.OutlookFormRegion.Parent which will contain either the Explorer or an Inspector
-                 *     A cast could be tried to an Explorer of this parent and if it fails, it's assumed to be an inspector
-                 * (2) Use this.OutlookFormRegion.Inspector which will contain the Inspector if it exists.
-                 *     This will fail or return null if this form region is not running within it's own Inspector window.
-                 */
-                insp = this.OutlookFormRegion.Inspector;
-
-                if (insp != null)
-                {
-                    isWithinInspector = true;
-                }
-            }
-            catch
-            {
-                isWithinInspector = false;
-            }
-            finally
-            {
-                if (insp != null)
-                {
-                    // Marshal.ReleaseComObject(insp);
-                    insp = null;
-                }
-            }
-
-            return (isWithinInspector);
-        }
-
-        /// <summary>
         /// Builds the latest state of the encryption status manager then shows the UI.
         /// </summary>
-        private void BuildAndShowManager()
+        public void BuildAndShowManager()
         {
             /* Resolve all recipients -- this ensures the identities list is correctly populated
              * 
@@ -192,21 +178,37 @@
             }
 
             // Build the dialog
+            Outlook.MailItem omi = null;
             try
             {
+                // Get the Outlook mail item
+                omi = this.OutlookItem as Outlook.MailItem;
+
                 // The PEPMessage to build the dialog with
                 PEPMessage message = null;
 
                 // If message is a draft, create it directly from the Outlook mail item
-                if ((this.OutlookItem as Outlook.MailItem)?.GetIsDraft() == true)
+                if (omi?.GetIsDraft() == true)
                 {
                     Log.Verbose("BuildAndShowManager: Creating PEPMessage from draft.");
 
-                    if (PEPMessage.Create((this.OutlookItem as Outlook.MailItem), out message) != Globals.ReturnStatus.Success)
+                    if (PEPMessage.Create(omi, out message) != Globals.ReturnStatus.Success)
                     {
                         Log.Error("BuildAndShowManager: Error creating PEPMessage from draft.");
                         message = null;
                     }
+
+                    // If Force Protection is set, assign a random GUID
+                    if ((this.ForceProtection) &&
+                        (this.DisableForceProtection == false))
+                    {
+                        message.ForceProtectionId = Guid.NewGuid().ToString();
+                    }
+
+                    // If message is Force Unencrypted, assign it
+                    message.ForceUnencrypted = this.ForceUnencrypted;
+
+                    omi = null;
                 }
                 else
                 {
@@ -219,13 +221,10 @@
                     {
                         Log.Verbose("BuildAndShowManager: Using fallback method to get message.");
 
-                        Outlook.MailItem omi = null;
                         Outlook.MailItem mirror = null;
 
                         try
                         {
-                            omi = this.OutlookItem as Outlook.MailItem;
-
                             // For securely stored mails, try to look up mirror
                             if (omi?.GetIsSecurelyStored() == true)
                             {
@@ -291,11 +290,10 @@
                 // Build dialog
                 if (message != null)
                 {
-                    message.Rating = AdapterExtensions.ReevaluateMessageRating(message);
                     handshakeDialog = new HandshakeDialog(message, this.cryptableMailItem.Myself, this.cryptableMailItem.IsDraft);
                     handshakeDialog.OnUpdateStatus += HandshakeDialog_Updated;
                     handshakeDialog.Closed += HandshakeDialog_Closed;
-                    handshakeDialog.ShowDialog();
+                    handshakeDialog.Show();
                 }
                 else
                 {
@@ -306,6 +304,10 @@
             {
                 Globals.StopAndSendCrashReport(ex);
             }
+            finally
+            {
+                omi = null;
+            }
         }
 
         /// <summary>
@@ -355,7 +357,6 @@
             {
                 this.ResolveAllRecipients();
                 this.RequestRatingAndUIUpdate();
-                RibbonCustomizations.Invalidate();
             }
         }
 
@@ -406,7 +407,7 @@
                         }
                         else
                         {
-                            tempFolder = store.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
+                            tempFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
                         }
 
                         if (tempFolder != null)
@@ -456,35 +457,11 @@
                 }
                 finally
                 {
-                    if (application != null)
-                    {
-                        //Marshal.ReleaseComObject(application);
-                        application = null;
-                    }
-
-                    if (currentInspector != null)
-                    {
-                        // Marshal.ReleaseComObject(currentInspector);
-                        currentInspector = null;
-                    }
-
-                    if (newInspector != null)
-                    {
-                        // Marshal.ReleaseComObject(newInspector);
-                        newInspector = null;
-                    }
-
-                    if (tempMailItem != null)
-                    {
-                        // Marshal.ReleaseComObject(tempMailItem);
-                        tempMailItem = null;
-                    }
-
-                    if (omi != null)
-                    {
-                        // Marshal.ReleaseComObject(omi);
-                        omi = null;
-                    }
+                    application = null;
+                    currentInspector = null;
+                    newInspector = null;
+                    omi = null;
+                    tempMailItem = null;
                 }
             }
 
@@ -492,54 +469,6 @@
         }
 
         /// <summary>
-        /// Immediately update the manage privacy status form display state.
-        /// This by default will completely rebuild the display state.
-        /// </summary>
-        private void UpdateManagePrivacyStatusForm()
-        {
-            if (this.managerForm != null)
-            {
-                // Only update the message rating
-                this.managerForm.DisplayState.Rating = this.FormControlPrivacyStatusChild.DisplayState.Rating;
-            }
-
-            return;
-        }
-
-        /// <summary>
-        /// Sets the rating of the privacy status bar.
-        /// </summary>
-        /// <param name="rating">The rating to set.</param>
-        public void SetRating(pEpRating rating)
-        {
-            try
-            {
-                // Marshal code back to UI thread as necessary
-                this.Invoke(new Action(() =>
-                {
-                    if (this.isEnabled)
-                    {
-                        try
-                        {
-                            this.FormControlPrivacyStatusChild.DisplayState.Rating = rating;
-                            FormControlPrivacyStatus.PreviousRating = rating;
-                            RibbonCustomizations.Invalidate();
-                            this.UpdateManagePrivacyStatusForm(); // Only update the rating
-                        }
-                        catch (Exception ex)
-                        {
-                            Log.Verbose("FormRegionPrivacyStatus.UpdateRating: Error. " + ex.ToString());
-                        }
-                    }
-                }));
-            }
-            catch (Exception ex)
-            {
-                Log.Verbose("FormRegionPrivacyStatus.UpdateRating: Error occured. " + ex.ToString());
-            }
-        }
-
-        /// <summary>
         /// Clears the associated unencrypted preview and displays the given note (if any).
         /// </summary>
         /// <param name="note">The note to diplsay.</param>
@@ -574,7 +503,6 @@
             Outlook.Account sendingAccount = null;
             Outlook.NameSpace ns = null;
 
-            this.OutlookFormRegion.Visible = enabled;
             this.isEnabled = enabled;
 
             if (enabled)
@@ -638,66 +566,26 @@
                             }
                         }
                     }
-                    catch { }
+                    catch (Exception ex)
+                    {
+                        Log.Error("SetIsEnabled: Error occured. " + ex.ToString());
+                    }
                     finally
                     {
-                        if (omi != null)
-                        {
-                            // Marshal.ReleaseComObject(omi);
-                            omi = null;
-                        }
-
-                        if (currUser != null)
-                        {
-                            //Marshal.ReleaseComObject(currUser);
-                            currUser = null;
-                        }
-
-                        if (currAccount != null)
-                        {
-                            //Marshal.ReleaseComObject(currAccount);
-                            currAccount = null;
-                        }
-
-                        if (sendingAccount != null)
-                        {
-                            //Marshal.ReleaseComObject(sendingAccount);
-                            sendingAccount = null;
-                        }
-
-                        if (ns != null)
-                        {
-                            //Marshal.ReleaseComObject(ns);
-                            ns = null;
-                        }
+                        currAccount = null;
+                        currUser = null;
+                        ns = null;
+                        omi = null;
+                        sendingAccount = null;
                     }
 
-                    // Set reader upgrade link visibility
-                    if ((Globals.RELEASE_MODE == Globals.ReleaseMode.Reader) &&
-                        (this.cryptableMailItem != null) &&
-                        (this.cryptableMailItem.IsDraft))
-                    {
-                        this.FormControlPrivacyStatusChild.DisplayState.UpgradeLinkIsVisible = true;
-                    }
-                    else
-                    {
-                        this.FormControlPrivacyStatusChild.DisplayState.UpgradeLinkIsVisible = false;
-                    }
-
-                    // Connect events
-                    this.FormControlPrivacyStatusChild.PrivacyViewClick += FormControlPrivacyStatusChild_PrivacyViewClick;
-                    this.Expanded += FormRegionPrivacyStatus_Expanded;
-
+                    // Connect refresh timer
                     this.TimerRefresh.Tick += TimerRefresh_Tick;
                     this.isStarted = true;
                 }
             }
             else
             {
-                // Disconnect events
-                this.FormControlPrivacyStatusChild.PrivacyViewClick -= FormControlPrivacyStatusChild_PrivacyViewClick;
-                this.Expanded -= FormRegionPrivacyStatus_Expanded;
-
                 // Stop and disconnect the refresh timer
                 this.TimerRefresh.Stop();
                 this.TimerRefresh.Enabled = false;
@@ -735,8 +623,6 @@
                     Log.Error("Error resolving recipients. " + ex.ToString());
                 }
             }
-
-            return;
         }
 
         /**************************************************************
@@ -758,6 +644,9 @@
             string messageId = null;
             Outlook.MailItem omi = null;
 
+            // Do not show the form region
+            this.OutlookFormRegion.Visible = false;
+
             // Set mail item
             omi = this.OutlookItem as Outlook.MailItem;
 
@@ -792,7 +681,11 @@
                     }
                 }
 
-                this.SetRating(provisionalRating);
+                // Only set rating if one has been retrieved
+                if (provisionalRating != pEpRating.pEpRatingUndefined)
+                {
+                    this.SetRating(provisionalRating);
+                }
 
                 /* Check if item is attached mail. For performance reasons,
                  * only do the whole check if an item has been loaded to the
@@ -917,12 +810,7 @@
                             Log.Error("FormRegionPrivacyStatus_FormRegionShowing: Error occured. " + ex.ToString());
                         }
 
-                        if (omi.GetIsSMIMEEnabled())
-                        {
-                            // Do not show form region for S/MIME messages
-                            enableFormRegion = false;
-                        }
-                        else if (omi.GetIsPEPEnabled())
+                        if (omi.GetIsPEPEnabled())
                         {
                             // If pEp is enabled, show the form region
                             enableFormRegion = true;
@@ -937,18 +825,14 @@
                              *                          current code runs before CryptableMailItem.MailItem_Reply
                              *                          or CryptableMailItem.MailItem_Forward.
                              */
-                            if (omi.GetIsIncoming() || omi.GetIsInSentFolder())
+                            if (omi.GetIsDraft())
                             {
-                                enableFormRegion = omi.GetIsDecryptAlwaysEnabled();
+                                enableFormRegion = true;
+                                this.cryptableMailItem.OriginallyEncryptedStatusUpdated += CryptableMailItem_OriginallyEncryptedStatusUpdated;
                             }
                             else
                             {
-                                enableFormRegion = omi.GetEnableProtection();
-
-                                if (enableFormRegion == false)
-                                {
-                                    this.cryptableMailItem.OriginallyEncryptedStatusUpdated += CryptableMailItem_OriginallyEncryptedStatusUpdated;
-                                }
+                                enableFormRegion = omi.GetIsDecryptAlwaysEnabled();
                             }
                         }
                     }
@@ -999,6 +883,7 @@
                     this.cryptableMailItem.GetMirrorCompleted -= MailItem_GetMirrorCompleted;
                     this.cryptableMailItem.Open -= MailItem_Open;
                     this.cryptableMailItem.Send -= MailItem_Send;
+                    this.cryptableMailItem.OriginallyEncryptedStatusUpdated -= CryptableMailItem_OriginallyEncryptedStatusUpdated;
                 }
                 catch { }
 
@@ -1008,46 +893,6 @@
 
             // Disconnect other
             this.SetIsEnabled(false);
-
-            return;
-        }
-
-        /// <summary>
-        /// Event handler for when the form region is expanded or collapsed.
-        /// </summary>
-        private void FormRegionPrivacyStatus_Expanded(object sender, EventArgs e)
-        {
-            /* This Outlook form region has a bug where clicking the '+' button to expand will also
-             * raise a click event on the privacy status button. Basically, Outlook would fire the click event 
-             * (FormControlPrivacyStatusChild_PrivacyViewClick) immediately after the region is expanded even though at 
-             * the time it was clicked it was collapsed and the click already captured by the expander '+' button.
-             * This code here works around that issue by disabling the manager form when the form region is collapsed.
-             * Since the click event occurs BEFORE the expanded event, this will disable opening the manage privacy status
-             * form in this situation.
-             */
-            this.isManagerFormEnabled = this.OutlookFormRegion.IsExpanded;
-
-            return;
-        }
-
-        /// <summary>
-        /// Event handler called after the monitor timer has elapsed.
-        /// This should be used only for quick polling of changes in Outlook or the UI state.
-        /// </summary>
-        private void TimerMonitor_Tick(object sender, EventArgs e)
-        {
-            bool isExpandedCurrent;
-
-            // Check for IsExpanded changes
-            isExpandedCurrent = this.OutlookFormRegion.IsExpanded;
-            if ((this.isExpandedPrevious == null) ||
-                ((bool)this.isExpandedPrevious != isExpandedCurrent))
-            {
-                this.Expanded?.Invoke(this, new EventArgs());
-            }
-            this.isExpandedPrevious = isExpandedCurrent;
-
-            return;
         }
 
         /// <summary>
@@ -1178,9 +1023,7 @@
                         {
                             try
                             {
-                                this.FormControlPrivacyStatusChild.DisplayState.Rating = e.ProcessedRating;
-                                RibbonCustomizations.Invalidate();
-                                this.UpdateManagePrivacyStatusForm(); // Only update the rating
+                                this.SetRating(e.ProcessedRating);
                                 Log.Verbose("MailItem_ProcessingComplete: Status bar updated with rating " + Enum.GetName(typeof(pEpRating), e.ProcessedRating));
                             }
                             catch (Exception ex)
@@ -1222,10 +1065,6 @@
                                 {
                                     Log.Verbose("MailItem_ProcessingComplete: Error while checking if mail item is in outbox or updating inspector. " + ex.Message);
                                 }
-                                finally
-                                {
-                                    omi = null;
-                                }
 
                                 /* Create the unencrypted preview if the mail item is encrypted and
                                  * it is in an encrypted (untrusted) store
@@ -1251,6 +1090,58 @@
                                     // While rare, just log the issue and stop the process
                                     Log.Warning("MailItem_ProcessingComplete: Failed to start mirror location, " + ex.ToString());
                                 }
+
+                                /* OUT-470: Workaround until this is implemented in the engine:
+                                 * Only enable Force Protection if all recipients are grey
+                                 */
+                                if (omi?.GetIsDraft() == true)
+                                {
+                                    bool disableForceProtection = false;
+                                    Outlook.Recipients recipients = null;
+                                    Outlook.Recipient recipient = null;
+                                    PEPIdentity pEpIdentity = null;
+
+                                    try
+                                    {
+                                        recipients = omi?.Recipients;
+                                        if (omi.Recipients?.Count > 0)
+                                        {
+                                            for (int i = 1; i <= recipients.Count; i++)
+                                            {
+                                                recipient = recipients[i];
+                                                if ((PEPIdentity.Create(recipient, out pEpIdentity, false) == Globals.ReturnStatus.Success) &&
+                                                    ((PEPIdentity.GetIsOwnIdentity(pEpIdentity.Address) ||
+                                                     (ThisAddIn.PEPEngine.IdentityRating(pEpIdentity.ToCOMType()) >= pEpRating.pEpRatingReliable))))
+                                                {
+                                                    disableForceProtection = true;
+                                                    Log.Verbose("ToggleButtonForceProtection_GetEnabled: Secure recipient found. Disabling force protection.");
+                                                    break;
+                                                }
+                                            }
+                                        }
+                                        else
+                                        {
+                                            // If there aren't any recipients (anymore), reset values
+                                            this.DisableForceProtection = false;
+                                            this.ForceProtection = false;
+                                            this.NeverUnsecure = false;
+                                            this.ForceUnencrypted = false;
+                                        }
+                                    }
+                                    catch (Exception ex)
+                                    {
+                                        Log.Error("ToggleButtonForceProtection_GetEnabled: Error occured. " + ex.ToString());
+                                    }
+                                    finally
+                                    {
+                                        recipient = null;
+                                        recipients = null;
+                                    }
+
+                                    this.DisableForceProtection = disableForceProtection;
+                                }
+
+                                omi = null;
                             }
                         }
                     }));
@@ -1282,7 +1173,7 @@
 
                             // If the message was forcefully protected, there is no mirror and we show the actual message
                             if ((e.Mirror == null) &&
-                                (this.OutlookItem as Outlook.MailItem).GetIsForcefullyProtected())
+                            (this.OutlookItem as Outlook.MailItem).GetIsForcefullyProtected())
                             {
                                 PEPMessage mirror = null;
                                 if (PEPMessage.Create((this.OutlookItem as Outlook.MailItem), out mirror) == Globals.ReturnStatus.Success)
@@ -1320,7 +1211,7 @@
 
                             // Display the mirror if necessary
                             if ((this.cryptableMailItem != null) &&
-                                (this.displayMirrorRequested))
+                            (this.displayMirrorRequested))
                             {
                                 this.cryptableMailItem.DisplayMirror();
                                 this.displayMirrorRequested = false;
@@ -1344,14 +1235,10 @@
         private void CryptableMailItem_OriginallyEncryptedStatusUpdated(object sender, EventArgs e)
         {
             // Process the mail item now that the cache is updated
-            if (this.isEnabled == false &&
-                this.cryptableMailItem.IsOriginallyEncrypted)
+            if (this.cryptableMailItem.IsOriginallyEncrypted)
             {
-                this.isEnabled = true;
                 this.TimerRefresh_Tick(null, new EventArgs());
             }
-
-            return;
         }
 
         /// <summary>
@@ -1416,7 +1303,7 @@
 
                 if ((Globals.ThisAddIn.Settings.IsSecurityLossWarningEnabled) &&
                     (this.cryptableMailItem.IsOriginallyEncrypted) &&
-                    (this.FormControlPrivacyStatusChild.DisplayState.Rating < pEpRating.pEpRatingUnreliable))
+                    (this.Rating < pEpRating.pEpRatingUnreliable))
                 {
 
 #if READER_RELEASE_MODE
@@ -1429,11 +1316,11 @@
                         cancel = true;
                     }
 #else
-                    result = System.Windows.Forms.MessageBox.Show(this.ParentForm,
-                                                                  pEp.Properties.Resources.Message_WarningSecurityLoss,
-                                                                  pEp.Properties.Resources.Message_TitleConfirmOperation,
-                                                                  MessageBoxButtons.YesNo,
-                                                                  MessageBoxIcon.Warning);
+                    result = MessageBox.Show(this.ParentForm,
+                                             Properties.Resources.Message_WarningSecurityLoss,
+                                             Properties.Resources.Message_TitleConfirmOperation,
+                                             MessageBoxButtons.YesNo,
+                                             MessageBoxIcon.Warning);
 
                     if (result == DialogResult.No)
                     {
@@ -1443,6 +1330,25 @@
 #endif
                 }
 
+                if (cancel == false)
+                {
+                    if ((this.ForceProtection) &&
+                        (this.DisableForceProtection == false))
+                    {
+                        (this.OutlookItem as Outlook.MailItem)?.SetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, Guid.NewGuid().ToString());
+                    }
+                    else if (this.ForceUnencrypted)
+                    {
+                        (this.OutlookItem as Outlook.MailItem)?.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, true);
+                    }
+
+                    if (this.NeverUnsecure)
+                    {
+                        (this.OutlookItem as Outlook.MailItem)?.SetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, true);
+                    }
+
+                }
+
                 // Stop and disconnect the refresh timer
                 // This is necessary so an ongoing refresh doesn't try to access a mail item as it's being moved
                 if (cancel == false)
@@ -1556,51 +1462,5 @@
                 this.handshakeDialog = null;
             }
         }
-
-        /// <summary>
-        /// Event handler for when the manager form is closed.
-        /// </summary>
-        private void ManagerForm_FormClosed(object sender, FormClosedEventArgs e)
-        {
-            // Remove the reference held in the FormRegionPrivacyStatus so it stops getting updated
-            if (this.managerForm != null)
-            {
-                this.managerForm.FormClosed -= ManagerForm_FormClosed;
-                this.managerForm = null;
-            }
-
-            return;
-        }
-
-        /// <summary>
-        /// Event handler for when the pEp website hyperlink is clicked.
-        /// </summary>
-        private void LinkLabelUpgrade_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
-        {
-            try
-            {
-                Process.Start(Globals.PEP_WEBSITE_UPGRADE_LINK);
-            }
-            catch (Exception ex)
-            {
-                Log.Error("LinkLabelUpgrade_LinkClicked: Unable to open website link, " + ex.ToString());
-            }
-
-            return;
-        }
-
-        /// <summary>
-        /// Event handler for when the privacy view button is clicked within the form control.
-        /// </summary>
-        private void FormControlPrivacyStatusChild_PrivacyViewClick(object sender, System.Windows.RoutedEventArgs e)
-        {
-            if (this.isManagerFormEnabled)
-            {
-                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
-                this.BuildAndShowManager();
-            }
-
-            return;
-        }
     }
 }
--- a/UI/HandshakeDialog.xaml.cs	Mon Jul 16 12:26:12 2018 +0200
+++ b/UI/HandshakeDialog.xaml.cs	Fri Jul 20 13:22:30 2018 +0200
@@ -127,7 +127,7 @@
             this._Message = message;
             this._IsIncoming = message.Direction == pEpMsgDirection.pEpDirIncoming;
             this._IsDraft = isDraft;
-            this._MessageRating = (this._IsDraft) ? message.OutgoingRating : message.Rating;
+            this._MessageRating = (this._IsDraft) ? message.GetOutgoingRating() : AdapterExtensions.ReevaluateMessageRating(message);
 
             try
             {
@@ -536,7 +536,7 @@
         public void Reload()
         {
             // Update message rating (needed for dialog wording)
-            this._MessageRating = (this._IsDraft) ? this.Message.OutgoingRating : AdapterExtensions.ReevaluateMessageRating(this.Message);
+            this._MessageRating = (this._IsDraft) ? this.Message.GetOutgoingRating() : AdapterExtensions.ReevaluateMessageRating(this.Message);
 
             // Rebuild state
             this.BuildDialog();
--- a/UI/RibbonCustomizations.cs	Mon Jul 16 12:26:12 2018 +0200
+++ b/UI/RibbonCustomizations.cs	Fri Jul 20 13:22:30 2018 +0200
@@ -6,6 +6,7 @@
 using System.Reflection;
 using System.Runtime.InteropServices;
 using System.Windows.Forms;
+using System.Windows.Input;
 using Office = Microsoft.Office.Core;
 using Outlook = Microsoft.Office.Interop.Outlook;
 
@@ -38,6 +39,130 @@
 
         /**************************************************************
          * 
+         * Property accessors
+         * 
+         *************************************************************/
+
+        /// <summary>
+        /// Gets whether the Force Protection option is disabled for the current mail item.
+        /// </summary>
+        /// <param name="control">The current button control.</param>
+        /// <returns>True if the Force Protection option is disabled for the current mail item, otherwise false.</returns>
+        internal bool GetDisableForceProtection(Office.IRibbonControl control)
+        {
+            return this.GetFormRegionPrivacyStatus(control)?.DisableForceProtection ?? false;
+        }
+
+        /// <summary>
+        /// Sets whether the Force Protection option should be disabled for the current mail item.
+        /// </summary>
+        /// <param name="control">The current button control.</param>
+        /// <param name="disable">Whether to disable the Force Protection option or not</param>
+        internal void SetDisableForceProtection(Office.IRibbonControl control, bool disable)
+        {
+            try
+            {
+                this.GetFormRegionPrivacyStatus(control).DisableForceProtection = disable;
+            }
+            catch (Exception ex)
+            {
+                Log.Error("SetDisableForceProtection: Error setting value. " + ex.ToString());
+            }
+        }
+
+        /// <summary>
+        /// Gets whether the current mail item is forcefully protected.
+        /// </summary>
+        /// <param name="control">The current button control.</param>
+        /// <returns>True if the current mail item is forcefully protected, otherwise false.</returns>
+        internal bool GetForceProtection(Office.IRibbonControl control)
+        {
+            return this.GetFormRegionPrivacyStatus(control)?.ForceProtection ?? false;
+        }
+
+        /// <summary>
+        /// Sets whether the current mail item should be forcefully protected or not.
+        /// </summary>
+        /// <param name="control">The current button control.</param>
+        /// <param name="forceProtection">Whether to enable Force Protection or not.</param>
+        internal void SetForceProtection(Office.IRibbonControl control, bool forceProtection)
+        {
+            try
+            {
+                this.GetFormRegionPrivacyStatus(control).ForceProtection = forceProtection;
+            }
+            catch (Exception ex)
+            {
+                Log.Error("SetForceProtection: Error setting value. " + ex.ToString());
+            }
+        }
+
+        /// <summary>
+        /// Gets whether the current mail item is forcefully unencrypted.
+        /// </summary>
+        /// <param name="control">The current button control.</param>
+        /// <returns>True if the current mail item is forcefully unencrypted, otherwise false.</returns>
+        internal bool GetForceUnencrypted(Office.IRibbonControl control)
+        {
+            return this.GetFormRegionPrivacyStatus(control)?.ForceUnencrypted ?? false;
+        }
+
+        /// <summary>
+        /// Sets whether the current mail item should be forcefully unencrypted or not.
+        /// </summary>
+        /// <param name="control">The current button control.</param>
+        /// <param name="forceUnencrypted">Whether to enable Force Unencrypted or not.</param>
+        internal void SetForceUnencrypted(Office.IRibbonControl control, bool forceUnencrypted)
+        {
+            try
+            {
+                this.GetFormRegionPrivacyStatus(control).ForceUnencrypted = forceUnencrypted;
+            }
+            catch (Exception ex)
+            {
+                Log.Error("SetForceUnencrypted: Error setting value. " + ex.ToString());
+            }
+        }
+
+        /// <summary>
+        /// Gets whether the current mail item has the Never Unsecure option set
+        /// </summary>
+        /// <param name="control">The current button control.</param>
+        /// <returns>True if the current mail item has the Never Unsecure option set, otherwise false.</returns>
+        internal bool GetNeverUnsecure(Office.IRibbonControl control)
+        {
+            return this.GetFormRegionPrivacyStatus(control)?.NeverUnsecure ?? false;
+        }
+
+        /// <summary>
+        /// Sets whether the current mail item should be forcefully unencrypted or not.
+        /// </summary>
+        /// <param name="control">The current button control.</param>
+        /// <param name="neverUnsecure">Whether to enable Force Unencrypted or not.</param>
+        internal void SetNeverUnsecure(Office.IRibbonControl control, bool neverUnsecure)
+        {
+            try
+            {
+                this.GetFormRegionPrivacyStatus(control).NeverUnsecure = neverUnsecure;
+            }
+            catch (Exception ex)
+            {
+                Log.Error("SetNeverUnsecure: Error setting value. " + ex.ToString());
+            }
+        }
+
+        /// <summary>
+        /// Gets the current UI rating as determined in the associated form region.
+        /// </summary>
+        /// <param name="control">The current button control.</param>
+        /// <returns>The pEpRating of the current message or undefined if an error occured.</returns>
+        private pEpRating GetRating(Office.IRibbonControl control)
+        {
+            return this.GetFormRegionPrivacyStatus(control)?.Rating ?? pEpRating.pEpRatingUndefined;
+        }
+
+        /**************************************************************
+         * 
          * Methods
          * 
          *************************************************************/
@@ -49,7 +174,167 @@
         public static void Invalidate()
         {
             RibbonCustomizations.ribbon?.Invalidate();
-            return;
+        }
+
+        /// <summary>
+        /// Gets the Outlook contact item that is associated with a given control's parent
+        /// window (Inspector / Explorer). Can return null.
+        /// </summary>
+        /// <param name="control">The control to get the associated contact item for.</param>
+        /// <returns>The associated contact item or null if an error occured.</returns>
+        private Outlook.ContactItem GetContactItem(Office.IRibbonControl control)
+        {
+            Outlook.ContactItem oci = null;
+            Outlook.Inspector inspector = null;
+            Outlook.Explorer explorer = null;
+            Outlook.Selection selection = null;
+
+            try
+            {
+                inspector = control.Context as Outlook.Inspector;
+                if (inspector != null)
+                {
+                    oci = inspector.CurrentItem as Outlook.ContactItem;
+                }
+                else
+                {
+                    explorer = control.Context as Outlook.Explorer;
+                    if (explorer != null)
+                    {
+                        selection = explorer.Selection;
+                        if (selection.Count > 0)
+                        {
+                            oci = selection[1] as Outlook.ContactItem;
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                oci = null;
+                Log.Error("GetFormRegionPrivacyStatus: Error getting form region. " + ex.ToString());
+            }
+            finally
+            {
+                inspector = null;
+                explorer = null;
+                selection = null;
+            }
+
+            return oci;
+        }
+
+        /// <summary>
+        /// Gets whether S/MIME encryption or signature is enabled.
+        /// </summary>
+        /// <returns>True if S/MIME encryption or signature is enabled, otherwise false.</returns>
+        private bool GetIsSMIMEEnabled(Office.IRibbonControl control)
+        {
+            bool isEnabled = false;
+            Outlook.MailItem omi = null;
+
+            try
+            {
+                omi = this.GetMailItem(control);
+                isEnabled = (omi?.GetIsSMIMEEnabled() == true);
+            }
+            catch (Exception ex)
+            {
+                isEnabled = false;
+                Log.Error("RibbonCustomizations.GetIsSMIMEEnabled: Error getting whether S/MIME processing is enabled. " + ex.ToString());
+            }
+            finally
+            {
+                omi = null;
+            }
+
+            return isEnabled;
+        }
+
+        /// <summary>
+        /// Gets the FormRegionPrivacyStatus that is associated with a given control's parent
+        /// window (Inspector / Explorer). Can return null.
+        /// </summary>
+        /// <param name="control">The control to get the associated form region for.</param>
+        /// <returns>The associated FormRegionPrivacyStatus or null if an error occured.</returns>
+        private FormRegionPrivacyStatus GetFormRegionPrivacyStatus(Office.IRibbonControl control)
+        {
+            dynamic window = null;
+            FormRegionPrivacyStatus formRegion = null;
+
+            try
+            {
+                // Get the parent window
+                window = control.Context as Outlook.Explorer;
+                if (window == null)
+                {
+                    window = control.Context as Outlook.Inspector;
+                }
+
+                if (window != null)
+                {
+                    formRegion = Globals.FormRegions[window].FormRegionPrivacyStatus;
+                }
+            }
+            catch (Exception ex)
+            {
+                formRegion = null;
+                Log.Error("GetFormRegionPrivacyStatus: Error getting form region. " + ex.ToString());
+            }
+            finally
+            {
+                window = null;
+            }
+
+            return formRegion;
+        }
+
+        /// <summary>
+        /// Gets the Outlook mail item that is associated with a given control's parent
+        /// window (Inspector / Explorer). Can return null.
+        /// </summary>
+        /// <param name="control">The control to get the associated mail item for.</param>
+        /// <returns>The associated mail item or null if an error occured.</returns>
+        private Outlook.MailItem GetMailItem(Office.IRibbonControl control)
+        {
+            Outlook.MailItem omi = null;
+            Outlook.Inspector inspector = null;
+            Outlook.Explorer explorer = null;
+            Outlook.Selection selection = null;
+
+            try
+            {
+                inspector = control.Context as Outlook.Inspector;
+                if (inspector != null)
+                {
+                    omi = inspector.CurrentItem as Outlook.MailItem;
+                }
+                else
+                {
+                    explorer = control.Context as Outlook.Explorer;
+                    if (explorer != null)
+                    {
+                        selection = explorer.Selection;
+                        if (selection.Count > 0)
+                        {
+                            omi = selection[1] as Outlook.MailItem;
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                omi = null;
+                Log.Error("GetFormRegionPrivacyStatus: Error getting form region. " + ex.ToString());
+            }
+            finally
+            {
+                inspector = null;
+                explorer = null;
+                selection = null;
+            }
+
+            return omi;
         }
 
         /// <summary>
@@ -57,7 +342,7 @@
         /// This will manage/save states as well.
         /// </summary>
         /// <param name="page">The page to open the options form to.</param>
-        private void ShowOptions(FormControlOptions.State.OptionPages page)
+        private void ShowOptions(FormControlOptions.State.OptionPages page = FormControlOptions.State.OptionPages.Accounts)
         {
             DialogResult result;
             FormOptions form;
@@ -94,138 +379,50 @@
         /// Determines if the active UI mail item has pEp enabled for it.
         /// </summary>
         /// <returns>True if the mail item has pEp enabled, otherwise false.</returns>
-        private bool GetIsPEPEnabled()
+        private bool GetIsPEPEnabled(Office.IRibbonControl control)
         {
-            bool result = PEPSettings.ACCOUNT_SETTING_IS_PEP_ENABLED_DEFAULT;
-            Outlook.MailItem currMailItem = null;
-            Outlook.Inspector insp = Globals.ThisAddIn.Application.ActiveInspector();
-
-            // Look for the property
-            if ((insp != null) &&
-                (insp.CurrentItem != null) &&
-                (insp.CurrentItem is Outlook.MailItem))
-            {
-                currMailItem = (Outlook.MailItem)insp.CurrentItem;
-                result = currMailItem.GetIsPEPEnabled();
-            }
-
-            if (currMailItem != null)
-            {
-                // Marshal.ReleaseComObject(currMailItem);
-                currMailItem = null;
-            }
+            Outlook.MailItem omi = null;
+            bool isEnabled = PEPSettings.ACCOUNT_SETTING_IS_PEP_ENABLED_DEFAULT;
 
-            if (insp != null)
-            {
-                // Marshal.ReleaseComObject(insp);
-                insp = null;
-            }
-
-            return (result);
-        }
-
-        /// <summary>
-        /// Gets the pEp rating of the mail item currently active in the UI.
-        /// This method will not do any calculation itself.
-        /// </summary>
-        private pEpRating GetDisplayRating()
-        {
-            pEpRating rating = pEpRating.pEpRatingUndefined;
-            Outlook.Inspector insp = Globals.ThisAddIn.Application.ActiveInspector();
-            Outlook.MailItem omi = insp?.CurrentItem as Outlook.MailItem;
-            WindowFormRegionCollection formRegions = null;
-
-            // Note: Leave the check to make sure the UI is for a MailItem
             try
             {
-                // If pEp is disabled and no protection is set, rating is unencrypted
-                object enableProtection = null;
-                if ((omi?.GetIsPEPEnabled() == false) &&
-                    (omi.GetPEPProperty(MailItemExtensions.PEPProperty.EnableProtection, out enableProtection)) &&
-                    (enableProtection as bool?) == false)
-                {
-                    return pEpRating.pEpRatingUnencrypted;
-                }
-
-                if (omi != null)
-                {
-                    formRegions = Globals.FormRegions[insp];
-
-                    if ((formRegions != null) &&
-                        (formRegions.FormRegionPrivacyStatus != null))
-                    {
-                        rating = formRegions.FormRegionPrivacyStatus.DisplayState.Rating;
-                    }
-                }
+                omi = this.GetMailItem(control);
+                isEnabled = omi?.GetIsPEPEnabled() ?? PEPSettings.ACCOUNT_SETTING_IS_PEP_ENABLED_DEFAULT;
             }
             catch (Exception ex)
             {
-                Log.Error("GetUIRating: Failed to get rating, " + ex.ToString());
-            }
-
-            if (insp != null)
-            {
-                // Marshal.ReleaseComObject(insp);
-                insp = null;
-            }
-
-            return (rating);
-        }
-
-        /// <summary>
-        /// Gets whether the mail item in the active inspector
-        /// has BCC recipients.
-        /// </summary>
-        /// <returns>True if the mail item has BCC recipients, otherwise false.</returns>
-        private bool GetHasBccRecipients()
-        {
-            bool hasBcc = false;
-            Outlook.MailItem omi = null;
-            Outlook.Inspector inspector = null;
-
-            try
-            {
-                inspector = Globals.ThisAddIn.Application.ActiveInspector();
-                omi = inspector.CurrentItem as Outlook.MailItem;
-                hasBcc = (string.IsNullOrEmpty(omi?.BCC) == false);
-            }
-            catch (Exception ex)
-            {
-                Log.Error("GetHasBccRecipients: Error occured. " + ex.ToString());
+                isEnabled = PEPSettings.ACCOUNT_SETTING_IS_PEP_ENABLED_DEFAULT;
+                Log.Error("GetIsPEPEnabled: Error occured. " + ex.ToString());
             }
             finally
             {
                 omi = null;
-                inspector = null;
             }
 
-            return hasBcc;
+            return isEnabled;
         }
 
         /// <summary>
-        /// Gets whether S/MIME encryption or signature is enabled.
+        /// Determines whether the Decrypt Always option is enabled for the current mail item.
         /// </summary>
-        /// <returns>True if S/MIME encryption or signature is enabled, otherwise false.</returns>
-        private bool GetIsSMIMEEnabled()
+        /// <returns>True if the Decrypt Always option is enabled for the current mail item, otherwise false.</returns>
+        private bool GetIsDecryptAlwaysEnabled(Office.IRibbonControl control)
         {
-            bool isEnabled = false;
-            Outlook.Inspector inspector = null;
             Outlook.MailItem omi = null;
+            bool isEnabled = PEPSettings.ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT;
 
             try
             {
-                inspector = Globals.ThisAddIn.Application.ActiveInspector();
-                omi = inspector.CurrentItem as Outlook.MailItem;
-                isEnabled = (omi?.GetIsSMIMEEnabled() == true);
+                omi = this.GetMailItem(control);
+                isEnabled = omi?.GetIsDecryptAlwaysEnabled() ?? PEPSettings.ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT;
             }
             catch (Exception ex)
             {
-                isEnabled = false;
-                Log.Error("RibbonCustomizations.GetIsSMIMEEnabled: Error getting whether S/MIME processing is enabled. " + ex.ToString());
+                isEnabled = PEPSettings.ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT;
+                Log.Error("GetIsDecryptAlwaysEnabled: Error occured. " + ex.ToString());
             }
             finally
             {
-                inspector = null;
                 omi = null;
             }
 
@@ -237,82 +434,77 @@
         /// </summary>
         /// <param name="property">The property to get the value for.</param>
         /// <returns>The property value.</returns>
-        private object GetProperty(MailItemExtensions.PEPProperty property)
+        private object GetProperty(Office.IRibbonControl control,
+                                   MailItemExtensions.PEPProperty property)
         {
             object propValue;
             object result = null;
-            Outlook.MailItem currMailItem = null;
-            Outlook.ContactItem currContactItem = null;
-            Outlook.Inspector insp = Globals.ThisAddIn.Application.ActiveInspector();
+            Outlook.MailItem omi = null;
+            Outlook.ContactItem oci = null;
 
             // Set the default
             result = MailItemExtensions.GetPEPPropertyDefault(property);
 
-            // Look for the property
-            if ((insp != null) &&
-                (insp.CurrentItem != null))
+            // If the current item is a mail item
+            omi = this.GetMailItem(control);
+            if (omi != null)
             {
-                // MailItem
-                if (insp.CurrentItem is Outlook.MailItem)
+                try
+                {
+                    switch (property)
+                    {
+                        case (MailItemExtensions.PEPProperty.ForceUnencrypted):
+                            {
+                                // Return status can be ignored here, using the auto default value is good enough
+                                omi.GetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, out propValue);
+                                result = (bool)propValue;
+                                break;
+                            }
+                        case (MailItemExtensions.PEPProperty.ForceProtection):
+                            {
+                                // Return status can be ignored here, using the auto default value is good enough
+                                omi.GetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, out propValue);
+                                result = propValue as string;
+                                break;
+                            }
+                        case (MailItemExtensions.PEPProperty.NeverUnsecure):
+                            {
+                                // Return status can be ignored here, using the auto default value is good enough
+                                omi.GetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, out propValue);
+                                result = (bool)propValue;
+                                break;
+                            }
+                        case (MailItemExtensions.PEPProperty.EnableProtection):
+                            {
+                                // Return status can be ignored here, using the auto default value is good enough
+                                omi.GetPEPProperty(MailItemExtensions.PEPProperty.EnableProtection, out propValue);
+                                result = (bool)propValue;
+                                break;
+                            }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Log.Error("GetProperty: Error occured. " + ex.ToString());
+                }
+                finally
+                {
+                    omi = null;
+                }
+            }
+            else
+            {
+                // If the current item is a contact item
+                oci = this.GetContactItem(control);
+                if (oci != null)
                 {
                     try
                     {
-                        currMailItem = (Outlook.MailItem)insp.CurrentItem;
-
                         switch (property)
                         {
                             case (MailItemExtensions.PEPProperty.ForceUnencrypted):
                                 {
-                                    // Return status can be ignored here, using the auto default value is good enough
-                                    currMailItem.GetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, out propValue);
-                                    result = (bool)propValue;
-                                    break;
-                                }
-                            case (MailItemExtensions.PEPProperty.ForceProtection):
-                                {
-                                    // Return status can be ignored here, using the auto default value is good enough
-                                    currMailItem.GetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, out propValue);
-                                    result = propValue as string;
-                                    break;
-                                }
-                            case (MailItemExtensions.PEPProperty.NeverUnsecure):
-                                {
-                                    // Return status can be ignored here, using the auto default value is good enough
-                                    currMailItem.GetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, out propValue);
-                                    result = (bool)propValue;
-                                    break;
-                                }
-                            case (MailItemExtensions.PEPProperty.EnableProtection):
-                                {
-                                    // Return status can be ignored here, using the auto default value is good enough
-                                    currMailItem.GetPEPProperty(MailItemExtensions.PEPProperty.EnableProtection, out propValue);
-                                    result = (bool)propValue;
-                                    break;
-                                }
-                        }
-                    }
-                    catch { }
-                    finally
-                    {
-                        if (currMailItem != null)
-                        {
-                            // Marshal.ReleaseComObject(currMailItem);
-                            currMailItem = null;
-                        }
-                    }
-                }
-                // ContactItem
-                else if (insp.CurrentItem is Outlook.ContactItem)
-                {
-                    try
-                    {
-                        currContactItem = (Outlook.ContactItem)insp.CurrentItem;
-
-                        switch (property)
-                        {
-                            case (MailItemExtensions.PEPProperty.ForceUnencrypted):
-                                {
-                                    propValue = currContactItem.GetForceUnencrypted();
+                                    propValue = oci.GetForceUnencrypted();
 
                                     // Don't replace the default if the value is null
                                     if (propValue != null)
@@ -329,22 +521,19 @@
                                 }
                         }
                     }
-                    catch { }
+                    catch (Exception ex)
+                    {
+                        Log.Error("GetProperty: Error occured. " + ex.ToString());
+
+                    }
                     finally
                     {
-                        if (currContactItem != null)
-                        {
-                            // Marshal.ReleaseComObject(currContactItem);
-                            currContactItem = null;
-                        }
+                        oci = null;
                     }
                 }
-
-                // Marshal.ReleaseComObject(insp);
-                insp = null;
             }
 
-            return (result);
+            return result;
         }
 
         /// <summary>
@@ -353,130 +542,113 @@
         /// </summary>
         /// <param name="property">The property to set the value for.</param>
         /// <param name="value">The value of the property to set.</param>
-        private void SetProperty(MailItemExtensions.PEPProperty property,
+        private void SetProperty(Office.IRibbonControl control,
+                                 MailItemExtensions.PEPProperty property,
                                  object value)
         {
             bool? propertyValue;
-            WindowFormRegionCollection formRegions;
-            Outlook.MailItem currMailItem = null;
-            Outlook.ContactItem currContactItem = null;
-            Outlook.Inspector insp = Globals.ThisAddIn.Application.ActiveInspector();
+            Outlook.MailItem omi = null;
+            Outlook.ContactItem oci = null;
+
+            omi = this.GetMailItem(control);
+
+            // MailItem
+            if (omi != null)
+            {
+                try
+                {
+                    switch (property)
+                    {
+                        case (MailItemExtensions.PEPProperty.ForceProtection):
+                            {
+                                // Return status can be ignored
+                                omi.SetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, value);
+
+                                // Update UI
+                                if (string.IsNullOrEmpty(value as string))
+                                {
+                                    this.GetFormRegionPrivacyStatus(control)?.RequestRatingAndUIUpdate();
+                                }
+                                else
+                                {
+                                    this.GetFormRegionPrivacyStatus(control)?.SetRating(pEpRating.pEpRatingReliable);
+                                }
+                                break;
+                            }
+                        case (MailItemExtensions.PEPProperty.ForceUnencrypted):
+                            {
+                                if ((value as bool?) != null)
+                                {
+                                    // Return status can be ignored
+                                    omi.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, value);
+
+                                    // Update UI
+                                    RibbonCustomizations.Invalidate();
+                                }
 
-            if ((insp != null) &&
-                (insp.CurrentItem != null))
+                                break;
+                            }
+                        case (MailItemExtensions.PEPProperty.NeverUnsecure):
+                            {
+                                if ((value as bool?) != null)
+                                {
+                                    // Return status can be ignored
+                                    omi.SetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, value);
+                                }
+
+                                break;
+                            }
+                        case (MailItemExtensions.PEPProperty.EnableProtection):
+                            {
+                                if ((value as bool?) != null)
+                                {
+                                    // Return status can be ignored
+                                    omi.SetPEPProperty(MailItemExtensions.PEPProperty.EnableProtection, value);
+
+                                    // Update UI
+                                    this.GetFormRegionPrivacyStatus(control)?.RequestRatingAndUIUpdate();
+                                }
+
+                                break;
+                            }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Log.Error("SetProperty: Error occured. " + ex.ToString());
+                }
+                finally
+                {
+                    omi = null;
+                }
+            }
+            else
             {
-                // MailItem
-                if (insp.CurrentItem is Outlook.MailItem)
+                // ContactItem
+                oci = this.GetContactItem(control);
+                if (oci != null)
                 {
                     try
                     {
-                        currMailItem = (Outlook.MailItem)insp.CurrentItem;
-                        formRegions = Globals.FormRegions[insp];
-
-                        switch (property)
-                        {
-                            case (MailItemExtensions.PEPProperty.ForceProtection):
-                                {
-                                    // Return status can be ignored
-                                    currMailItem.SetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, value);
-                                    currMailItem.Save();
-
-                                    if ((formRegions != null) &&
-                                        (formRegions.FormRegionPrivacyStatus != null))
-                                    {
-                                        formRegions.FormRegionPrivacyStatus.RequestRatingAndUIUpdate();
-                                    }
-
-                                    break;
-                                }
-                            case (MailItemExtensions.PEPProperty.ForceUnencrypted):
-                                {
-                                    if ((value != null) &&
-                                        (value is bool))
-                                    {
-                                        // Return status can be ignored
-                                        currMailItem.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, value);
-                                        currMailItem.Save();
-
-                                        if ((formRegions != null) &&
-                                            (formRegions.FormRegionPrivacyStatus != null))
-                                        {
-                                            formRegions.FormRegionPrivacyStatus.RequestRatingAndUIUpdate();
-                                        }
-                                    }
-
-                                    break;
-                                }
-                            case (MailItemExtensions.PEPProperty.NeverUnsecure):
-                                {
-                                    if ((value != null) &&
-                                        (value is bool))
-                                    {
-                                        // Return status can be ignored
-                                        currMailItem.SetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, value);
-                                        currMailItem.Save();
-                                    }
-
-                                    break;
-                                }
-                            case (MailItemExtensions.PEPProperty.EnableProtection):
-                                {
-                                    if ((value != null) &&
-                                        (value is bool))
-                                    {
-                                        // Return status can be ignored
-                                        currMailItem.SetPEPProperty(MailItemExtensions.PEPProperty.EnableProtection, value);
-                                        currMailItem.Save();
-
-                                        if ((formRegions != null) &&
-                                            (formRegions.FormRegionPrivacyStatus != null))
-                                        {
-                                            formRegions.FormRegionPrivacyStatus.UpdateFormRegion((bool)value);
-                                        }
-                                    }
-
-                                    break;
-                                }
-                        }
-                    }
-                    catch { }
-                    finally
-                    {
-                        if (currMailItem != null)
-                        {
-                            // Marshal.ReleaseComObject(currMailItem);
-                            currMailItem = null;
-                        }
-                    }
-                }
-                // ContactItem
-                else if (insp.CurrentItem is Outlook.ContactItem)
-                {
-                    try
-                    {
-                        currContactItem = (Outlook.ContactItem)insp.CurrentItem;
-
                         switch (property)
                         {
                             case (MailItemExtensions.PEPProperty.ForceUnencrypted):
                                 {
-                                    if ((value != null) &&
-                                        (value.GetType() == typeof(bool)))
+                                    if ((value as bool?) != null)
                                     {
-                                        if ((bool)value == true)
+                                        if ((value as bool?) == true)
                                         {
-                                            currContactItem.SetForceUnencrypted(true);
+                                            oci.SetForceUnencrypted(true);
                                         }
                                         else
                                         {
-                                            propertyValue = currContactItem.GetForceUnencrypted();
+                                            propertyValue = oci.GetForceUnencrypted();
 
                                             // Set the mail item value to false ONLY if it was previously true.
                                             // This is necessary because the UI will default to false if null (indeterminate).
-                                            if ((propertyValue != null) &&
-                                                ((bool)propertyValue == true))
+                                            if (propertyValue == true)
                                             {
-                                                currContactItem.SetForceUnencrypted(false);
+                                                oci.SetForceUnencrypted(false);
                                             }
                                         }
                                     }
@@ -490,22 +662,16 @@
                                 }
                         }
                     }
-                    catch { }
+                    catch (Exception ex)
+                    {
+                        Log.Error("SetProperty: Error occured. " + ex.ToString());
+                    }
                     finally
                     {
-                        if (currContactItem != null)
-                        {
-                            // Marshal.ReleaseComObject(currContactItem);
-                            currContactItem = null;
-                        }
+                        oci = null;
                     }
                 }
-
-                // Marshal.ReleaseComObject(insp);
-                insp = null;
             }
-
-            return;
         }
 
         /**************************************************************
@@ -590,39 +756,262 @@
         }
 
         ///////////////////////////////////////////////////////////
+        // ButtonPrivacyStatus
+        ///////////////////////////////////////////////////////////
+
+        /// <summary>
+        /// Event handler for when the Privacy Status button is clicked.
+        /// This will open the Options dialog.
+        /// </summary>
+        public void ButtonPrivacyStatus_Click(Office.IRibbonControl control)
+        {
+            try
+            {
+                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
+                this.GetFormRegionPrivacyStatus(control)?.BuildAndShowManager();
+            }
+            catch (Exception ex)
+            {
+                Globals.StopAndSendCrashReport(ex);
+            }
+        }
+
+        /// <summary>
+        /// Callback to get the image of the ButtonPrivacyStatus.
+        /// </summary>
+        public System.Drawing.Bitmap ButtonPrivacyStatus_GetImage(Office.IRibbonControl control)
+        {
+            pEpRating rating = this.GetRating(control);
+
+            switch (rating)
+            {
+                // Red rating
+                case pEpRating.pEpRatingMistrust:
+                case pEpRating.pEpRatingB0rken:
+                case pEpRating.pEpRatingUnderAttack:
+                    return Properties.Resources.ImageRatingRed;
+
+                // Yellow rating
+                case pEpRating.pEpRatingReliable:
+                    {
+                        if (this.GetForceUnencrypted(control))
+                        {
+                            return Properties.Resources.ImagePrivacyStatusYellowProtectionDisabled;
+                        }
+                        else
+                        {
+                            return Properties.Resources.ImageRatingYellow;
+                        }
+                    }
+
+                // Green rating
+                case pEpRating.pEpRatingTrusted:
+                case pEpRating.pEpRatingTrustedAndAnonymized:
+                case pEpRating.pEpRatingFullyAnonymous:
+                    {
+                        if (this.GetForceUnencrypted(control))
+                        {
+                            return Properties.Resources.ImagePrivacyStatusGreenProtectionDisabled;
+                        }
+                        else
+                        {
+                            return Properties.Resources.ImageRatingGreen;
+                        }
+                    }
+
+                // No color rating
+                case pEpRating.pEpRatingUnencrypted:
+                case pEpRating.pEpRatingUnencryptedForSome:
+                    {
+                        if ((this.GetForceProtection(control)) &&
+                            (this.GetDisableForceProtection(control) == false))
+                        {
+                            return Properties.Resources.ImageRatingYellow;
+                        }
+                        else
+                        {
+                            return Properties.Resources.ImagePrivacyStatusNoColor;
+                        }
+                    }
+                case pEpRating.pEpRatingUndefined:
+                case pEpRating.pEpRatingCannotDecrypt:
+                case pEpRating.pEpRatingHaveNoKey:
+                case pEpRating.pEpRatingUnreliable:
+                default:
+                    return Properties.Resources.ImagePrivacyStatusNoColor;
+            }
+        }
+
+        /// <summary>
+        /// Callback to get the label of the ButtonPrivacyStatus.
+        /// </summary>
+        public string ButtonPrivacyStatus_GetLabel(Office.IRibbonControl control)
+        {
+            return Properties.Resources.PrivacyStatus_FormText;
+        }
+
+        /// <summary>
+        /// Callback to get the supertip of the ButtonPrivacyStatus.
+        /// </summary>
+        public string ButtonPrivacyStatus_GetScreentip(Office.IRibbonControl control)
+        {
+            pEpRating rating = this.GetRating(control);
+
+            switch (rating)
+            {
+                case pEpRating.pEpRatingMistrust:
+                    return Properties.Resources.PrivacyStatus_RatingMistrustText;
+                case pEpRating.pEpRatingB0rken:
+                    return Properties.Resources.PrivacyStatus_RatingBrokenText;
+                case pEpRating.pEpRatingUnderAttack:
+                    return Properties.Resources.PrivacyStatus_RatingUnderAttackText;
+                case pEpRating.pEpRatingReliable:
+                    {
+                        if (this.GetForceUnencrypted(control))
+                        {
+                            return Properties.Resources.PrivacyStatus_RatingUnencryptedText;
+                        }
+                        else
+                        {
+                            return Properties.Resources.PrivacyStatus_RatingReliableText;
+                        }
+                    }
+                case pEpRating.pEpRatingTrusted:
+                case pEpRating.pEpRatingTrustedAndAnonymized:
+                case pEpRating.pEpRatingFullyAnonymous:
+                    {
+                        if (this.GetForceUnencrypted(control))
+                        {
+                            return Properties.Resources.PrivacyStatus_RatingUnencryptedText;
+                        }
+                        else
+                        {
+                            return Properties.Resources.PrivacyStatus_RatingTrustedText;
+                        }
+                    }
+                case pEpRating.pEpRatingCannotDecrypt:
+                case pEpRating.pEpRatingHaveNoKey:
+                    return Properties.Resources.PrivacyStatus_RatingHaveNoKeyText;
+                case pEpRating.pEpRatingUnencrypted:
+                    {
+                        if ((this.GetForceProtection(control)) &&
+                            (this.GetDisableForceProtection(control) == false))
+                        {
+                            return Properties.Resources.PrivacyStatus_RatingReliableText;
+                        }
+                        else
+                        {
+                            return Properties.Resources.PrivacyStatus_RatingUnencryptedText;
+                        }
+                    }
+                case pEpRating.pEpRatingUnencryptedForSome:
+                    return Properties.Resources.PrivacyStatus_RatingUnencryptedForSomeText;
+                case pEpRating.pEpRatingUnreliable:
+                    return Properties.Resources.PrivacyStatus_RatingUnreliableText;
+                case pEpRating.pEpRatingUndefined:
+                default:
+                    return Properties.Resources.PrivacyStatus_RatingUndefinedText;
+            }
+        }
+
+        /// <summary>
+        /// Callback to get whether the ButtonPrivacyStatus is visible.
+        /// </summary>
+        public bool ButtonPrivacyStatus_GetVisible(Office.IRibbonControl control)
+        {
+            /* Visible if pEp enabled.
+             * If pEp is disabled, only visible in draft windows (so user can Enable Protection)
+             * or if DecryptAlways option is set.
+             */
+            bool visible = true;
+
+            if (this.GetIsPEPEnabled(control) == false)
+            {
+                visible = false;
+                dynamic window = null;
+                Outlook.MailItem omi = null;
+
+                try
+                {
+                    // Get the parent window
+                    window = control.Context as Outlook.Explorer;
+                    if (window != null)
+                    {
+                        visible = this.GetIsDecryptAlwaysEnabled(control);
+                    }
+                    else
+                    {
+                        window = control.Context as Outlook.Inspector;
+                        if (window != null)
+                        {
+                            omi = this.GetMailItem(control);
+                            visible = ((omi?.GetIsDraft() == true) ||
+                                       (this.GetIsDecryptAlwaysEnabled(control)));                     
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Log.Error("ButtonPrivacyStatus_GetVisible: Error occured. " + ex.ToString());
+                }
+                finally
+                {
+                    omi = null;
+                    window = null;
+                }
+            }
+
+            return visible;
+        }
+
+        /// <summary>
+        /// Event handler for when the builtin Encrypt Message button is clicked.
+        /// </summary>
+        public void ButtonSMIME_Clicked(Office.IRibbonControl control, bool pressed, ref bool cancel)
+        {
+            cancel = false;
+            this.GetFormRegionPrivacyStatus(control)?.RequestRatingAndUIUpdate();
+        }
+
+        ///////////////////////////////////////////////////////////
         // ToggleButtonForceUnencrypted
         ///////////////////////////////////////////////////////////
 
         /// <summary>
+        /// Event handler for when the ToggleButtonForceUnencrypted is clicked.
+        /// </summary>
+        public void ToggleButtonForceUnencrypted_Click(Office.IRibbonControl control, bool isPressed)
+        {
+            this.SetForceUnencrypted(control, isPressed);
+
+            // Disable Force Protection and Never Unsecure if needed
+            if (isPressed)
+            {
+                this.SetForceProtection(control, false);
+                this.SetNeverUnsecure(control, false);
+            }
+
+            RibbonCustomizations.Invalidate();
+        }
+
+        /// <summary>
         /// Callback to get whether the ToggleButtonForceUnencrypted is enabled.
         /// </summary>
         public bool ToggleButtonForceUnencrypted_GetEnabled(Office.IRibbonControl control)
         {
-            // When a message is marked as never unsecure or forcefully proteced, it cannot be forcefully unencrypted
-            if (((bool)this.GetProperty(MailItemExtensions.PEPProperty.NeverUnsecure) || (this.GetProperty(MailItemExtensions.PEPProperty.ForceProtection) != null)) ||
-                (((bool)this.GetProperty(MailItemExtensions.PEPProperty.ForceUnencrypted) == false) && (this.GetDisplayRating() == pEpRating.pEpRatingUnencrypted)) ||
-                (this.GetIsSMIMEEnabled()))
+            /* The button is disabled if
+             *  - Rating is lower than reliable
+             *  - Force Protection or Never Unsecure are enabled and not overridden
+             */ 
+            if (((this.GetRating(control) < pEpRating.pEpRatingReliable) ||
+                 (this.GetNeverUnsecure(control))) ||
+                 ((this.GetForceProtection(control)) && (this.GetDisableForceProtection(control) == false)))
             {
-                return (false);
-            }
+                return false;
+            }            
             else
             {
-                return (true);
-            }
-        }
-
-        /// <summary>
-        /// Callback to get the image for the ToggleButtonForceUnencrypted.
-        /// </summary>
-        public System.Drawing.Bitmap ToggleButtonForceUnencrypted_GetImage(Office.IRibbonControl control)
-        {
-            if ((bool)this.GetProperty(MailItemExtensions.PEPProperty.ForceUnencrypted))
-            {
-                return (Properties.Resources.ImageForceUnencOn);
-            }
-            else
-            {
-                return (Properties.Resources.ImageForceUnencOff);
+                return true;
             }
         }
 
@@ -631,7 +1020,7 @@
         /// </summary>
         public string ToggleButtonForceUnencrypted_GetLabel(Office.IRibbonControl control)
         {
-            return (Properties.Resources.Ribbon_ForceUnencrypted);
+            return Properties.Resources.Ribbon_ForceUnencrypted;
         }
 
         /// <summary>
@@ -639,7 +1028,7 @@
         /// </summary>
         public bool ToggleButtonForceUnencrypted_GetPressed(Office.IRibbonControl control)
         {
-            return ((bool)this.GetProperty(MailItemExtensions.PEPProperty.ForceUnencrypted));
+            return this.GetForceUnencrypted(control);
         }
 
         /// <summary>
@@ -647,7 +1036,7 @@
         /// </summary>
         public string ToggleButtonForceUnencrypted_GetSupertip(Office.IRibbonControl control)
         {
-            return (Properties.Resources.Ribbon_ForceUnencryptedDesc);
+            return Properties.Resources.Ribbon_ForceUnencryptedDesc;
         }
 
         /// <summary>
@@ -656,7 +1045,7 @@
         public bool ToggleButtonForceUnencrypted_GetVisible(Office.IRibbonControl control)
         {
             return ((Globals.RELEASE_MODE != Globals.ReleaseMode.Reader) &&
-                    (this.GetIsPEPEnabled()));
+                    (this.GetIsPEPEnabled(control)));
         }
 
         ///////////////////////////////////////////////////////////
@@ -664,6 +1053,21 @@
         ///////////////////////////////////////////////////////////
 
         /// <summary>
+        /// Event handler for when the ToggleButtonEnableProtection is clicked.
+        /// </summary>
+        public void ToggleButtonEnableProtection_Click(Office.IRibbonControl control, bool isPressed)
+        {
+            this.SetProperty(control, MailItemExtensions.PEPProperty.EnableProtection, isPressed);
+
+            // If protection is disabled, disable also force protected and never unsecure
+            if (isPressed == false)
+            {
+                this.SetForceProtection(control, false);
+                this.SetNeverUnsecure(control, false);
+            }
+        }
+
+        /// <summary>
         /// Callback to get whether the ToggleButtonEnableProtection is enabled.
         /// </summary>
         public bool ToggleButtonEnableProtection_GetEnabled(Office.IRibbonControl control)
@@ -673,26 +1077,11 @@
         }
 
         /// <summary>
-        /// Callback to get the image for the ToggleButtonEnableProtection.
-        /// </summary>
-        public System.Drawing.Bitmap ToggleButtonEnableProtection_GetImage(Office.IRibbonControl control)
-        {
-            if (this.GetProperty(MailItemExtensions.PEPProperty.EnableProtection) as bool? ?? false)
-            {
-                return (Properties.Resources.ImageForceUnencOff);
-            }
-            else
-            {
-                return (Properties.Resources.ImageForceUnencOn);
-            }
-        }
-
-        /// <summary>
         /// Callback to get the label text for the ToggleButtonEnableProtection.
         /// </summary>
         public string ToggleButtonEnableProtection_GetLabel(Office.IRibbonControl control)
         {
-            return (Properties.Resources.Ribbon_EnableProtection);
+            return Properties.Resources.Ribbon_EnableProtection;
         }
 
         /// <summary>
@@ -700,7 +1089,7 @@
         /// </summary>
         public bool ToggleButtonEnableProtection_GetPressed(Office.IRibbonControl control)
         {
-            return ((bool)this.GetProperty(MailItemExtensions.PEPProperty.EnableProtection));
+            return ((this.GetProperty(control, MailItemExtensions.PEPProperty.EnableProtection) as bool?) ?? false);
         }
 
         /// <summary>
@@ -717,7 +1106,7 @@
         public bool ToggleButtonEnableProtection_GetVisible(Office.IRibbonControl control)
         {
             return ((Globals.RELEASE_MODE != Globals.ReleaseMode.Reader) &&
-                    (this.GetIsPEPEnabled()) == false);
+                    (this.GetIsPEPEnabled(control)) == false);
         }
 
         ///////////////////////////////////////////////////////////
@@ -725,19 +1114,19 @@
         ///////////////////////////////////////////////////////////
 
         /// <summary>
-        /// Callback to get the image for the ToggleButtonForceProtection.
+        /// Event handler for when the ToggleButtonForceProtection is clicked.
         /// </summary>
-        public System.Drawing.Bitmap ToggleButtonForceProtection_GetImage(Office.IRibbonControl control)
+        public void ToggleButtonForceProtection_Click(Office.IRibbonControl control, bool isPressed)
         {
-            // Placeholder until design is ready
-            if (this.GetProperty(MailItemExtensions.PEPProperty.ForceProtection) != null)
+            this.SetForceProtection(control, isPressed);
+
+            // If protection is disabled, disable also never unsecure
+            if (isPressed == false)
             {
-                return (Properties.Resources.ImageForceUnencOff);
+                this.SetNeverUnsecure(control, isPressed);
             }
-            else
-            {
-                return (Properties.Resources.ImageForceUnencOn);
-            }
+
+            RibbonCustomizations.Invalidate();
         }
 
         /// <summary>
@@ -745,8 +1134,31 @@
         /// </summary>
         public bool ToggleButtonForceProtection_GetEnabled(Office.IRibbonControl control)
         {
-            // If button is visible, it is also enabled
-            return true;
+            bool enabled = false;
+
+            /* The button is enabled when:
+             * 1. No S/MIME option is enabled
+             * 2. Force Unencrypted is not enabled
+             * 3. Rating is Unsecure
+             */
+            if ((this.GetIsSMIMEEnabled(control)) ||
+                (this.GetDisableForceProtection(control)))
+            {
+                return false;
+            }
+
+            if (this.GetIsPEPEnabled(control))
+            {
+                enabled = ((this.GetRating(control) == pEpRating.pEpRatingUnencrypted) && 
+                           (this.GetForceUnencrypted(control) == false));
+            }
+            else
+            {
+                enabled = ((this.GetRating(control) == pEpRating.pEpRatingUnencrypted) &&
+                           ((this.GetProperty(control, MailItemExtensions.PEPProperty.EnableProtection) as bool?) ?? false));
+            }
+
+            return enabled;
         }
 
         /// <summary>
@@ -754,7 +1166,7 @@
         /// </summary>
         public string ToggleButtonForceProtection_GetLabel(Office.IRibbonControl control)
         {
-            return (Properties.Resources.Ribbon_ForceProtection);
+            return Properties.Resources.Ribbon_ForceProtection;
         }
 
         /// <summary>
@@ -762,7 +1174,8 @@
         /// </summary>
         public bool ToggleButtonForceProtection_GetPressed(Office.IRibbonControl control)
         {
-            return (this.GetProperty(MailItemExtensions.PEPProperty.ForceProtection) != null);
+            return ((this.GetForceProtection(control)) && 
+                    (this.GetDisableForceProtection(control) == false));
         }
 
         /// <summary>
@@ -770,7 +1183,7 @@
         /// </summary>
         public string ToggleButtonForceProtection_GetSupertip(Office.IRibbonControl control)
         {
-            return (Properties.Resources.Ribbon_ForceProtectionDesc);
+            return Properties.Resources.Ribbon_ForceProtectionDesc;
         }
 
         /// <summary>
@@ -778,28 +1191,8 @@
         /// </summary>
         public bool ToggleButtonForceProtection_GetVisible(Office.IRibbonControl control)
         {
-            // Not in Reader mode, not forcefully unencrypted and unsecure rating - or if property is set
-            bool visible = false;
-
-            if ((Globals.RELEASE_MODE != Globals.ReleaseMode.Reader) &&
-                (this.GetIsSMIMEEnabled() == false) &&
-                (this.GetHasBccRecipients() == false))
-            {
-                if (this.GetIsPEPEnabled())
-                {
-                    visible = ((this.GetProperty(MailItemExtensions.PEPProperty.ForceUnencrypted) as bool? == false) &&
-                               ((this.GetDisplayRating() == pEpRating.pEpRatingUnencrypted) || (this.GetDisplayRating() == pEpRating.pEpRatingUnencryptedForSome)) ||
-                               (this.GetProperty(MailItemExtensions.PEPProperty.ForceProtection) != null));
-                }
-                else
-                {
-                    visible = ((this.GetProperty(MailItemExtensions.PEPProperty.EnableProtection) as bool? == true) &&
-                               ((this.GetDisplayRating() == pEpRating.pEpRatingUnencrypted) || (this.GetDisplayRating() == pEpRating.pEpRatingUnencryptedForSome)) ||
-                               (this.GetProperty(MailItemExtensions.PEPProperty.ForceProtection) != null));
-                }
-            }
-
-            return visible;
+            // Visible if not in Reader mode
+            return (Globals.RELEASE_MODE != Globals.ReleaseMode.Reader);
         }
 
         ///////////////////////////////////////////////////////////
@@ -807,37 +1200,23 @@
         ///////////////////////////////////////////////////////////
 
         /// <summary>
+        /// Event handler for when the ToggleButtonNeverUnsecure is clicked.
+        /// </summary>
+        public void ToggleButtonNeverUnsecure_Click(Office.IRibbonControl control, bool isPressed)
+        {
+            this.SetNeverUnsecure(control, isPressed);
+            RibbonCustomizations.Invalidate();
+        }
+
+        /// <summary>
         /// Callback to get whether the ToggleButtonNeverUnsecure is enabled.
         /// </summary>
         public bool ToggleButtonNeverUnsecure_GetEnabled(Office.IRibbonControl control)
         {
-            // When a message is being sent forcefully unencrypted, it cannot be marked never unsecure
-            if (((this.GetProperty(MailItemExtensions.PEPProperty.ForceUnencrypted) as bool?) == true) ||
-                (this.GetDisplayRating() < pEpRating.pEpRatingReliable) ||
-                (this.GetIsSMIMEEnabled() ||
-                (this.GetHasBccRecipients())))
-            {
-                return (false);
-            }
-            else
-            {
-                return (true);
-            }
-        }
-
-        /// <summary>
-        /// Callback to get the image for the ToggleButtonNeverUnsecure.
-        /// </summary>
-        public System.Drawing.Bitmap ToggleButtonNeverUnsecure_GetImage(Office.IRibbonControl control)
-        {
-            if ((bool)this.GetProperty(MailItemExtensions.PEPProperty.NeverUnsecure))
-            {
-                return (Properties.Resources.ImageNeverUnsecureOn);
-            }
-            else
-            {
-                return (Properties.Resources.ImageNeverUnsecureOff);
-            }
+            // Enabled if not forcefully unencrypted, rating >= Reliable (or force protection), no S/MIME enabled and no BCC recipients
+             return (((this.GetRating(control) >= pEpRating.pEpRatingReliable) || (this.GetForceProtection(control)) && (this.ToggleButtonForceProtection_GetEnabled(control))) &&
+                     (this.GetForceUnencrypted(control) == false) &&
+                     (this.GetIsSMIMEEnabled(control) == false));
         }
 
         /// <summary>
@@ -845,7 +1224,7 @@
         /// </summary>
         public string ToggleButtonNeverUnsecure_GetLabel(Office.IRibbonControl control)
         {
-            return (pEp.Properties.Resources.Ribbon_NeverUnsecure);
+            return Properties.Resources.Ribbon_NeverUnsecure;
         }
 
         /// <summary>
@@ -853,7 +1232,7 @@
         /// </summary>
         public bool ToggleButtonNeverUnsecure_GetPressed(Office.IRibbonControl control)
         {
-            return ((bool)this.GetProperty(MailItemExtensions.PEPProperty.NeverUnsecure));
+            return this.GetNeverUnsecure(control);
         }
 
         /// <summary>
@@ -861,7 +1240,7 @@
         /// </summary>
         public string ToggleButtonNeverUnsecure_GetSupertip(Office.IRibbonControl control)
         {
-            return (pEp.Properties.Resources.Ribbon_NeverUnsecureDesc);
+            return Properties.Resources.Ribbon_NeverUnsecureDesc;
         }
 
         /// <summary>
@@ -878,6 +1257,21 @@
         ///////////////////////////////////////////////////////////
 
         /// <summary>
+        /// Event handler for when the Upgrade pEp button is clicked.
+        /// </summary>
+        public void ButtonUpgradePEP_Click(Office.IRibbonControl control)
+        {
+            try
+            {
+                Process.Start(Globals.PEP_WEBSITE_UPGRADE_LINK);
+            }
+            catch (Exception ex)
+            {
+                Log.Error("ButtonUpgradePEP_Click: Unable to open website link, " + ex.ToString());
+            }
+        }
+
+        /// <summary>
         /// Callback to get whether the ButtonUpgradePEP is enabled.
         /// </summary>
         public bool ButtonUpgradePEP_GetEnabled(Office.IRibbonControl control)
@@ -891,7 +1285,7 @@
         /// </summary>
         public System.Drawing.Bitmap ButtonUpgradePEP_GetImage(Office.IRibbonControl control)
         {
-            return (Properties.Resources.ImageUpgradePEP);
+            return Properties.Resources.ImageUpgradePEP;
         }
 
         /// <summary>
@@ -899,7 +1293,7 @@
         /// </summary>
         public string ButtonUpgradePEP_GetLabel(Office.IRibbonControl control)
         {
-            return (Environment.NewLine + pEp.Properties.Resources.Ribbon_UpgradePEP);
+            return (Environment.NewLine + Properties.Resources.Ribbon_UpgradePEP);
         }
 
         /// <summary>
@@ -907,7 +1301,7 @@
         /// </summary>
         public string ButtonUpgradePEP_GetSupertip(Office.IRibbonControl control)
         {
-            return (pEp.Properties.Resources.Ribbon_UpgradePEPDesc);
+            return Properties.Resources.Ribbon_UpgradePEPDesc;
         }
 
         /// <summary>
@@ -947,18 +1341,31 @@
          *
          *************************************************************/
 
+        ///////////////////////////////////////////////////////////
+        // ToggleButtonForceUnencryptedContact
+        ///////////////////////////////////////////////////////////
+
+        /// <summary>
+        /// Event handler for when the ToggleButtonForceUnencryptedContact is clicked.
+        /// </summary>
+        public void ToggleButtonForceUnencryptedContact_Click(Office.IRibbonControl control, bool isPressed)
+        {
+            this.SetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted, isPressed);
+            RibbonCustomizations.Invalidate();
+        }
+
         /// <summary>
         /// Callback to get the image for the ToggleButtonForceUnencryptedContact.
         /// </summary>
         public System.Drawing.Bitmap ToggleButtonForceUnencryptedContact_GetImage(Office.IRibbonControl control)
         {
-            if ((bool)this.GetProperty(MailItemExtensions.PEPProperty.ForceUnencrypted))
+            if ((bool)this.GetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted))
             {
-                return (Properties.Resources.ImageForceUnencOn);
+                return Properties.Resources.ImageForceUnencOn;
             }
             else
             {
-                return (Properties.Resources.ImageForceUnencOff);
+                return Properties.Resources.ImageForceUnencOff;
             }
         }
 
@@ -967,7 +1374,7 @@
         /// </summary>
         public string ToggleButtonForceUnencryptedContact_GetLabel(Office.IRibbonControl control)
         {
-            return (Properties.Resources.Ribbon_ForceUnencrypted);
+            return Properties.Resources.Ribbon_ForceUnencrypted;
         }
 
         /// <summary>
@@ -975,14 +1382,14 @@
         /// </summary>
         public bool ToggleButtonForceUnencryptedContact_GetPressed(Office.IRibbonControl control)
         {
-            return ((bool)this.GetProperty(MailItemExtensions.PEPProperty.ForceUnencrypted));
+            return (bool)this.GetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted);
         }
 
         /// Callback to get the supertip/description text for the ToggleButtonForceUnencryptedContact.
         /// </summary>
         public string ToggleButtonForceUnencryptedContact_GetSupertip(Office.IRibbonControl control)
         {
-            return (Properties.Resources.Ribbon_ForceUnencryptedDesc);
+            return Properties.Resources.Ribbon_ForceUnencryptedDesc;
         }
 
         /// <summary>
@@ -990,7 +1397,7 @@
         /// </summary>
         public bool ToggleButtonForceUnencryptedContact_GetVisible(Office.IRibbonControl control)
         {
-            return (true);
+            return true;
         }
 
         /// <summary>
@@ -1128,123 +1535,11 @@
 
         /**************************************************************
          *
-         * Event Handling (Ribbon)
+         * Event Handling (Context menu)
          *
          *************************************************************/
 
         /// <summary>
-        /// Event handler for when the built-in Encrypt Message button is clicked.
-        /// </summary>
-        public void ButtonSMIME_Clicked(Office.IRibbonControl control, bool pressed, ref bool cancel)
-        {
-            Outlook.Inspector inspector;
-            Outlook.MailItem omi;
-            cancel = false;
-
-            try
-            {
-                inspector = Globals.ThisAddIn.Application.ActiveInspector();
-                omi = inspector.CurrentItem as Outlook.MailItem;
-                int secFlags = (int)MapiHelper.GetProperty(omi, MapiProperty.PidTagSecurityFlags);
-                bool isSMIMEEncrypted = ((secFlags & (int)MapiPropertyValue.SecurityFlags.Encrypted) != 0);
-                bool isSMIMESigned = ((secFlags & (int)MapiPropertyValue.SecurityFlags.Signed) != 0);
-
-                // Disable the form region if one of the two S/MIME buttons is pressed
-                bool disableFormRegion = ((pressed) ||
-                                         ((control.Id == "EncryptMessage") && isSMIMESigned) ||
-                                         ((control.Id == "DigitallySignMessage") && isSMIMEEncrypted));
-                Globals.FormRegions[inspector]?.FormRegionPrivacyStatus?.UpdateFormRegion(disableFormRegion == false);
-            }
-            catch (Exception ex)
-            {
-                Log.Error("ButtonSMIME_Clicked_Clicked: Error occurred. " + ex.ToString());
-            }
-            finally
-            {
-                inspector = null;
-                omi = null;
-            }
-        }
-
-        /// <summary>
-        /// Event handler for when the ToggleButtonForceUnencrypted is clicked.
-        /// </summary>
-        public void ToggleButtonForceUnencrypted_Click(Office.IRibbonControl control, bool isPressed)
-        {
-            this.SetProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, isPressed);
-            RibbonCustomizations.Invalidate();
-            return;
-        }
-
-        /// <summary>
-        /// Event handler for when the ToggleButtonEnableProtection is clicked.
-        /// </summary>
-        public void ToggleButtonEnableProtection_Click(Office.IRibbonControl control, bool isPressed)
-        {
-            this.SetProperty(MailItemExtensions.PEPProperty.EnableProtection, isPressed);
-
-            // If protection is disabled, disable also never unsecure
-            if (isPressed == false)
-            {
-                this.SetProperty(MailItemExtensions.PEPProperty.NeverUnsecure, false);
-            }
-
-            RibbonCustomizations.Invalidate();
-        }
-
-        /// <summary>
-        /// Event handler for when the ToggleButtonForceProtection is clicked.
-        /// </summary>
-        public void ToggleButtonForceProtection_Click(Office.IRibbonControl control, bool isPressed)
-        {
-            string guid = null;
-            if (isPressed)
-            {
-                guid = Guid.NewGuid().ToString();
-            }
-            this.SetProperty(MailItemExtensions.PEPProperty.ForceProtection, guid);
-            RibbonCustomizations.Invalidate();
-            return;
-        }
-
-        /// <summary>
-        /// Event handler for when the ToggleButtonNeverUnsecure is clicked.
-        /// </summary>
-        public void ToggleButtonNeverUnsecure_Click(Office.IRibbonControl control, bool isPressed)
-        {
-            this.SetProperty(MailItemExtensions.PEPProperty.NeverUnsecure, isPressed);
-            RibbonCustomizations.Invalidate();
-            return;
-        }
-
-        /// <summary>
-        /// Event handler for when the ToggleButtonForceUnencryptedContact is clicked.
-        /// </summary>
-        public void ToggleButtonForceUnencryptedContact_Click(Office.IRibbonControl control, bool isPressed)
-        {
-            this.SetProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, isPressed);
-            RibbonCustomizations.Invalidate();
-            return;
-        }
-
-        /// <summary>
-        /// Event handler for when the Upgrade pEp button is clicked.
-        /// </summary>
-        public void ButtonUpgradePEP_Click(Office.IRibbonControl control)
-        {
-            try
-            {
-                Process.Start(Globals.PEP_WEBSITE_UPGRADE_LINK);
-            }
-            catch (Exception ex)
-            {
-                Log.Error("ButtonUpgradePEP_Click: Unable to open website link, " + ex.ToString());
-            }
-
-            return;
-        }
-
-        /// <summary>
         /// Event handler for when the key import context menu button is clicked.
         /// </summary>
         public void ContextMenuKeyImportButton_Click(Office.IRibbonControl control)
@@ -1294,7 +1589,6 @@
         public void ButtonAccounts_Click(Office.IRibbonControl control)
         {
             this.ShowOptions(FormControlOptions.State.OptionPages.Accounts);
-            return;
         }
 
         /// <summary>
@@ -1304,7 +1598,6 @@
         public void ButtonCompatibility_Click(Office.IRibbonControl control)
         {
             this.ShowOptions(FormControlOptions.State.OptionPages.Compatibility);
-            return;
         }
 
         /// <summary>
@@ -1314,7 +1607,6 @@
         public void ButtonAbout_Click(Office.IRibbonControl control)
         {
             this.ShowOptions(FormControlOptions.State.OptionPages.About);
-            return;
         }
 
         #region IRibbonExtensibility Members
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UI/RibbonCustomizations.xml	Fri Jul 20 13:22:30 2018 +0200
@@ -0,0 +1,195 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"
+          onLoad="Ribbon_Load">
+  <commands>
+    <command idMso="EncryptMessage"
+             onAction="ButtonSMIME_Clicked"/>
+    <command idMso="DigitallySignMessage"
+             onAction="ButtonSMIME_Clicked"/>
+  </commands>
+  <ribbon>
+    <tabs>
+      <tab idMso="TabNewMailMessage">
+        <group id="GroupPEPNewMailMessage"
+               insertAfterMso="GroupMessageOptions"
+               label="p≡p"
+               getVisible="GroupPEPNewMailMessage_GetVisible">
+          <toggleButton id="ToggleButtonForceUnencrypted"
+                        size="large"
+                        getEnabled="ToggleButtonForceUnencrypted_GetEnabled"
+                        getImage="ToggleButtonForceUnencrypted_GetImage"
+                        getLabel="ToggleButtonForceUnencrypted_GetLabel"
+                        getPressed="ToggleButtonForceUnencrypted_GetPressed"
+                        getSupertip="ToggleButtonForceUnencrypted_GetSupertip"
+                        getVisible="ToggleButtonForceUnencrypted_GetVisible"
+                        onAction="ToggleButtonForceUnencrypted_Click" />
+          <toggleButton id="ToggleButtonForceProtection"
+                        size="large"
+                        getImage="ToggleButtonForceProtection_GetImage"
+                        getLabel="ToggleButtonForceProtection_GetLabel"
+                        getPressed="ToggleButtonForceProtection_GetPressed"
+                        getSupertip="ToggleButtonForceProtection_GetSupertip"
+                        getVisible="ToggleButtonForceProtection_GetVisible"
+                        onAction="ToggleButtonForceProtection_Click" />
+          <toggleButton id="ToggleButtonEnableProtection"
+                        size="large"
+                        getEnabled="ToggleButtonEnableProtection_GetEnabled"
+                        getImage="ToggleButtonEnableProtection_GetImage"
+                        getLabel="ToggleButtonEnableProtection_GetLabel"
+                        getPressed="ToggleButtonEnableProtection_GetPressed"
+                        getSupertip="ToggleButtonEnableProtection_GetSupertip"
+                        getVisible="ToggleButtonEnableProtection_GetVisible"
+                        onAction="ToggleButtonEnableProtection_Click" />
+          <toggleButton id="ToggleButtonNeverUnsecure"
+                        size="large"
+                        getEnabled="ToggleButtonNeverUnsecure_GetEnabled"
+                        getImage="ToggleButtonNeverUnsecure_GetImage"
+                        getLabel="ToggleButtonNeverUnsecure_GetLabel"
+                        getPressed="ToggleButtonNeverUnsecure_GetPressed"
+                        getSupertip="ToggleButtonNeverUnsecure_GetSupertip"
+                        getVisible="ToggleButtonNeverUnsecure_GetVisible"
+                        onAction="ToggleButtonNeverUnsecure_Click" />
+          <button id="ButtonUpgradePEPNewMessage"
+                  size="large"
+                  getEnabled="ButtonUpgradePEP_GetEnabled"
+                  getImage="ButtonUpgradePEP_GetImage"
+                  getLabel="ButtonUpgradePEP_GetLabel"
+                  getSupertip="ButtonUpgradePEP_GetSupertip"
+                  getVisible="ButtonUpgradePEP_GetVisible"
+                  onAction="ButtonUpgradePEP_Click" />
+        </group>
+      </tab>
+      <tab idMso="TabContact">
+        <group id="GroupPEPContact"
+               insertAfterMso="GroupContactOptions"
+               label="p≡p"
+               getVisible="GroupPEPContact_GetVisible">
+          <toggleButton id="ToggleButtonForceUnencryptedContact"
+                        size="large"
+                        getImage="ToggleButtonForceUnencryptedContact_GetImage"
+                        getLabel="ToggleButtonForceUnencryptedContact_GetLabel"
+                        getPressed="ToggleButtonForceUnencryptedContact_GetPressed"
+                        getSupertip="ToggleButtonForceUnencryptedContact_GetSupertip"
+                        getVisible="ToggleButtonForceUnencryptedContact_GetVisible"
+                        onAction="ToggleButtonForceUnencryptedContact_Click"/>
+        </group>
+      </tab>
+      <tab idMso="TabReadMessage">
+        <group id="GroupUpgradePEPReadMessage"
+               insertAfterMso="GroupZoom"
+               label="p≡p"
+               getVisible="GroupUpgradePEP_GetVisible">
+          <button id="ButtonUpgradePEPReadMessage"
+                  size="large"
+                  getEnabled="ButtonUpgradePEP_GetEnabled"
+                  getImage="ButtonUpgradePEP_GetImage"
+                  getLabel="ButtonUpgradePEP_GetLabel"
+                  getSupertip="ButtonUpgradePEP_GetSupertip"
+                  getVisible="ButtonUpgradePEP_GetVisible"
+                  onAction="ButtonUpgradePEP_Click" />
+        </group>
+      </tab>
+      <tab idMso="TabMail">
+        <group id="GroupUpgradePEPHome"
+               insertAfterMso="GroupSendReceive"
+               label="p≡p"
+               getVisible="GroupUpgradePEP_GetVisible">
+          <button id="ButtonUpgradePEPHome"
+                  size="large"
+                  getEnabled="ButtonUpgradePEP_GetEnabled"
+                  getImage="ButtonUpgradePEP_GetImage"
+                  getLabel="ButtonUpgradePEP_GetLabel"
+                  getSupertip="ButtonUpgradePEP_GetSupertip"
+                  getVisible="ButtonUpgradePEP_GetVisible"
+                  onAction="ButtonUpgradePEP_Click" />
+        </group>
+      </tab>
+    </tabs>
+    <contextualTabs>
+      <tabSet idMso="TabComposeTools">
+        <tab idMso="TabMessage">
+          <group id="GroupUpgradePEPComposeMessageInline"
+                 label="p≡p"
+                 getVisible="GroupUpgradePEP_GetVisible">
+            <button id="ButtonUpgradePEPComposeMessageInline"
+                    size="large"
+                    getEnabled="ButtonUpgradePEP_GetEnabled"
+                    getImage="ButtonUpgradePEP_GetImage"
+                    getLabel="ButtonUpgradePEP_GetLabel"
+                    getSupertip="ButtonUpgradePEP_GetSupertip"
+                    getVisible="ButtonUpgradePEP_GetVisible"
+                    onAction="ButtonUpgradePEP_Click" />
+          </group>
+        </tab>
+      </tabSet>
+    </contextualTabs>
+  </ribbon>
+  <backstage>
+    <!-- Available Mso for insertAfterMso: FileSaveAs, TabRecent, TabPrint, TabHelp, ApplicationOptionsDialog -->
+    <tab id="BackstagePEP"
+         label="p≡p"
+         title="p≡p for Outlook"
+         columnWidthPercent="65"
+         insertAfterMso="ApplicationOptionsDialog"
+         visible="true" >
+      <firstColumn>
+        <!-- Account Options -->
+        <group id="GroupAccounts"
+               getLabel="GroupAccounts_GetLabel"
+               getHelperText="GroupAccounts_GetHelperText">
+          <primaryItem>
+            <button id="ButtonAccounts"
+                    isDefinitive="true"
+                    onAction="ButtonAccounts_Click"
+                    getImage="ButtonAccounts_GetImage"
+                    getLabel="ButtonAccounts_GetLabel" />
+          </primaryItem>
+        </group>
+        <!-- Compatibility options -->
+        <group id="GroupCompatibility"
+               getLabel="GroupCompatibility_GetLabel"
+               getHelperText="GroupCompatibility_GetHelperText">
+          <primaryItem>
+            <button id="ButtonCompatibility"
+                    isDefinitive="true"
+                    onAction="ButtonCompatibility_Click"
+                    getImage="ButtonCompatibility_GetImage"
+                    getLabel="ButtonCompatibility_GetLabel"/>
+          </primaryItem>
+        </group>
+      </firstColumn>
+      <secondColumn>
+        <!-- About -->
+        <group id="GroupAbout">
+          <topItems>
+            <layoutContainer id="LayoutContainer3"
+                             layoutChildren="vertical">
+              <imageControl id="ImageControlLogo"
+                            getImage="ImageControlLogo_GetImage"
+                            visible="true" />
+              <labelControl id="Spacer1"
+                            label=" " />
+              <labelControl id="LabelControlName"
+                            getLabel="LabelControlName_GetLabel"
+                            alignLabel="right" />
+              <labelControl id="LabelControlCopyright"
+                            getLabel="LabelControlCopyright_GetLabel"
+                            alignLabel="right"/>
+              <labelControl id="LabelControlVersion"
+                            getLabel="LabelControlVersion_GetLabel"
+                            alignLabel="right"/>
+            </layoutContainer>
+          </topItems>
+          <bottomItems>
+            <labelControl id="LabelSpacer1"
+                          label=" "/>
+            <hyperlink id="HyperlinkPEP"
+                       label="www.prettyeasyprivacy.com"
+                       target="https://prettyeasyprivacy.com"/>
+          </bottomItems>
+        </group>
+      </secondColumn>
+    </tab>
+  </backstage>
+</customUI>
+
--- a/UI/RibbonCustomizationsCompose.xml	Mon Jul 16 12:26:12 2018 +0200
+++ b/UI/RibbonCustomizationsCompose.xml	Fri Jul 20 13:22:30 2018 +0200
@@ -14,42 +14,45 @@
                insertAfterMso="GroupMessageOptions"
                label="p≡p"
                getVisible="GroupPEPNewMailMessage_GetVisible">
-          <toggleButton id="ToggleButtonForceUnencrypted"
-                        size="large"
-                        getEnabled="ToggleButtonForceUnencrypted_GetEnabled"
-                        getImage="ToggleButtonForceUnencrypted_GetImage"
-                        getLabel="ToggleButtonForceUnencrypted_GetLabel"
-                        getPressed="ToggleButtonForceUnencrypted_GetPressed"
-                        getSupertip="ToggleButtonForceUnencrypted_GetSupertip"
-                        getVisible="ToggleButtonForceUnencrypted_GetVisible"
-                        onAction="ToggleButtonForceUnencrypted_Click" />
-          <toggleButton id="ToggleButtonForceProtection"
-                        size="large"
-                        getEnabled="ToggleButtonForceProtection_GetEnabled"
-                        getImage="ToggleButtonForceProtection_GetImage"
-                        getLabel="ToggleButtonForceProtection_GetLabel"
-                        getPressed="ToggleButtonForceProtection_GetPressed"
-                        getSupertip="ToggleButtonForceProtection_GetSupertip"
-                        getVisible="ToggleButtonForceProtection_GetVisible"
-                        onAction="ToggleButtonForceProtection_Click" />
-          <toggleButton id="ToggleButtonEnableProtection"
-                        size="large"
-                        getEnabled="ToggleButtonEnableProtection_GetEnabled"
-                        getImage="ToggleButtonEnableProtection_GetImage"
-                        getLabel="ToggleButtonEnableProtection_GetLabel"
-                        getPressed="ToggleButtonEnableProtection_GetPressed"
-                        getSupertip="ToggleButtonEnableProtection_GetSupertip"
-                        getVisible="ToggleButtonEnableProtection_GetVisible"
-                        onAction="ToggleButtonEnableProtection_Click" />
-          <toggleButton id="ToggleButtonNeverUnsecure"
-                        size="large"
-                        getEnabled="ToggleButtonNeverUnsecure_GetEnabled"
-                        getImage="ToggleButtonNeverUnsecure_GetImage"
-                        getLabel="ToggleButtonNeverUnsecure_GetLabel"
-                        getPressed="ToggleButtonNeverUnsecure_GetPressed"
-                        getSupertip="ToggleButtonNeverUnsecure_GetSupertip"
-                        getVisible="ToggleButtonNeverUnsecure_GetVisible"
-                        onAction="ToggleButtonNeverUnsecure_Click" />
+          <splitButton id="PEPButton"
+                       size="large"
+                       getVisible="ButtonPrivacyStatus_GetVisible">
+            <button id="ButtonPrivacyStatus"
+                    getImage="ButtonPrivacyStatus_GetImage"
+                    getLabel="ButtonPrivacyStatus_GetLabel"
+                    getScreentip="ButtonPrivacyStatus_GetScreentip"
+                    onAction="ButtonPrivacyStatus_Click"/>
+            <menu id="menu">
+              <toggleButton id="ToggleButtonForceUnencrypted"
+                            getEnabled="ToggleButtonForceUnencrypted_GetEnabled"
+                            getLabel="ToggleButtonForceUnencrypted_GetLabel"
+                            getPressed="ToggleButtonForceUnencrypted_GetPressed"
+                            getSupertip="ToggleButtonForceUnencrypted_GetSupertip"
+                            getVisible="ToggleButtonForceUnencrypted_GetVisible"
+                            onAction="ToggleButtonForceUnencrypted_Click" />
+              <toggleButton id="ToggleButtonForceProtection"
+                            getEnabled="ToggleButtonForceProtection_GetEnabled"
+                            getLabel="ToggleButtonForceProtection_GetLabel"
+                            getPressed="ToggleButtonForceProtection_GetPressed"
+                            getSupertip="ToggleButtonForceProtection_GetSupertip"
+                            getVisible="ToggleButtonForceProtection_GetVisible"
+                            onAction="ToggleButtonForceProtection_Click" />
+              <toggleButton id="ToggleButtonEnableProtection"
+                            getEnabled="ToggleButtonEnableProtection_GetEnabled"
+                            getLabel="ToggleButtonEnableProtection_GetLabel"
+                            getPressed="ToggleButtonEnableProtection_GetPressed"
+                            getSupertip="ToggleButtonEnableProtection_GetSupertip"
+                            getVisible="ToggleButtonEnableProtection_GetVisible"
+                            onAction="ToggleButtonEnableProtection_Click" />
+              <toggleButton id="ToggleButtonNeverUnsecure"
+                            getEnabled="ToggleButtonNeverUnsecure_GetEnabled"
+                            getLabel="ToggleButtonNeverUnsecure_GetLabel"
+                            getPressed="ToggleButtonNeverUnsecure_GetPressed"
+                            getSupertip="ToggleButtonNeverUnsecure_GetSupertip"
+                            getVisible="ToggleButtonNeverUnsecure_GetVisible"
+                            onAction="ToggleButtonNeverUnsecure_Click" />
+            </menu>
+          </splitButton>
           <button id="ButtonUpgradePEPNewMessage"
                   size="large"
                   getEnabled="ButtonUpgradePEP_GetEnabled"
@@ -59,7 +62,7 @@
                   getVisible="ButtonUpgradePEP_GetVisible"
                   onAction="ButtonUpgradePEP_Click" />
         </group>
-      </tab>            
+      </tab>
     </tabs>
   </ribbon>
   <backstage>
--- a/UI/RibbonCustomizationsExplorer.xml	Mon Jul 16 12:26:12 2018 +0200
+++ b/UI/RibbonCustomizationsExplorer.xml	Fri Jul 20 13:22:30 2018 +0200
@@ -6,8 +6,14 @@
       <tab idMso="TabMail">
         <group id="GroupUpgradePEPHome"
                insertAfterMso="GroupSendReceive"
-               label="p≡p"
-               getVisible="GroupUpgradePEP_GetVisible">
+               label="p≡p">
+          <button id="ButtonPrivacyStatus"
+                  size="large"
+                  getImage="ButtonPrivacyStatus_GetImage"
+                  getVisible="ButtonPrivacyStatus_GetVisible"
+                  getLabel="ButtonPrivacyStatus_GetLabel"
+                  getScreentip="ButtonPrivacyStatus_GetScreentip"
+                  onAction="ButtonPrivacyStatus_Click"/>
           <button id="ButtonUpgradePEPHome"
                   size="large"
                   getEnabled="ButtonUpgradePEP_GetEnabled"
@@ -109,16 +115,16 @@
     <contextMenu idMso="ContextMenuStore">
       <menu id="ContextMenuKeyImport"
             getImage="ContextMenuKeyImport_GetImage"
-            getVisible="ContextMenuKeyImport_GetVisible"            
+            getVisible="ContextMenuKeyImport_GetVisible"
             getLabel="ContextMenuKeyImport_GetLabel">
         <button id="ContextMenuKeyImportButtonPEP"
                 getLabel="ContextMenuKeyImportButtonPEP_GetLabel"
                 imageMso="AdpPrimaryKey"
                 onAction="ContextMenuKeyImportButton_Click"/>
-          <button id="ContextMenuKeyImportButtonPGP"
-                  getLabel="ContextMenuKeyImportButtonPGP_GetLabel"
-                  imageMso="AdpPrimaryKey"
-                  onAction="ContextMenuKeyImportButton_Click"/>
+        <button id="ContextMenuKeyImportButtonPGP"
+                getLabel="ContextMenuKeyImportButtonPGP_GetLabel"
+                imageMso="AdpPrimaryKey"
+                onAction="ContextMenuKeyImportButton_Click"/>
       </menu>
     </contextMenu>
   </contextMenus>
--- a/UI/RibbonCustomizationsRead.xml	Mon Jul 16 12:26:12 2018 +0200
+++ b/UI/RibbonCustomizationsRead.xml	Fri Jul 20 13:22:30 2018 +0200
@@ -6,8 +6,14 @@
       <tab idMso="TabReadMessage">
         <group id="GroupUpgradePEPReadMessage"
                insertAfterMso="GroupZoom"
-               label="p≡p"
-               getVisible="GroupUpgradePEP_GetVisible">
+               label="p≡p">
+          <button id="ButtonPrivacyStatus"
+                  size="large"
+                  getImage="ButtonPrivacyStatus_GetImage"
+                  getVisible="ButtonPrivacyStatus_GetVisible"
+                  getLabel="ButtonPrivacyStatus_GetLabel"
+                  getScreentip="ButtonPrivacyStatus_GetScreentip"
+                  onAction="ButtonPrivacyStatus_Click"/>
           <button id="ButtonUpgradePEPReadMessage"
                   size="large"
                   getEnabled="ButtonUpgradePEP_GetEnabled"
--- a/pEpForOutlook.csproj	Mon Jul 16 12:26:12 2018 +0200
+++ b/pEpForOutlook.csproj	Fri Jul 20 13:22:30 2018 +0200
@@ -524,6 +524,9 @@
     <WCFMetadata Include="Service References\" />
   </ItemGroup>
   <ItemGroup>
+    <Resource Include="Resources\ImagePrivacyStatusGreenProtectionDisabled.png" />
+    <Resource Include="Resources\ImagePrivacyStatusYellowProtectionDisabled.png" />
+    <Content Include="UI\RibbonCustomizations.xml" />
     <EmbeddedResource Include="UI\RibbonCustomizationsCompose.xml">
       <SubType>Designer</SubType>
     </EmbeddedResource>
@@ -540,6 +543,9 @@
     <Resource Include="Resources\ImagePrivacyStatusNoColorInvert.png" />
     <Resource Include="Resources\ImagePrivacyStatusRedInvert.png" />
     <Resource Include="Resources\ImagePrivacyStatusYellowInvert.png" />
+    <Resource Include="Resources\ImageRatingGreen.png" />
+    <Resource Include="Resources\ImageRatingRed.png" />
+    <Resource Include="Resources\ImageRatingYellow.png" />
     <Content Include="Resources\ImageReaderSplash.png" />
     <Content Include="Resources\ImageUpgradePEP.png" />
     <Resource Include="Resources\ImageNeverUnsecureOff.png" />