Add reencryption Redesign_Ribbon
authorThomas
Tue, 22 May 2018 15:36:37 +0200
branchRedesign_Ribbon
changeset 2207191d9997af5e
parent 2206 d0173d827aa2
child 2221 f43484757177
Add reencryption
Extensions/MailItemExtensions.cs
MsgContainer.cs
MsgProcessor.cs
UI/HandshakeDialog.xaml.cs
UI/Ribbon/RibbonExtensions.cs
     1.1 --- a/Extensions/MailItemExtensions.cs	Tue May 22 11:35:06 2018 +0200
     1.2 +++ b/Extensions/MailItemExtensions.cs	Tue May 22 15:36:37 2018 +0200
     1.3 @@ -2415,7 +2415,7 @@
     1.4                      if (mirrorMailItem != null)
     1.5                      {
     1.6                          sts = PEPMessage.Create(mirrorMailItem, out newMessage);
     1.7 -                        msgCont.Mirror = newMessage;
     1.8 +                        msgCont.ProcessedMessage = newMessage;
     1.9                          msgCont.MirrorCreationStatus = sts;
    1.10                      }
    1.11                  }
    1.12 @@ -2435,7 +2435,7 @@
    1.13                  // Get other Outlook store/location information
    1.14                  msgCont.EntryId = omi.EntryID;
    1.15                  msgCont.IsDraft = omi.GetIsDraft();
    1.16 -                msgCont.IsInSecureStore = omi.GetIsInSecureStore();
    1.17 +                msgCont.IsOnUntrustedServer = omi.GetIsInSecureStore();
    1.18                  msgCont.IsInSentFolder = omi.GetIsInSentFolder();
    1.19                  msgCont.IsMirror = omi.GetIsMirror();
    1.20              }
     2.1 --- a/MsgContainer.cs	Tue May 22 11:35:06 2018 +0200
     2.2 +++ b/MsgContainer.cs	Tue May 22 15:36:37 2018 +0200
     2.3 @@ -1,9 +1,6 @@
     2.4  ´╗┐using pEpCOMServerAdapterLib;
     2.5  using System;
     2.6 -using System.Collections.Generic;
     2.7  using System.ComponentModel;
     2.8 -using System.Diagnostics;
     2.9 -using System.Runtime.InteropServices;
    2.10  using Outlook = Microsoft.Office.Interop.Outlook;
    2.11  
    2.12  namespace pEp
    2.13 @@ -26,16 +23,16 @@
    2.14          /// </summary>
    2.15          public event PropertyChangedEventHandler PropertyChanged;
    2.16  
    2.17 +        private pEpDecryptFlags      _DecryptionFlags;
    2.18          private string               _EntryId;
    2.19          private Exception            _Error;
    2.20 -        private pEpDecryptFlags      _DecryptionFlags;
    2.21          private bool                 _IsDraft;
    2.22 -        private bool                 _IsInSecureStore;
    2.23 +        private bool                 _IsOnUntrustedServer;
    2.24          private bool                 _IsInSentFolder;
    2.25          private bool                 _IsMirror;
    2.26          private PEPMessage           _Message;
    2.27          private Globals.ReturnStatus _MessageCreationStatus;
    2.28 -        private PEPMessage           _Mirror;
    2.29 +        private PEPMessage           _ProcessedMessage;
    2.30          private bool                 _MirrorCreated;
    2.31          private Globals.ReturnStatus _MirrorCreationStatus;
    2.32          private pEpRating            _Rating;
    2.33 @@ -62,6 +59,19 @@
    2.34           *************************************************************/
    2.35  
    2.36          /// <summary>
    2.37 +        /// Gets or sets the Decryption flags returned during decryption.
    2.38 +        /// </summary>
    2.39 +        public pEpDecryptFlags DecryptionFlags
    2.40 +        {
    2.41 +            get { return (this._DecryptionFlags); }
    2.42 +            set
    2.43 +            {
    2.44 +                this._DecryptionFlags = value;
    2.45 +                this.RaisePropertyChangedEvent(nameof(this.DecryptionFlags));
    2.46 +            }
    2.47 +        }
    2.48 +
    2.49 +        /// <summary>
    2.50          /// Gets or sets the EntryID used to locate the reference to the original MailItem.
    2.51          /// </summary>
    2.52          public string EntryId
    2.53 @@ -88,19 +98,6 @@
    2.54          }
    2.55  
    2.56          /// <summary>
    2.57 -        /// Gets or sets the Decryption flags returned during decryption.
    2.58 -        /// </summary>
    2.59 -        public pEpDecryptFlags DecryptionFlags
    2.60 -        {
    2.61 -            get { return (this._DecryptionFlags); }
    2.62 -            set
    2.63 -            {
    2.64 -                this._DecryptionFlags = value;
    2.65 -                this.RaisePropertyChangedEvent(nameof(this.DecryptionFlags));
    2.66 -            }
    2.67 -        }
    2.68 -
    2.69 -        /// <summary>
    2.70          /// Gets or sets whether the PEPMessage is a draft.
    2.71          /// This is not a property of the PEPMessage because the draft flag cannot be set after
    2.72          /// the MailItem is saved the first time. It depends on information at a higher level than
    2.73 @@ -117,19 +114,6 @@
    2.74          }
    2.75  
    2.76          /// <summary>
    2.77 -        /// Gets or sets whether the original MailItem is in a secure store.
    2.78 -        /// </summary>
    2.79 -        public bool IsInSecureStore
    2.80 -        {
    2.81 -            get { return (this._IsInSecureStore); }
    2.82 -            set
    2.83 -            {
    2.84 -                this._IsInSecureStore = value;
    2.85 -                this.RaisePropertyChangedEvent(nameof(this.IsInSecureStore));
    2.86 -            }
    2.87 -        }
    2.88 -
    2.89 -        /// <summary>
    2.90          /// Gets or sets whether the original MailItem is in the sent folder.
    2.91          /// </summary>
    2.92          public bool IsInSentFolder
    2.93 @@ -156,6 +140,30 @@
    2.94          }
    2.95  
    2.96          /// <summary>
    2.97 +        /// Gets or sets whether the original MailItem is on an untrusted server.
    2.98 +        /// </summary>
    2.99 +        public bool IsOnUntrustedServer
   2.100 +        {
   2.101 +            get { return (this._IsOnUntrustedServer); }
   2.102 +            set
   2.103 +            {
   2.104 +                this._IsOnUntrustedServer = value;
   2.105 +                this.RaisePropertyChangedEvent(nameof(this.IsOnUntrustedServer));
   2.106 +            }
   2.107 +        }
   2.108 +
   2.109 +        /// <summary>
   2.110 +        /// Gets whether the message is either on an untrusted server or tagged as NeverUnsecure
   2.111 +        /// </summary>
   2.112 +        public bool IsSecurelyStored
   2.113 +        {
   2.114 +            get
   2.115 +            {
   2.116 +                return (this.IsOnUntrustedServer || (this.Message?.NeverUnsecure == true));
   2.117 +            }
   2.118 +        }
   2.119 +
   2.120 +        /// <summary>
   2.121          /// Gets or sets the PEPMessage that represents the data in the original MailItem.
   2.122          /// </summary>
   2.123          public PEPMessage Message
   2.124 @@ -182,19 +190,6 @@
   2.125          }
   2.126  
   2.127          /// <summary>
   2.128 -        /// Gets or sets the PEPMessage that represents the data in an unencrypted mirror of the original MailItem.
   2.129 -        /// </summary>
   2.130 -        public PEPMessage Mirror
   2.131 -        {
   2.132 -            get { return (this._Mirror); }
   2.133 -            set
   2.134 -            {
   2.135 -                this._Mirror = value;
   2.136 -                this.RaisePropertyChangedEvent(nameof(this.Mirror));
   2.137 -            }
   2.138 -        }
   2.139 -
   2.140 -        /// <summary>
   2.141          /// Gets or sets whether a new mirror was created during decryption.
   2.142          /// </summary>
   2.143          public bool MirrorCreated
   2.144 @@ -221,6 +216,19 @@
   2.145          }
   2.146  
   2.147          /// <summary>
   2.148 +        /// Gets or sets the PEPMessage that represents the processed message.
   2.149 +        /// </summary>
   2.150 +        public PEPMessage ProcessedMessage
   2.151 +        {
   2.152 +            get { return (this._ProcessedMessage); }
   2.153 +            set
   2.154 +            {
   2.155 +                this._ProcessedMessage = value;
   2.156 +                this.RaisePropertyChangedEvent(nameof(this.ProcessedMessage));
   2.157 +            }
   2.158 +        }
   2.159 +
   2.160 +        /// <summary>
   2.161          /// Gets or sets the rating to be shown in the UI.
   2.162          /// </summary>
   2.163          public pEpRating Rating
   2.164 @@ -269,7 +277,7 @@
   2.165                  try
   2.166                  {
   2.167                      Log.Verbose("MsgContainer.Create. Starting...");
   2.168 -                    msgContainer.IsInSecureStore = omi.GetIsInSecureStore();
   2.169 +                    msgContainer.IsOnUntrustedServer = omi.GetIsInSecureStore();
   2.170                      Log.Verbose("MsgContainer.Create. GetIsInSecureStore.");
   2.171                      msgContainer.MessageCreationStatus = PEPMessage.Create(omi, out message);
   2.172                      Log.Verbose("MsgContainer.Create. Created message.");
   2.173 @@ -286,8 +294,8 @@
   2.174                      Log.Verbose("MsgContainer.Create. GetIsMirror.");
   2.175  
   2.176                      if (lookupMirror &&
   2.177 -                        (msgContainer.IsInSecureStore) &&
   2.178 -                        (msgContainer.Message?.IsSecure ?? false))
   2.179 +                        (msgContainer.IsSecurelyStored) &&
   2.180 +                        (msgContainer.Message?.IsSecure == true))
   2.181                      {
   2.182                          Outlook.MailItem mirror = null;
   2.183                          PEPMessage mirrorMessage = null;
   2.184 @@ -300,18 +308,16 @@
   2.185                              Log.Verbose("MsgContainer.Create. Created mirror.");
   2.186                              if (msgContainer.MirrorCreationStatus == Globals.ReturnStatus.Success)
   2.187                              {
   2.188 -                                msgContainer.Mirror = mirrorMessage;
   2.189 +                                msgContainer.ProcessedMessage = mirrorMessage;
   2.190 +                                msgContainer.Rating = AdapterExtensions.ReevaluateMessageRating(mirrorMessage);
   2.191                              }
   2.192                          }
   2.193                      }
   2.194  
   2.195 -                    if (msgContainer.Message != null)
   2.196 +                    if (msgContainer.Message?.Direction == pEpMsgDirection.pEpDirOutgoing)
   2.197                      {
   2.198 -                        if (msgContainer.Message.Direction == pEpMsgDirection.pEpDirOutgoing)
   2.199 -                        {
   2.200 -                            msgContainer.Rating = msgContainer.Message.GetOutgoingRating();
   2.201 -                            Log.Verbose("MsgContainer.Create. Outgoing rating.");
   2.202 -                        }
   2.203 +                        msgContainer.Rating = msgContainer.Message.GetOutgoingRating();
   2.204 +                        Log.Verbose("MsgContainer.Create. Outgoing rating.");
   2.205                      }
   2.206  
   2.207                      Log.Verbose("MsgContainer.Create. Container created.");
   2.208 @@ -345,14 +351,14 @@
   2.209              this._EntryId = null;
   2.210              this._Error = null;
   2.211              this._IsDraft = false;
   2.212 -            this._IsInSecureStore = false;
   2.213              this._IsInSentFolder = false;
   2.214              this._IsMirror = false;
   2.215 +            this._IsOnUntrustedServer = false;
   2.216              this._Message = null;
   2.217              this._MessageCreationStatus = Globals.ReturnStatus.Success;
   2.218 -            this._Mirror = null;
   2.219              this._MirrorCreated = false;
   2.220              this._MirrorCreationStatus = Globals.ReturnStatus.Success;
   2.221 +            this._ProcessedMessage = null;
   2.222              this._Rating = pEpRating.pEpRatingUndefined;
   2.223              this._StoreId = null;
   2.224  
   2.225 @@ -360,14 +366,14 @@
   2.226              this.RaisePropertyChangedEvent(nameof(this.EntryId));
   2.227              this.RaisePropertyChangedEvent(nameof(this.Error));
   2.228              this.RaisePropertyChangedEvent(nameof(this.IsDraft));
   2.229 -            this.RaisePropertyChangedEvent(nameof(this.IsInSecureStore));
   2.230              this.RaisePropertyChangedEvent(nameof(this.IsInSentFolder));
   2.231              this.RaisePropertyChangedEvent(nameof(this.IsMirror));
   2.232 +            this.RaisePropertyChangedEvent(nameof(this.IsOnUntrustedServer));
   2.233              this.RaisePropertyChangedEvent(nameof(this.Message));
   2.234              this.RaisePropertyChangedEvent(nameof(this.MessageCreationStatus));
   2.235 -            this.RaisePropertyChangedEvent(nameof(this.Mirror));
   2.236              this.RaisePropertyChangedEvent(nameof(this.MirrorCreated));
   2.237              this.RaisePropertyChangedEvent(nameof(this.MirrorCreationStatus));
   2.238 +            this.RaisePropertyChangedEvent(nameof(this.ProcessedMessage));
   2.239              this.RaisePropertyChangedEvent(nameof(this.Rating));
   2.240              this.RaisePropertyChangedEvent(nameof(this.StoreId));
   2.241  
   2.242 @@ -415,14 +421,14 @@
   2.243                  Comparisons.Equals(this.EntryId, obj.EntryId) &&
   2.244                  Comparisons.Equals(this.Error, obj.Error) &&
   2.245                  Comparisons.Equals(this.IsDraft, obj.IsDraft) &&
   2.246 -                Comparisons.Equals(this.IsInSecureStore, obj.IsInSecureStore) &&
   2.247                  Comparisons.Equals(this.IsInSentFolder, obj.IsInSentFolder) &&
   2.248                  Comparisons.Equals(this.IsMirror, obj.IsMirror) &&
   2.249 +                Comparisons.Equals(this.IsOnUntrustedServer, obj.IsOnUntrustedServer) &&
   2.250                  Comparisons.Equals(this.Message, obj.Message) &&
   2.251                  Comparisons.Equals(this.MessageCreationStatus, obj.MessageCreationStatus) &&
   2.252 -                Comparisons.Equals(this.Mirror, obj.Mirror) &&
   2.253                  Comparisons.Equals(this.MirrorCreated, obj.MirrorCreated) &&
   2.254                  Comparisons.Equals(this.MirrorCreationStatus, obj.MirrorCreationStatus) &&
   2.255 +                Comparisons.Equals(this.ProcessedMessage, obj.ProcessedMessage) &&
   2.256                  Comparisons.Equals(this.Rating, obj.Rating) &&
   2.257                  Comparisons.Equals(this.StoreId, obj.StoreId))
   2.258              {
   2.259 @@ -438,25 +444,23 @@
   2.260          /// <returns>The deep copy of the object.</returns>
   2.261          public MsgContainer Copy()
   2.262          {
   2.263 -            MsgContainer copy = new MsgContainer();
   2.264 -
   2.265 -            copy.DecryptionFlags = this._DecryptionFlags;
   2.266 -            copy.EntryId = (this._EntryId == null ? null : string.Copy(this._EntryId));
   2.267 -            copy.Error = this._Error;
   2.268 -            copy.IsDraft = this._IsDraft;
   2.269 -            copy.IsInSecureStore = this._IsInSecureStore;
   2.270 -            copy.IsInSentFolder = this._IsInSentFolder;
   2.271 -            copy.IsMirror = this._IsMirror;
   2.272 -            copy.Message = (this._Message == null ? null : this._Message.Copy());
   2.273 -            copy.MessageCreationStatus = this._MessageCreationStatus;
   2.274 -            copy.Mirror = (this._Mirror == null ? null : this._Mirror.Copy());
   2.275 -            copy.MirrorCreated = this._MirrorCreated;
   2.276 -            copy.MirrorCreationStatus = this._MirrorCreationStatus;
   2.277 -            copy.Rating = this._Rating;
   2.278 -            copy.StoreId = (this._StoreId == null ? null : string.Copy(this._StoreId));
   2.279 -
   2.280 -            return (copy);
   2.281 +            return new MsgContainer
   2.282 +            {
   2.283 +                DecryptionFlags = this._DecryptionFlags,
   2.284 +                EntryId = (this._EntryId == null ? null : string.Copy(this._EntryId)),
   2.285 +                Error = this._Error,
   2.286 +                IsDraft = this._IsDraft,
   2.287 +                IsInSentFolder = this._IsInSentFolder,
   2.288 +                IsMirror = this._IsMirror,
   2.289 +                IsOnUntrustedServer = this._IsOnUntrustedServer,
   2.290 +                Message = (this._Message == null ? null : this._Message.Copy()),
   2.291 +                MessageCreationStatus = this._MessageCreationStatus,
   2.292 +                MirrorCreated = this._MirrorCreated,
   2.293 +                MirrorCreationStatus = this._MirrorCreationStatus,
   2.294 +                ProcessedMessage = (this._ProcessedMessage == null ? null : this._ProcessedMessage.Copy()),
   2.295 +                Rating = this._Rating,
   2.296 +                StoreId = (this._StoreId == null ? null : string.Copy(this._StoreId))
   2.297 +            };
   2.298          }
   2.299 -
   2.300      }
   2.301  }
     3.1 --- a/MsgProcessor.cs	Tue May 22 11:35:06 2018 +0200
     3.2 +++ b/MsgProcessor.cs	Tue May 22 15:36:37 2018 +0200
     3.3 @@ -53,7 +53,7 @@
     3.4          /// Default constructor.
     3.5          /// </summary>
     3.6          public MsgProcessor()
     3.7 -        {           
     3.8 +        {
     3.9          }
    3.10  
    3.11          /**************************************************************
    3.12 @@ -93,7 +93,7 @@
    3.13                      if (updateUI == false)
    3.14                      {
    3.15                          Log.Verbose("ProcessMailItem: Same EntryId as last item. Skipped processing of item with EntryId " + msgContainer.EntryId);
    3.16 -                        return; 
    3.17 +                        return;
    3.18                      }
    3.19                  }
    3.20                  else
    3.21 @@ -146,7 +146,7 @@
    3.22  
    3.23          public MsgContainer Process(MsgContainer msgContainer)
    3.24          {
    3.25 -            PEPMessage mirrorMessage = null;
    3.26 +            bool createMirror = false;
    3.27              PEPMessage processedMessage = null;
    3.28              pEpRating processedRating;
    3.29              pEpDecryptFlags decryptionFlags;
    3.30 @@ -157,10 +157,10 @@
    3.31              {
    3.32                  processedMessageContainer = msgContainer.Copy();
    3.33  
    3.34 -                if ((msgContainer.IsInSecureStore) &&
    3.35 -                    (msgContainer.Mirror != null))
    3.36 +                if ((msgContainer.IsSecurelyStored) &&
    3.37 +                    (msgContainer.ProcessedMessage != null))
    3.38                  {
    3.39 -                    processedMessageContainer.Rating = AdapterExtensions.ReevaluateMessageRating(msgContainer.Mirror);
    3.40 +                    processedMessageContainer.Rating = AdapterExtensions.ReevaluateMessageRating(msgContainer.ProcessedMessage);
    3.41                  }
    3.42                  else
    3.43                  {
    3.44 @@ -174,21 +174,21 @@
    3.45                      }
    3.46  
    3.47                      // Define decryption flags
    3.48 -                    decryptionFlags = msgContainer.IsInSecureStore ? pEpDecryptFlags.pEpDecryptFlagUntrustedServer : pEpDecryptFlags.pEpDecryptFlagsNone;
    3.49 +                    decryptionFlags = msgContainer.IsSecurelyStored ? pEpDecryptFlags.pEpDecryptFlagUntrustedServer : pEpDecryptFlags.pEpDecryptFlagsNone;
    3.50                      PEPMessage message = msgContainer.Message;
    3.51  
    3.52                      sts = this.ProcessMessage(ref message,
    3.53                                                msgContainer.MessageCreationStatus,
    3.54 -                                              msgContainer.IsInSecureStore,
    3.55 +                                              msgContainer.IsOnUntrustedServer,
    3.56                                                msgContainer.IsInSentFolder,
    3.57                                                msgContainer.IsDraft,
    3.58 -                                              out mirrorMessage,
    3.59 +                                              out createMirror,
    3.60                                                out processedMessage,
    3.61                                                out processedRating,
    3.62                                                ref decryptionFlags);
    3.63  
    3.64 -                    if ((decryptionFlags == pEpDecryptFlags.pEpDecryptFlagConsume) ||
    3.65 -                        (decryptionFlags == pEpDecryptFlags.pEpDecryptFlagIgnore))
    3.66 +                    if ((decryptionFlags.HasFlag(pEpDecryptFlags.pEpDecryptFlagConsume)) ||
    3.67 +                        (decryptionFlags.HasFlag(pEpDecryptFlags.pEpDecryptFlagIgnore)))
    3.68                      {
    3.69                          Log.Verbose("MsgProcessor.Process: pEp internal message processed.");
    3.70                          return null;
    3.71 @@ -196,11 +196,19 @@
    3.72                      else
    3.73                      {
    3.74                          processedMessageContainer.DecryptionFlags = decryptionFlags;
    3.75 -                        processedMessageContainer.Message = (decryptionFlags.HasFlag(pEpDecryptFlags.pEpDecryptFlagSrcModified)) ? message : processedMessage;
    3.76 +                        processedMessageContainer.Message = message;
    3.77 +                        processedMessageContainer.MirrorCreated = createMirror;
    3.78 +                        processedMessageContainer.ProcessedMessage = processedMessage;
    3.79  
    3.80 -                        if (processedMessage != null)
    3.81 +                        if (processedMessageContainer.ProcessedMessage != null)
    3.82                          {
    3.83                              processedMessageContainer.Rating = processedRating;
    3.84 +
    3.85 +                            if (createMirror)
    3.86 +                            {
    3.87 +                                processedMessageContainer.MirrorCreated = true;
    3.88 +                                processedMessageContainer.MirrorCreationStatus = Globals.ReturnStatus.Success;
    3.89 +                            }
    3.90                          }
    3.91                          else
    3.92                          {
    3.93 @@ -214,13 +222,6 @@
    3.94                              }
    3.95                          }
    3.96  
    3.97 -                        if (mirrorMessage != null)
    3.98 -                        {
    3.99 -                            processedMessageContainer.Mirror = mirrorMessage;
   3.100 -                            processedMessageContainer.MirrorCreated = true;
   3.101 -                            processedMessageContainer.MirrorCreationStatus = Globals.ReturnStatus.Success;
   3.102 -                        }
   3.103 -
   3.104                          if (sts != Globals.ReturnStatus.Success)
   3.105                          {
   3.106                              processedMessageContainer.Error = new Exception(sts.ToString());
   3.107 @@ -239,7 +240,7 @@
   3.108          public void CompleteProcessing(MsgContainer msgContainer, object uiParent = null, bool updateUI = false)
   3.109          {
   3.110              Outlook.MailItem omi = null;
   3.111 -            bool applyToOmi = false;
   3.112 +            PEPMessage msgToApplyToOriginal = null;
   3.113  
   3.114              if (msgContainer != null)
   3.115              {
   3.116 @@ -271,6 +272,7 @@
   3.117                          if (string.IsNullOrEmpty(msgContainer.Message?.ForceProtectionId) == false)
   3.118                          {
   3.119                              PEPIdentity receivedBy = null;
   3.120 +
   3.121                              if (msgContainer.Message?.To?.Count == 1)
   3.122                              {
   3.123                                  receivedBy = msgContainer.Message.To[0];
   3.124 @@ -279,70 +281,69 @@
   3.125                              {
   3.126                                  receivedBy = msgContainer.Message.ReceivedBy;
   3.127                              }
   3.128 +
   3.129                              FPPMessage fppMessage = new FPPMessage(msgContainer.Message, receivedBy, msgContainer.EntryId);
   3.130                              fppMessage.ContinueProcessing();
   3.131                          }
   3.132 -                        // If in secure store, set mirror if available
   3.133 -                        else if (msgContainer.IsInSecureStore || (msgContainer.Message?.NeverUnsecure == true))
   3.134 +                        else if (msgContainer.ProcessedMessage != null)
   3.135                          {
   3.136 -                            if (msgContainer.Mirror != null)
   3.137 +                            if (msgContainer.IsSecurelyStored)
   3.138                              {
   3.139 -                                MsgProcessor.SetMirror(msgContainer);
   3.140 +                                MsgProcessor.SetMirror(msgContainer.ProcessedMessage, msgContainer.MirrorCreationStatus);
   3.141                              }
   3.142 -                            else if (msgContainer.Message != null)
   3.143 +                            else
   3.144                              {
   3.145 -                                applyToOmi = true;
   3.146 +                                msgToApplyToOriginal = msgContainer.ProcessedMessage;
   3.147                              }
   3.148                          }
   3.149 -                        // Else, apply to original mail item if needed
   3.150 -                        else if (msgContainer.Message != null)
   3.151 +
   3.152 +                        if (msgContainer.DecryptionFlags.HasFlag(pEpDecryptFlags.pEpDecryptFlagSrcModified))
   3.153                          {
   3.154 -                            applyToOmi = true;
   3.155 +                            msgToApplyToOriginal = msgContainer.Message;
   3.156                          }
   3.157  
   3.158                          // Apply to original mail item if necessary
   3.159 -                        if (applyToOmi)
   3.160 +                        if (msgToApplyToOriginal != null)
   3.161                          {
   3.162 -                            omi = Globals.ThisAddIn.Application.Session.GetItemFromID(msgContainer?.EntryId);
   3.163 +                            try
   3.164 +                            {
   3.165 +                                omi = Globals.ThisAddIn.Application.Session.GetItemFromID(msgContainer?.EntryId);
   3.166  
   3.167 -                            if (omi != null)
   3.168 -                            {
   3.169 -                                Globals.ReturnStatus status = Globals.ReturnStatus.Failure;
   3.170 -
   3.171 -                                try
   3.172 +                                if (omi != null)
   3.173                                  {
   3.174 -                                    status = msgContainer.Message?.ApplyTo(omi, true, false) ?? Globals.ReturnStatus.Failure;
   3.175 +                                    if (msgToApplyToOriginal.ApplyTo(omi, true, false,true, false) == Globals.ReturnStatus.Success)
   3.176 +                                    {
   3.177 +                                        omi.Save();
   3.178 +                                    }
   3.179                                  }
   3.180 -                                catch (Exception)
   3.181 +                                else
   3.182                                  {
   3.183 -
   3.184 -                                    status = Globals.ReturnStatus.Failure;
   3.185 -                                }
   3.186 -
   3.187 -                                if (status == Globals.ReturnStatus.Success)
   3.188 -                                {
   3.189 -                                    omi.Save();
   3.190 +                                    Log.Error("MsgProcessor.CompleteProcessing: Failure getting omi from entryId. "
   3.191 +                                              + ((string.IsNullOrEmpty(msgContainer.EntryId)) ? "EntryId null or empty." : ""));
   3.192                                  }
   3.193                              }
   3.194 -                            else
   3.195 +                            catch (Exception ex)
   3.196                              {
   3.197 -                                Log.Error("MsgProcessor.CompleteProcessing: Failure getting omi from entryId. "
   3.198 -                                          + ((string.IsNullOrEmpty(msgContainer.EntryId)) ? "EntryId null or empty." : ""));
   3.199 +                                Log.Error("CompleteProcessing: Error applying message. " + ex.ToString());
   3.200                              }
   3.201                          }
   3.202  
   3.203                          if (msgContainer.MirrorCreated)
   3.204                          {
   3.205 -                            omi = Globals.ThisAddIn.Application.Session.GetItemFromID(msgContainer?.EntryId);
   3.206 +                            try
   3.207 +                            {
   3.208 +                                omi = Globals.ThisAddIn.Application.Session.GetItemFromID(msgContainer?.EntryId);
   3.209 +                            }
   3.210 +                            catch (Exception ex)
   3.211 +                            {
   3.212 +                                omi = null;
   3.213 +                                Log.Error("CompleteProcessing: Error getting item from id. " + ex.ToString());
   3.214 +                            }
   3.215  
   3.216                              // Double check if mirror is not already there
   3.217                              if (omi != null)
   3.218                              {
   3.219 -                                var sw = new System.Diagnostics.Stopwatch();
   3.220 -                                sw.Restart();
   3.221                                  Outlook.MailItem mirrorItem = omi.GetMirror();
   3.222 -                                sw.Stop();
   3.223 -                                Log.Verbose(string.Format("MsgProcessor.CompleteProcessing: Looking up mirror took {0} ms. Was found: {1}.", sw.ElapsedMilliseconds, (mirrorItem != null).ToString()));
   3.224  
   3.225                                  if (mirrorItem == null)
   3.226                                  {
   3.227 @@ -352,7 +353,7 @@
   3.228                                      {
   3.229                                          try
   3.230                                          {
   3.231 -                                            msgContainer.Mirror.ApplyTo(mirrorItem, true, false);
   3.232 +                                            msgContainer.ProcessedMessage.ApplyTo(mirrorItem, true, false);
   3.233                                              mirrorItem.Save();
   3.234                                          }
   3.235                                          catch (Exception ex)
   3.236 @@ -510,12 +511,9 @@
   3.237          /// <param name="message">The original message to process. Can be returned modified (reencrypted). This will be
   3.238          /// signalled by the pEpDecryptFlagSrcModified flag.</param>
   3.239          /// <param name="messageCreationStatus">The return status after creating the message.</param>
   3.240 -        /// <param name="mirror">The existing mirror for the original message (if any).</param>
   3.241          /// <param name="isInSecureStore">Whether the message being processed is in a secure (untrusted) store.</param>
   3.242          /// <param name="isInSentFolder">Whether the message being processed in in a sent folder.</param>
   3.243          /// <param name="isDraft">Whether the message being processed is a draft.</param>
   3.244 -        /// <param name="outIsMirror">Whether the output data should be applied to a mirror (true) or the 
   3.245 -        /// original message (false).</param>
   3.246          /// <param name="outProcessedMessage">The processed message. This will contain any updated data for either 
   3.247          /// the original message or the mirror. Use the 'outIsMirror' pararameter to determine which.</param>
   3.248          /// <param name="outProcessedRating">The processed rating of the message.</param>
   3.249 @@ -526,7 +524,7 @@
   3.250                                                     bool isInSecureStore,
   3.251                                                     bool isInSentFolder,
   3.252                                                     bool isDraft,
   3.253 -                                                   out PEPMessage outMirror,
   3.254 +                                                   out bool createMirror,
   3.255                                                     out PEPMessage outProcessedMessage,
   3.256                                                     out pEpRating outProcessedRating,
   3.257                                                     ref pEpDecryptFlags decryptionFlags)
   3.258 @@ -535,7 +533,7 @@
   3.259              bool sentItem = false;
   3.260              string[] decryptionKeyList;
   3.261              PEPMessage processedMessage = null;
   3.262 -            PEPMessage mirror = null;
   3.263 +            createMirror = false;
   3.264              pEpRating processedRating = pEpRating.pEpRatingUndefined;
   3.265              pEpRating decryptionRating;
   3.266              Globals.ReturnStatus status = Globals.ReturnStatus.Success;
   3.267 @@ -614,7 +612,7 @@
   3.268                                  if (success)
   3.269                                  {
   3.270                                      Log.Verbose("ProcessMessage: Message successfully decrypted");
   3.271 -                                    mirror = processedMessage.Copy();
   3.272 +                                    createMirror = true;
   3.273                                      processedRating = decryptionRating;
   3.274                                  }
   3.275                                  else
   3.276 @@ -721,16 +719,7 @@
   3.277                      status = Globals.ReturnStatus.FailureNoConnection;
   3.278  
   3.279                      // Try to use the last stored rating, do no other processing
   3.280 -                    if ((isInSecureStore || message.NeverUnsecure) &&
   3.281 -                        (message.IsSecure) &&
   3.282 -                        (mirror != null))
   3.283 -                    {
   3.284 -                        processedRating = mirror.Rating; // Undefined if not already existing
   3.285 -                    }
   3.286 -                    else
   3.287 -                    {
   3.288 -                        processedRating = message.Rating; // Undefined if not already existing
   3.289 -                    }
   3.290 +                    processedRating = message.Rating; // Undefined if not already existing
   3.291                  }
   3.292                  else
   3.293                  {
   3.294 @@ -740,7 +729,6 @@
   3.295              }
   3.296  
   3.297              // Set outputs
   3.298 -            outMirror = mirror;
   3.299              outProcessedMessage = processedMessage;
   3.300              outProcessedRating = processedRating;
   3.301  
   3.302 @@ -1397,7 +1385,7 @@
   3.303                          (sourceMessage.ForceUnencrypted))
   3.304                      {
   3.305                          encFormat = pEpEncFormat.pEpEncNone;
   3.306 -                    }                   
   3.307 +                    }
   3.308  
   3.309                      ThisAddIn.PEPEngine.EncryptMessage(src, out dst, extraKeys, flags, encFormat);
   3.310                      success = true;
   3.311 @@ -1750,15 +1738,15 @@
   3.312          /// <summary>
   3.313          /// Displays the mirror message in the unencrypted preview.
   3.314          /// </summary>
   3.315 -        /// <param name="msgContainer">The message container that contains the mirror message.</param>
   3.316 -        public static void SetMirror(MsgContainer msgContainer)
   3.317 +        /// <param name="mirror">The mirror message.</param>
   3.318 +        /// <param name="mirrorCreationStatus">The mirror message creation status.</param>
   3.319 +        public static void SetMirror(PEPMessage mirror, Globals.ReturnStatus mirrorCreationStatus)
   3.320          {
   3.321              WindowFormRegionCollection formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
   3.322 -            PEPMessage mirror = msgContainer.Mirror;
   3.323  
   3.324              if (mirror == null)
   3.325              {
   3.326 -                if (msgContainer.MirrorCreationStatus == Globals.ReturnStatus.FailureNoConnection)
   3.327 +                if (mirrorCreationStatus == Globals.ReturnStatus.FailureNoConnection)
   3.328                  {
   3.329                      MsgProcessor.SetNote(Properties.Resources.Message_DecryptionNoConnection);
   3.330                      Log.Verbose("MailItem_GetMirrorComplete: Cannot display mirror, connection failure during decryption.");
     4.1 --- a/UI/HandshakeDialog.xaml.cs	Tue May 22 11:35:06 2018 +0200
     4.2 +++ b/UI/HandshakeDialog.xaml.cs	Tue May 22 15:36:37 2018 +0200
     4.3 @@ -555,8 +555,6 @@
     4.4          private void TrustIdentityKey(HandshakeItem handshakeItem)
     4.5          {
     4.6              if (string.IsNullOrEmpty(handshakeItem?.Partner?.Fingerprint) == false)
     4.7 -
     4.8 -
     4.9              {
    4.10                  pEpIdentity partnerIdentity = handshakeItem.Partner.ToCOMType();
    4.11  
    4.12 @@ -575,6 +573,7 @@
    4.13                  Log.Error("TrustIdentityKey: HandshakeItem, identity partner or fingerprint are null.");
    4.14              }
    4.15          }
    4.16 +
    4.17          /// <summary>
    4.18          /// Mistrusts the key that belongs to the identity that corresponds to the given HandshakeItem.
    4.19          /// </summary>
     5.1 --- a/UI/Ribbon/RibbonExtensions.cs	Tue May 22 11:35:06 2018 +0200
     5.2 +++ b/UI/Ribbon/RibbonExtensions.cs	Tue May 22 15:36:37 2018 +0200
     5.3 @@ -98,7 +98,7 @@
     5.4          /// </summary>
     5.5          public static string GetPEPButtonLabel(pEpRating rating)
     5.6          {
     5.7 -            return "Privacy Status";
     5.8 +            return Properties.Resources.PrivacyStatus_FormText;
     5.9          }
    5.10  
    5.11          /// <summary>
    5.12 @@ -140,8 +140,33 @@
    5.13                  // If mail item was successfully retrieved, build handshake dialog
    5.14                  if (omi != null)
    5.15                  {
    5.16 -                    // Create MsgContainer
    5.17 -                    if (PEPMessage.Create(omi, out message) != Globals.ReturnStatus.Success)
    5.18 +                    // If message is secure, use mirror
    5.19 +                    if (omi.GetIsSecure())
    5.20 +                    {
    5.21 +                        Outlook.MailItem mirror = null;
    5.22 +                        try
    5.23 +                        {
    5.24 +                            mirror = omi.GetMirror();
    5.25 +
    5.26 +                            if ((mirror == null) ||
    5.27 +                                (PEPMessage.Create(mirror, out message) != Globals.ReturnStatus.Success))
    5.28 +                            {
    5.29 +                                message = null;
    5.30 +                            }                                                    
    5.31 +                        }
    5.32 +                        catch (Exception ex)
    5.33 +                        {
    5.34 +                            Log.Error("pEpButton_Click: Error getting rating. " + ex.ToString());
    5.35 +                        }
    5.36 +                        finally
    5.37 +                        {
    5.38 +                            mirror = null;
    5.39 +                        }
    5.40 +                    }
    5.41 +
    5.42 +                    // If we have no message at this point, use OMI
    5.43 +                    if ((message == null) &&
    5.44 +                        (PEPMessage.Create(omi, out message) != Globals.ReturnStatus.Success))
    5.45                      {
    5.46                          throw new Exception("Error creating MsgContainer.");
    5.47                      }