Merge with sync OUT-445
authorThomas
Mon, 18 Nov 2019 10:47:37 +0100
branchOUT-445
changeset 2864a270517f8860
parent 2855 de4fd5064177
parent 2863 8d5bd5db108d
child 2865 9ef6cd3d8ae5
Merge with sync
UI/FormControlOptions.xaml.cs
     1.1 --- a/AdapterCallbacks.cs	Fri Nov 08 10:23:21 2019 +0100
     1.2 +++ b/AdapterCallbacks.cs	Mon Nov 18 10:47:37 2019 +0100
     1.3 @@ -3,6 +3,7 @@
     1.4  using pEp.UI.Views;
     1.5  using pEpCOMServerAdapterLib;
     1.6  using System;
     1.7 +using System.Diagnostics;
     1.8  using System.Runtime.InteropServices;
     1.9  
    1.10  namespace pEp
    1.11 @@ -29,6 +30,7 @@
    1.12              Log.Verbose("NotifyHandshake: Received signal " + signal.ToString());
    1.13  
    1.14  #if DEBUG
    1.15 +            Debug.Assert(signal != SyncHandshakeSignal.SyncNotifyUndefined);
    1.16              Notification.Show(signal.ToString(), "NotifyHandshake called with signal " + signal.ToString());
    1.17  #endif
    1.18              // Send sync handshake signal to dialog (if existing)
    1.19 @@ -85,16 +87,6 @@
    1.20                          Notification.Show(Properties.Resources.KeySync_DeviceGroup, Properties.Resources.KeySync_NotifyAcceptedGroupCreated);
    1.21                          break;
    1.22                      }
    1.23 -                // Signal to close the dialog (actually, it is already closed at this point)
    1.24 -                case SyncHandshakeSignal.SyncNotifyOvertaken:
    1.25 -                    {
    1.26 -                        break;
    1.27 -                    }
    1.28 -                // Signal that a group is being formed
    1.29 -                case SyncHandshakeSignal.SyncNotifyFormingGroup:
    1.30 -                    {
    1.31 -                        break;
    1.32 -                    }
    1.33                  // Signal to show that the device is in state sole
    1.34                  case SyncHandshakeSignal.SyncNotifySole:
    1.35                      {
     2.1 --- a/CryptableMailItem.cs	Fri Nov 08 10:23:21 2019 +0100
     2.2 +++ b/CryptableMailItem.cs	Mon Nov 18 10:47:37 2019 +0100
     2.3 @@ -1069,7 +1069,7 @@
     2.4                      {
     2.5                          if (PEPMessage.Create(this.internalMailItem, out mirror) == Globals.ReturnStatus.Success)
     2.6                          {
     2.7 -                            result.Rating = AdapterExtensions.ReevaluateMessageRating(mirror);
     2.8 +                            result.Rating = mirror.Rating;
     2.9                              this.Message = mirror;
    2.10                          }
    2.11                      }
    2.12 @@ -1125,7 +1125,7 @@
    2.13                          // Get UI rating from mirror
    2.14                          try
    2.15                          {
    2.16 -                            result.Rating = AdapterExtensions.ReevaluateMessageRating(mirror);
    2.17 +                            result.Rating = mirror.Rating;
    2.18                          }
    2.19                          catch (Exception ex)
    2.20                          {
    2.21 @@ -1391,10 +1391,6 @@
    2.22                                      message.Rating = processedRating;
    2.23                                      processedRating = AdapterExtensions.ReevaluateFPPMessageRating(message);
    2.24                                  }
    2.25 -                                else
    2.26 -                                {
    2.27 -                                    processedRating = AdapterExtensions.ReevaluateMessageRating(message, processedRating);
    2.28 -                                }
    2.29                              }
    2.30                          }
    2.31                      }
     3.1 --- a/PEPIdentity.cs	Fri Nov 08 10:23:21 2019 +0100
     3.2 +++ b/PEPIdentity.cs	Mon Nov 18 10:47:37 2019 +0100
     3.3 @@ -887,6 +887,16 @@
     3.4          }
     3.5  
     3.6          /// <summary>
     3.7 +        /// Gets whether the given identity is an own identity.
     3.8 +        /// </summary>
     3.9 +        /// <param name="identity">The identity to check.</param>
    3.10 +        /// <returns>True if the identity is an own identity, otherwise false.</returns>
    3.11 +        public static bool GetIsOwnIdentity(PEPIdentity identity)
    3.12 +        {
    3.13 +            return PEPIdentity.GetIsOwnIdentity(identity.Address);
    3.14 +        }
    3.15 +
    3.16 +        /// <summary>
    3.17          /// Gets whether the given address represents an own personal identity (myself).
    3.18          /// This is done by comparing against the current session's account list.
    3.19          /// If a registered account's SMTP address, or current user address, matches the given address (case insensitive), it is a match.
     4.1 --- a/PEPMessage.cs	Fri Nov 08 10:23:21 2019 +0100
     4.2 +++ b/PEPMessage.cs	Mon Nov 18 10:47:37 2019 +0100
     4.3 @@ -630,7 +630,7 @@
     4.4          /// <param name="propertyName">The name of the property that changed.</param>
     4.5          private void RaisePropertyChangedEvent(string propertyName)
     4.6          {
     4.7 -            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));           
     4.8 +            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
     4.9          }
    4.10  
    4.11          /// <summary>
    4.12 @@ -1688,7 +1688,7 @@
    4.13                              // Marshal.ReleaseComObject(newRecipient);
    4.14                              newRecipient = null;
    4.15                          }
    4.16 -                    }                    
    4.17 +                    }
    4.18                  }
    4.19  
    4.20                  /* Add the pEp From identity as its own recipient. This will be removed later.
    4.21 @@ -1849,7 +1849,7 @@
    4.22                          recipients.ResolveAll();
    4.23                      }
    4.24                      catch { }
    4.25 -                }                
    4.26 +                }
    4.27  
    4.28                  // ReplyTo recipients
    4.29                  recipients = omi.ReplyRecipients;
    4.30 @@ -2313,6 +2313,55 @@
    4.31           * 
    4.32           *************************************************************/
    4.33  
    4.34 +        public static pEpRating CalculateRating(PEPMessage message)
    4.35 +        {
    4.36 +            pEpRating rating = pEpRating.pEpRatingTrustedAndAnonymized;
    4.37 +            List<PEPIdentity> recipients = new List<PEPIdentity>
    4.38 +            {
    4.39 +                message.From
    4.40 +            };
    4.41 +
    4.42 +            message.To?.ForEach(identity =>
    4.43 +            {
    4.44 +                recipients.Add(identity);
    4.45 +            });
    4.46 +
    4.47 +            message.Cc?.ForEach(identity =>
    4.48 +            {
    4.49 +                recipients.Add(identity);
    4.50 +            });
    4.51 +
    4.52 +            message.Bcc?.ForEach(identity =>
    4.53 +            {
    4.54 +                recipients.Add(identity);
    4.55 +            });
    4.56 +
    4.57 +            recipients.ForEach(identity =>
    4.58 +            {
    4.59 +                // Skip own identities
    4.60 +                if (PEPIdentity.GetIsOwnIdentity(identity) == false)
    4.61 +                {
    4.62 +                    try
    4.63 +                    {
    4.64 +                        pEpIdentity _identity = identity.ToCOMType();
    4.65 +                        _identity = ThisAddIn.PEPEngine.UpdateIdentity(_identity);
    4.66 +                        pEpRating identityRating = ThisAddIn.PEPEngine.RatingFromCommType(_identity.CommType);
    4.67 +
    4.68 +                        if (identityRating < rating)
    4.69 +                        {
    4.70 +                            rating = identityRating;
    4.71 +                        }
    4.72 +                    }
    4.73 +                    catch (Exception ex)
    4.74 +                    {
    4.75 +                        Log.Error("CalculateRating: Error updating identity. " + ex.ToString());
    4.76 +                    }
    4.77 +                }
    4.78 +            });
    4.79 +
    4.80 +            return rating;
    4.81 +        }
    4.82 +
    4.83          /// <summary>
    4.84          /// Constructs a new message from the given pEp engine TextMessage.
    4.85          /// The output will never be null.
     5.1 --- a/ThisAddIn.cs	Fri Nov 08 10:23:21 2019 +0100
     5.2 +++ b/ThisAddIn.cs	Mon Nov 18 10:47:37 2019 +0100
     5.3 @@ -1225,6 +1225,25 @@
     5.4                  }
     5.5                  this._Settings.HideInternalMessages = state.HideInternalMessages;
     5.6  
     5.7 +                // If the user disables sync for all accounts, leave device group, if necessary
     5.8 +                if ((state.IsGrouped) &&
     5.9 +                    (state.IsSyncEnabledForAllAccounts == false) &&
    5.10 +                    (this._Settings.IsSyncEnabledForAllAccounts))
    5.11 +                {
    5.12 +                    try
    5.13 +                    {
    5.14 +                        ThisAddIn.PEPEngine.LeaveDeviceGroup();
    5.15 +                    }
    5.16 +                    catch (Exception ex)
    5.17 +                    {
    5.18 +                        Log.Error("SetOptionsState: Error occured while trying to leave device group. " + ex.ToString());
    5.19 +                    }
    5.20 +                }
    5.21 +                else // else just sync the setting
    5.22 +                {
    5.23 +                    this._Settings.IsSyncEnabledForAllAccounts = state.IsSyncEnabledForAllAccounts;
    5.24 +                }
    5.25 +
    5.26                  this._Settings.IsAutoUpdateEnabled = state.IsAutoUpdateEnabled;
    5.27                  this._Settings.IsEncryptAllAccountsEnabled = state.IsEncryptAllAccountsEnabled;
    5.28                  this._Settings.IsNeverUnsecureOptionVisible = state.IsNeverUnsecureOptionVisible;
    5.29 @@ -1232,7 +1251,6 @@
    5.30                  this._Settings.IsPEPFolderVisible = state.IsPEPFolderVisible;
    5.31                  this._Settings.IsPrivacyStatusBarEnabled = state.IsPrivacyStatusBarEnabled;
    5.32                  this._Settings.IsSecurityLossWarningEnabled = state.IsSecurityLossWarningEnabled;
    5.33 -                this._Settings.IsSyncEnabledForAllAccounts = state.IsSyncEnabledForAllAccounts;
    5.34                  this._Settings.IsUnencryptedSubjectEnabled = state.IsUnencryptedSubjectEnabled;
    5.35                  this._Settings.IsVerboseLoggingEnabled = state.IsVerboseLoggingEnabled;
    5.36                  this._Settings.TrustwordsCulture = ((state.TrustwordsCulture != null) ? new CultureInfo(state.TrustwordsCulture.LCID) : null);
     6.1 --- a/UI/FormControlOptions.xaml.cs	Fri Nov 08 10:23:21 2019 +0100
     6.2 +++ b/UI/FormControlOptions.xaml.cs	Mon Nov 18 10:47:37 2019 +0100
     6.3 @@ -265,8 +265,15 @@
     6.4          {
     6.5              try
     6.6              {
     6.7 +                // Leave the device group
     6.8                  ThisAddIn.PEPEngine.LeaveDeviceGroup();
     6.9 +
    6.10 +                // Calling LeaveDeviceGroup will shutdown sync, so we have to persist
    6.11 +                // this setting in the app to not start sync again.
    6.12                  this.DisplayState.IsGrouped = false;
    6.13 +                this.DisplayState.IsSyncEnabledForAllAccounts = false;
    6.14 +
    6.15 +                // Show a success notification
    6.16                  Notification.Show(Properties.Resources.KeySync_DeviceGroup, Properties.Resources.Notifications_DeviceGroupLeftText);
    6.17              }
    6.18              catch (Exception ex)
     7.1 --- a/UI/FormControlPreviewMessage.xaml.cs	Fri Nov 08 10:23:21 2019 +0100
     7.2 +++ b/UI/FormControlPreviewMessage.xaml.cs	Mon Nov 18 10:47:37 2019 +0100
     7.3 @@ -696,7 +696,7 @@
     7.4                  this.OnPropertyChanged(nameof(this.FromRecipient));
     7.5  
     7.6                  // Contact Icon color
     7.7 -                this.ContactIconBackground = (SolidColorBrush)new BrushConverter().ConvertFromString("#03AA4B");
     7.8 +                this.ContactIconBackground = Brushes.DarkGray;
     7.9                  this.OnPropertyChanged(nameof(this.ContactIconBackground));
    7.10  
    7.11                  // Contact Icon text
     8.1 --- a/UI/Models/Dialog.cs	Fri Nov 08 10:23:21 2019 +0100
     8.2 +++ b/UI/Models/Dialog.cs	Mon Nov 18 10:47:37 2019 +0100
     8.3 @@ -124,7 +124,17 @@
     8.4                  try
     8.5                  {
     8.6                      pEpIdentity _identity = identity.ToCOMType();
     8.7 -                    _identity = ThisAddIn.PEPEngine.UpdateIdentity(_identity);
     8.8 +
     8.9 +                    if (PEPIdentity.GetIsOwnIdentity(identity.Address))
    8.10 +                    {
    8.11 +                        _identity = ThisAddIn.PEPEngine.UpdateIdentity(_identity);
    8.12 +                        _identity.UserId = PEPSettings.PEP_OWN_USER_ID;
    8.13 +                    }
    8.14 +                    else
    8.15 +                    {
    8.16 +                        _identity = ThisAddIn.PEPEngine.UpdateIdentity(_identity);
    8.17 +                    }
    8.18 +
    8.19                      identity = new PEPIdentity(_identity)
    8.20                      {
    8.21                          Rating = ThisAddIn.PEPEngine.RatingFromCommType(_identity.CommType)
     9.1 --- a/UI/ViewModels/HandshakeDialogViewModel.cs	Fri Nov 08 10:23:21 2019 +0100
     9.2 +++ b/UI/ViewModels/HandshakeDialogViewModel.cs	Mon Nov 18 10:47:37 2019 +0100
     9.3 @@ -141,7 +141,7 @@
     9.4          /// <summary>
     9.5          /// Builds the dialog.
     9.6          /// </summary>
     9.7 -        /// <returns>True if the dialog has been built successfully, otherwise false</returns>
     9.8 +        /// <returns>True if the dialog has been built successfully, otherwise false.</returns>
     9.9          public void BuildDialog()
    9.10          {
    9.11              // Add primary identities
    10.1 --- a/UI/ViewModels/HandshakeViewModel.cs	Fri Nov 08 10:23:21 2019 +0100
    10.2 +++ b/UI/ViewModels/HandshakeViewModel.cs	Mon Nov 18 10:47:37 2019 +0100
    10.3 @@ -29,7 +29,8 @@
    10.4          private string                              _ExplanationText            = null;
    10.5          private string                              _FingerprintMyself          = null;
    10.6          private string                              _FingerprintPartner         = null;
    10.7 -        private bool                                _IsExpanded                 = false;
    10.8 +        private bool                                _IsExpanded                 = false; 
    10.9 +        private bool                                _IsResetButtonVisible       = false;
   10.10          private bool                                _IsSeparatorVisible         = false;
   10.11          private PEPIdentity                         _Partner                    = null;
   10.12          private string                              _PartnerDisplayName         = null;
   10.13 @@ -176,6 +177,19 @@
   10.14          }
   10.15  
   10.16          /// <summary>
   10.17 +        /// Gets or sets whether the Reset button is visible.
   10.18 +        /// </summary>
   10.19 +        public bool IsResetButtonVisible
   10.20 +        {
   10.21 +            get => this._IsResetButtonVisible;
   10.22 +            set
   10.23 +            {
   10.24 +                this._IsResetButtonVisible = value;
   10.25 +                this.OnPropertyChanged();
   10.26 +            }
   10.27 +        }
   10.28 +
   10.29 +        /// <summary>
   10.30          /// Gets or sets whether the separator is visible.
   10.31          /// </summary>
   10.32          public bool IsSeparatorVisible
   10.33 @@ -443,6 +457,9 @@
   10.34  
   10.35              // Set explanation text
   10.36              this.SetExplanationText();
   10.37 +
   10.38 +            // Define visibility of Reset button
   10.39 +            this.IsResetButtonVisible = (this.Parent.Dialog.DialogType == Dialog.Type.Handshake) && (this.Partner.IsOwnIdentity == false);
   10.40          }
   10.41  
   10.42          /// <summary>
   10.43 @@ -470,9 +487,6 @@
   10.44  
   10.45              // Update the view
   10.46              this.UpdateView();
   10.47 -
   10.48 -            // Update all open windows
   10.49 -            Globals.ThisAddIn.RecalculateAllWindows(null);
   10.50          }
   10.51  
   10.52          /// <summary>
   10.53 @@ -500,9 +514,6 @@
   10.54  
   10.55              // Update the view
   10.56              this.UpdateView();
   10.57 -
   10.58 -            // Update all open windows
   10.59 -            Globals.ThisAddIn.RecalculateAllWindows(null);
   10.60          }
   10.61  
   10.62          /// <summary>
   10.63 @@ -519,9 +530,6 @@
   10.64                  // Update the view
   10.65                  this.UpdateView();
   10.66  
   10.67 -                // Update all open windows
   10.68 -                Globals.ThisAddIn.RecalculateAllWindows(null);
   10.69 -
   10.70                  // Shot notification
   10.71                  Notification.Show(Properties.Resources.Options_Reset, Properties.Resources.Notifications_CommunicationPartnerReset);
   10.72              }
    11.1 --- a/UI/Views/DialogWindow.xaml.cs	Fri Nov 08 10:23:21 2019 +0100
    11.2 +++ b/UI/Views/DialogWindow.xaml.cs	Mon Nov 18 10:47:37 2019 +0100
    11.3 @@ -119,11 +119,10 @@
    11.4          /// <param name="signal">The received sync handshake signal.</param>
    11.5          private void SyncHandshakeSignalReceivedAction(SyncHandshakeSignal signal)
    11.6          {
    11.7 -            /* Close handshake dialog if the signal type is not "Undefined" 
    11.8 -             * or "Forming Group", in which case the status quo should be preserved.
    11.9 +            /* Close handshake dialog if the signal type is not "Undefined", 
   11.10 +             * in which case the status quo should be preserved.
   11.11               */
   11.12 -            if ((signal != SyncHandshakeSignal.SyncNotifyUndefined) &&
   11.13 -                (signal != SyncHandshakeSignal.SyncNotifyFormingGroup))
   11.14 +            if (signal != SyncHandshakeSignal.SyncNotifyUndefined)
   11.15              {
   11.16                  this.InvokeClosing(true);
   11.17              }
    12.1 --- a/UI/Views/HandshakeView.xaml	Fri Nov 08 10:23:21 2019 +0100
    12.2 +++ b/UI/Views/HandshakeView.xaml	Mon Nov 18 10:47:37 2019 +0100
    12.3 @@ -237,7 +237,7 @@
    12.4                          HorizontalAlignment="Right"
    12.5                          VerticalAlignment="Center"
    12.6                          Margin="0,5,0,0"
    12.7 -                        Visibility="{Binding Parent.Dialog.DialogType, Converter={StaticResource IsNotWizardModeToVisibility}}">
    12.8 +                        Visibility="{Binding IsResetButtonVisible, Converter={StaticResource BoolToVisibility}}">
    12.9                  <TextBlock Text="{x:Static p:Resources.DialogWindow_ResetCommunicationPartner}" 
   12.10                             VerticalAlignment="Center"
   12.11                             Margin="5"/>
    13.1 --- a/Wrappers/WatchedWindow.cs	Fri Nov 08 10:23:21 2019 +0100
    13.2 +++ b/Wrappers/WatchedWindow.cs	Mon Nov 18 10:47:37 2019 +0100
    13.3 @@ -1,5 +1,4 @@
    13.4 -using pEp.UI;
    13.5 -using pEp.UI.Models;
    13.6 +using pEp.UI.Models;
    13.7  using pEp.UI.Views;
    13.8  using pEpCOMServerAdapterLib;
    13.9  using System;
   13.10 @@ -17,6 +16,7 @@
   13.11      {
   13.12          private CryptableMailItem               cryptableMailItem           = null;
   13.13          private bool                            displayMirrorRequested      = false;
   13.14 +        private PEPMessage                      handshakeMessage            = null;
   13.15          private bool                            isEnabled                   = true;
   13.16          private bool                            isStarted                   = false;
   13.17          private bool                            processingOngoing           = false;
   13.18 @@ -26,7 +26,7 @@
   13.19          private const int                       maxRepeatCount              = 5;
   13.20  
   13.21  
   13.22 -        internal static DialogWindow              HandshakeDialog             = null;
   13.23 +        internal static DialogWindow            HandshakeDialog             = null;
   13.24  
   13.25          public enum WindowType
   13.26          {
   13.27 @@ -197,9 +197,6 @@
   13.28              // Build the dialog
   13.29              try
   13.30              {
   13.31 -                // The PEPMessage to build the dialog with
   13.32 -                PEPMessage message = null;
   13.33 -
   13.34                  // The own identity to build the dialog with
   13.35                  PEPIdentity myself = this.cryptableMailItem?.Myself;
   13.36  
   13.37 @@ -208,130 +205,58 @@
   13.38                  {
   13.39                      Log.Verbose("BuildAndShowHandshakeDialog: Creating PEPMessage from draft.");
   13.40  
   13.41 -                    if (PEPMessage.Create(this.CurrentMailItem, out message, true) == Globals.ReturnStatus.Success)
   13.42 +                    if (PEPMessage.Create(this.CurrentMailItem, out this.handshakeMessage, true) == Globals.ReturnStatus.Success)
   13.43                      {
   13.44 -                        // Calculate rating
   13.45 -                        message.Rating = message.GetOutgoingRating();
   13.46 -
   13.47                          // If Force Protection is set, assign a random GUID
   13.48                          if ((this.ForceProtection) &&
   13.49                              (this.DisableForceProtection == false))
   13.50                          {
   13.51 -                            message.ForceProtectionId = Guid.NewGuid().ToString();
   13.52 +                            this.handshakeMessage.ForceProtectionId = Guid.NewGuid().ToString();
   13.53                          }
   13.54  
   13.55                          // If message is Force Unencrypted, assign it
   13.56 -                        message.ForceUnencrypted = this.ForceUnencrypted;
   13.57 +                        this.handshakeMessage.ForceUnencrypted = this.ForceUnencrypted;
   13.58                      }
   13.59                      else
   13.60                      {
   13.61                          Log.Error("BuildAndShowHandshakeDialog: Error creating PEPMessage from draft.");
   13.62 -                        message = null;
   13.63 +                        this.handshakeMessage = null;
   13.64                      }
   13.65                  }
   13.66                  else
   13.67                  {
   13.68 -                    // Else, use either the cryptable mail item's associated mirror or message
   13.69 -                    message = this.cryptableMailItem?.Mirror ?? this.cryptableMailItem?.Message;
   13.70 -                    Log.Verbose(string.Format("BuildAndShowHandshakeDialog: Message {0} retrieved from CryptableMailItem", ((message != null) ? "successfully" : "could not be")));
   13.71 -
   13.72 -                    // As fallback, if we don't have a message yet, create it
   13.73 -                    if (message == null)
   13.74 +                    // Create the message
   13.75 +                    if (PEPMessage.Create(this.CurrentMailItem, out this.handshakeMessage) != Globals.ReturnStatus.Success)
   13.76                      {
   13.77 -                        Log.Verbose("BuildAndShowHandshakeDialog: Using fallback method to get message.");
   13.78 -
   13.79 -                        Outlook.MailItem mirror = null;
   13.80 -
   13.81 -                        try
   13.82 -                        {
   13.83 -                            // For securely stored mails, try to look up mirror
   13.84 -                            if (this.CurrentMailItem?.GetIsSecurelyStored() == true)
   13.85 -                            {
   13.86 -                                mirror = this.CurrentMailItem?.GetMirror();
   13.87 -
   13.88 -                                if (mirror != null)
   13.89 -                                {
   13.90 -                                    // If mirror is found, use it to create PEPMessage
   13.91 -                                    Log.Verbose("BuildAndShowHandshakeDialog: Mirror found.");
   13.92 -
   13.93 -                                    if (PEPMessage.Create(mirror, out message) != Globals.ReturnStatus.Success)
   13.94 -                                    {
   13.95 -                                        message = null;
   13.96 -                                        Log.Error("BuildAndShowHandshakeDialog: Error creating PEPMessage.");
   13.97 -                                    }
   13.98 -                                    else
   13.99 -                                    {
  13.100 -                                        message.Rating = AdapterExtensions.ReevaluateMessageRating(message);
  13.101 -                                    }
  13.102 -                                }
  13.103 -                                else
  13.104 -                                {
  13.105 -                                    // If no mirror is found, decrypt message and use decrypted one (do not 
  13.106 -                                    // decrypt forcefully protected messages).
  13.107 -                                    if ((PEPMessage.Create(this.CurrentMailItem, out message) == Globals.ReturnStatus.Success) &&
  13.108 -                                        (string.IsNullOrEmpty(message.ForceProtectionId)))
  13.109 -                                    {
  13.110 -                                        var msgProcessor = new MsgProcessor();
  13.111 -                                        pEpDecryptFlags flags = pEpDecryptFlags.pEpDecryptFlagsNone;
  13.112 -                                        pEpRating rating = msgProcessor.Decrypt(ref message, out PEPMessage decryptedMsg, out string[] keyList, ref flags);
  13.113 -                                        if (decryptedMsg != null)
  13.114 -                                        {
  13.115 -                                            message = decryptedMsg;
  13.116 -                                        }
  13.117 -                                        message.Rating = rating;
  13.118 -                                    }
  13.119 -                                    else
  13.120 -                                    {
  13.121 -                                        message = null;
  13.122 -                                        Log.Error("BuildAndShowHandshakeDialog: Error creating PEPMessage from mirror.");
  13.123 -                                    }
  13.124 -                                }
  13.125 -                            }
  13.126 -
  13.127 -                            // If we don't have a PEPMessage yet, create it
  13.128 -                            if (message == null)
  13.129 -                            {
  13.130 -                                Log.Verbose("BuildAndShowHandshakeDialog: Creating PEPMessage.");
  13.131 -
  13.132 -                                if (PEPMessage.Create(this.CurrentMailItem, out message) != Globals.ReturnStatus.Success)
  13.133 -                                {
  13.134 -                                    message = null;
  13.135 -                                    Log.Error("BuildAndShowHandshakeDialog: Error creating PEPMessage.");
  13.136 -                                }
  13.137 -                                else
  13.138 -                                {
  13.139 -                                    message.Rating = AdapterExtensions.ReevaluateMessageRating(message);
  13.140 -                                }
  13.141 -                            }
  13.142 -
  13.143 -                            // Get myself identiy if we don't have it yet
  13.144 -                            if (myself == null)
  13.145 -                            {
  13.146 -                                myself = this.CurrentMailItem.GetMyselfIdentity();
  13.147 -                            }
  13.148 -                        }
  13.149 -                        catch (Exception ex)
  13.150 -                        {
  13.151 -                            Log.Error("BuildAndShowHandshakeDialog: Error converting message. " + ex.ToString());
  13.152 -                        }
  13.153 -                        finally
  13.154 -                        {
  13.155 -                            mirror = null;
  13.156 -                        }
  13.157 +                        this.handshakeMessage = null;
  13.158 +                        Log.Error("BuildAndShowHandshakeDialog: Error creating PEPMessage from mirror.");
  13.159                      }
  13.160                  }
  13.161  
  13.162                  // Build dialog
  13.163 -                if (message != null)
  13.164 +                if (this.handshakeMessage != null)
  13.165                  {
  13.166 +                    // Get myself identiy if we don't have it yet
  13.167 +                    if (myself == null)
  13.168 +                    {
  13.169 +                        myself = this.CurrentMailItem.GetMyselfIdentity();
  13.170 +                    }
  13.171 +
  13.172 +                    /* Add recipients to the dialog:
  13.173 +                     *  - For incoming messages, add the From recipient as primary
  13.174 +                     *    recipient and all others as secondary recipients.
  13.175 +                     *  - For outgoing messages, add all To recipients as primary
  13.176 +                     *    recipients and all others as secondary recipients.
  13.177 +                     * Note: don't add own identities as secondary recipients.
  13.178 +                     */
  13.179                      List<PEPIdentity> primaryPartners = new List<PEPIdentity>();
  13.180                      List<PEPIdentity> secondaryPartners = new List<PEPIdentity>();
  13.181  
  13.182 -                    if (message.Direction == pEpMsgDirection.pEpDirIncoming)
  13.183 +                    if (this.handshakeMessage.Direction == pEpMsgDirection.pEpDirIncoming)
  13.184                      {
  13.185 -                        primaryPartners.Add(message.From);
  13.186 +                        primaryPartners.Add(this.handshakeMessage.From);
  13.187  
  13.188 -                        message.To?.ForEach(identity =>
  13.189 +                        this.handshakeMessage.To?.ForEach(identity =>
  13.190                          {
  13.191                              if (PEPIdentity.GetIsOwnIdentity(identity.Address) == false)
  13.192                              {
  13.193 @@ -341,16 +266,13 @@
  13.194                      }
  13.195                      else
  13.196                      {
  13.197 -                        message.To?.ForEach(identity =>
  13.198 +                        this.handshakeMessage.To?.ForEach(identity =>
  13.199                          {
  13.200 -                            if (PEPIdentity.GetIsOwnIdentity(identity.Address) == false)
  13.201 -                            {
  13.202 -                                primaryPartners.Add(identity);
  13.203 -                            }
  13.204 +                            primaryPartners.Add(identity);
  13.205                          });
  13.206                      }
  13.207  
  13.208 -                    message.Cc?.ForEach(identity =>
  13.209 +                    this.handshakeMessage.Cc?.ForEach(identity =>
  13.210                      {
  13.211                          if (PEPIdentity.GetIsOwnIdentity(identity.Address) == false)
  13.212                          {
  13.213 @@ -358,7 +280,7 @@
  13.214                          }
  13.215                      });
  13.216  
  13.217 -                    message.Bcc?.ForEach(identity =>
  13.218 +                    this.handshakeMessage.Bcc?.ForEach(identity =>
  13.219                      {
  13.220                          if (PEPIdentity.GetIsOwnIdentity(identity.Address) == false)
  13.221                          {
  13.222 @@ -1526,7 +1448,54 @@
  13.223          /// </summary>
  13.224          protected void HandshakeDialog_Closed(object sender, EventArgs e)
  13.225          {
  13.226 -            this.RequestRatingAndUIUpdate();
  13.227 +            pEpRating newRating = this.Rating;
  13.228 +
  13.229 +            // Get the updated rating
  13.230 +            bool trustedServer = this.CurrentMailItem.GetIsInSecureStore();
  13.231 +            if (trustedServer)
  13.232 +            {
  13.233 +                string[] keyList = new string[] { };
  13.234 +                pEpDecryptFlags flags = pEpDecryptFlags.pEpDecryptFlagUntrustedServer;
  13.235 +                TextMessage msg = this.handshakeMessage.ToCOMType();
  13.236 +                newRating = ThisAddIn.PEPEngine.DecryptMessage(ref msg, out _, ref keyList, ref flags);
  13.237 +            }
  13.238 +            else
  13.239 +            {
  13.240 +                newRating = AdapterExtensions.ReevaluateMessageRating(this.handshakeMessage, this.Rating);
  13.241 +            }
  13.242 +
  13.243 +            // If the new rating is different, update the message with the new rating
  13.244 +            if (newRating != this.Rating)
  13.245 +            {
  13.246 +                Outlook.MailItem mirror = null;
  13.247 +
  13.248 +                try
  13.249 +                {
  13.250 +                    this.SetRating(newRating);
  13.251 +
  13.252 +                    if (trustedServer)
  13.253 +                    {
  13.254 +                        mirror = this.CurrentMailItem.GetMirror();
  13.255 +                        mirror.SetPEPProperty(MailItemExtensions.PEPProperty.Rating, newRating);
  13.256 +                        mirror.Save();
  13.257 +                    }
  13.258 +                    else
  13.259 +                    {
  13.260 +                        this.CurrentMailItem.SetPEPProperty(MailItemExtensions.PEPProperty.Rating, newRating);
  13.261 +                        this.CurrentMailItem.Save();
  13.262 +                    }
  13.263 +                }
  13.264 +                catch (Exception ex)
  13.265 +                {
  13.266 +                    Log.Error("HandshakeDialog_Closed: Error updating rating. " + ex.ToString());
  13.267 +                }
  13.268 +                finally
  13.269 +                {
  13.270 +                    mirror = null;
  13.271 +                }
  13.272 +            }
  13.273 +
  13.274 +            // Recalculate all other windows
  13.275              Globals.ThisAddIn.RecalculateAllWindows(this);
  13.276  
  13.277              if (WatchedWindow.HandshakeDialog != null)
  13.278 @@ -1534,6 +1503,8 @@
  13.279                  WatchedWindow.HandshakeDialog.Closed -= HandshakeDialog_Closed;
  13.280                  WatchedWindow.HandshakeDialog = null;
  13.281              }
  13.282 +
  13.283 +            this.handshakeMessage = null;
  13.284          }
  13.285  
  13.286          /// <summary>
    14.1 --- a/pEpForOutlook.csproj	Fri Nov 08 10:23:21 2019 +0100
    14.2 +++ b/pEpForOutlook.csproj	Mon Nov 18 10:47:37 2019 +0100
    14.3 @@ -259,8 +259,8 @@
    14.4        <EmbedInteropTypes>False</EmbedInteropTypes>
    14.5      </Reference>
    14.6      <Reference Include="Microsoft.VisualStudio.Tools.Applications.Runtime, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
    14.7 -    <Reference Include="MimeKitLite, Version=2.3.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814, processorArchitecture=MSIL">
    14.8 -      <HintPath>..\packages\MimeKitLite.2.3.1\lib\net45\MimeKitLite.dll</HintPath>
    14.9 +    <Reference Include="MimeKitLite, Version=2.4.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814, processorArchitecture=MSIL">
   14.10 +      <HintPath>..\packages\MimeKitLite.2.4.1\lib\net45\MimeKitLite.dll</HintPath>
   14.11      </Reference>
   14.12      <Reference Include="Office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
   14.13        <EmbedInteropTypes>True</EmbedInteropTypes>
   14.14 @@ -285,8 +285,8 @@
   14.15      <Reference Include="PresentationFramework" />
   14.16      <Reference Include="System" />
   14.17      <Reference Include="System.Data" />
   14.18 -    <Reference Include="System.Data.SQLite, Version=1.0.111.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
   14.19 -      <HintPath>..\packages\System.Data.SQLite.Core.1.0.111.0\lib\net45\System.Data.SQLite.dll</HintPath>
   14.20 +    <Reference Include="System.Data.SQLite, Version=1.0.112.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
   14.21 +      <HintPath>..\packages\System.Data.SQLite.Core.1.0.112.0\lib\net45\System.Data.SQLite.dll</HintPath>
   14.22      </Reference>
   14.23      <Reference Include="System.Drawing" />
   14.24      <Reference Include="System.Runtime.Caching" />
   14.25 @@ -751,11 +751,13 @@
   14.26        </FlavorProperties>
   14.27      </VisualStudio>
   14.28    </ProjectExtensions>
   14.29 -  <Import Project="..\packages\System.Data.SQLite.Core.1.0.111.0\build\net45\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.111.0\build\net45\System.Data.SQLite.Core.targets')" />
   14.30 +  <Import Project="..\packages\System.Data.SQLite.Core.1.0.112.0\build\net45\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.112.0\build\net45\System.Data.SQLite.Core.targets')" />
   14.31    <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
   14.32      <PropertyGroup>
   14.33        <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
   14.34      </PropertyGroup>
   14.35 -    <Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.111.0\build\net45\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.111.0\build\net45\System.Data.SQLite.Core.targets'))" />
   14.36 +    <Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.112.0\build\net45\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.112.0\build\net45\System.Data.SQLite.Core.targets'))" />
   14.37 +    <Error Condition="!Exists('..\packages\boost.1.71.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.71.0.0\build\boost.targets'))" />
   14.38    </Target>
   14.39 +  <Import Project="..\packages\boost.1.71.0.0\build\boost.targets" Condition="Exists('..\packages\boost.1.71.0.0\build\boost.targets')" />
   14.40  </Project>
   14.41 \ No newline at end of file
    15.1 --- a/packages.config	Fri Nov 08 10:23:21 2019 +0100
    15.2 +++ b/packages.config	Mon Nov 18 10:47:37 2019 +0100
    15.3 @@ -1,5 +1,6 @@
    15.4  <?xml version="1.0" encoding="utf-8"?>
    15.5  <packages>
    15.6 -  <package id="MimeKitLite" version="2.3.1" targetFramework="net45" />
    15.7 -  <package id="System.Data.SQLite.Core" version="1.0.111.0" targetFramework="net45" />
    15.8 +  <package id="boost" version="1.71.0.0" targetFramework="net45" />
    15.9 +  <package id="MimeKitLite" version="2.4.1" targetFramework="net45" />
   15.10 +  <package id="System.Data.SQLite.Core" version="1.0.112.0" targetFramework="net45" />
   15.11  </packages>
   15.12 \ No newline at end of file