Merge with default sync
authorThomas
Mon, 15 Apr 2019 08:49:51 +0200
branchsync
changeset 2614105311c70875
parent 2613 9b7775c64b39
parent 2612 d46de99a6317
child 2616 b9e529090877
Merge with default
Wrappers/WatchedWindow.cs
     1.1 --- a/CryptableMailItem.cs	Mon Apr 15 08:48:46 2019 +0200
     1.2 +++ b/CryptableMailItem.cs	Mon Apr 15 08:49:51 2019 +0200
     1.3 @@ -1683,6 +1683,7 @@
     1.4                  {
     1.5                      args.ProcessedRating = result.Rating;
     1.6                      args.PropertiesToSet = result.PropertiesToSet;
     1.7 +                    args.EntryId = this.internalMailItem?.EntryID;
     1.8                  }
     1.9                  else
    1.10                  {
     2.1 --- a/MsgProcessor.cs	Mon Apr 15 08:48:46 2019 +0200
     2.2 +++ b/MsgProcessor.cs	Mon Apr 15 08:49:51 2019 +0200
     2.3 @@ -83,7 +83,7 @@
     2.4                                  }));
     2.5                              }
     2.6                              else
     2.7 -                            {                                
     2.8 +                            {
     2.9                                  Log.Verbose("CheckForSyncMessage: Wizard not opened. Wizard was {0} open. Own fpr is {1}", ((KeySyncWizard.Wizard?.IsVisible == true) ? "already" : "not"), (myself?.Fingerprint ?? "<null>"));
    2.10                              }
    2.11                          }
    2.12 @@ -305,50 +305,18 @@
    2.13                              {
    2.14                                  /* Decrypt message. This is done to check if it's a beacon
    2.15                                   * message and to remove public keys attached to the message.
    2.16 -                                 * The processed message itself can be ignored.
    2.17 +                                 * If the source message has been changed during
    2.18 +                                 * decryption, this is possibly due to the removal of a key.
    2.19 +                                 * In this case, return the source message as processed message if
    2.20 +                                 * it hasn't been sent to myself (do not remove keys from unsecure 
    2.21 +                                 * messages sent to myself).
    2.22                                  */
    2.23 -                                this.Decrypt(ref message,
    2.24 -                                             out _,
    2.25 -                                             out decryptionKeyList,
    2.26 -                                             ref decryptionFlags);
    2.27 -                            }
    2.28 -
    2.29 -                            /* Check all unsecure messages that are not sent to myself
    2.30 -                             * for attached keys and remove them.
    2.31 -                             * Although this is also done in the engine during decryption,
    2.32 -                             * it seems safer to only apply the round-trip Outlook mail item
    2.33 -                             * => PEPMessage => Outlook mail item if really needed.
    2.34 -                             */
    2.35 -                            bool keyFound = false;
    2.36 -                            bool sentToMyself = false;
    2.37 -
    2.38 -                            for (int i = 0; i < message.Attachments?.Count; i++)
    2.39 -                            {
    2.40 -                                if (message.Attachments[i].IsKey)
    2.41 +                                if (this.Decrypt(ref message, out _, out _, ref decryptionFlags, out _) &&
    2.42 +                                    decryptionFlags.HasFlag(pEpDecryptFlags.pEpDecryptFlagSrcModified))
    2.43                                  {
    2.44 -                                    message.Attachments.Remove(message.Attachments[i]);
    2.45 -                                    keyFound = true;
    2.46 -                                    i--;
    2.47 +                                    processedMessage = message;
    2.48                                  }
    2.49                              }
    2.50 -
    2.51 -                            if (keyFound)
    2.52 -                            {
    2.53 -                                for (int i = 0; i < message.Recipients?.Length; i++)
    2.54 -                                {
    2.55 -                                    if (message.Recipients[i].EqualsByAddress(message.From))
    2.56 -                                    {
    2.57 -                                        sentToMyself = true;
    2.58 -                                        break;
    2.59 -                                    }
    2.60 -                                }
    2.61 -                            }
    2.62 -
    2.63 -                            // If a key was found and detached, return updated message
    2.64 -                            if (keyFound && (sentToMyself == false))
    2.65 -                            {
    2.66 -                                processedMessage = message;
    2.67 -                            }
    2.68                          }
    2.69                      }
    2.70                  }
    2.71 @@ -507,7 +475,6 @@
    2.72          /// <returns>True if decryption was considered successful, otherwise false.</returns>
    2.73          public bool Decrypt(PEPMessage sourceMessage)
    2.74          {
    2.75 -
    2.76              return this.Decrypt(sourceMessage, out _);
    2.77          }
    2.78  
    2.79 @@ -629,7 +596,33 @@
    2.80                      keyList = dstKeyList;
    2.81                  }
    2.82  
    2.83 -                // Replace original if needed
    2.84 +                /* If the source message's attachments count changes during decryption and it's not because
    2.85 +                 * the source has been reencrypted, there has probably been removed a key. In this case,
    2.86 +                 * check if message is sent to myself and if not, set modified source flag so that the
    2.87 +                 * modified source is returned.
    2.88 +                 */
    2.89 +                bool attachmentsCountChanged = (src.Attachments?.Length != sourceMessage.Attachments?.Count);
    2.90 +                if ((flags.HasFlag(pEpDecryptFlags.pEpDecryptFlagSrcModified) == false) &&
    2.91 +                    attachmentsCountChanged)
    2.92 +                {
    2.93 +                    bool sentToMyself = false;
    2.94 +                    for (int i = 0; i < sourceMessage.Recipients?.Length; i++)
    2.95 +                    {
    2.96 +                        if (sourceMessage.Recipients[i].EqualsByAddress(sourceMessage.From))
    2.97 +                        {
    2.98 +                            sentToMyself = true;
    2.99 +                            break;
   2.100 +                        }
   2.101 +                    }
   2.102 +
   2.103 +                    // If a key was found and detached, return updated message
   2.104 +                    if (sentToMyself == false)
   2.105 +                    {
   2.106 +                        flags |= pEpDecryptFlags.pEpDecryptFlagSrcModified;
   2.107 +                    }
   2.108 +                }
   2.109 +
   2.110 +                // Return modified source if necessary
   2.111                  if (flags.HasFlag(pEpDecryptFlags.pEpDecryptFlagSrcModified))
   2.112                  {
   2.113                      sts = PEPMessage.Create(src, out PEPMessage reencryptedMessage);
   2.114 @@ -897,6 +890,11 @@
   2.115          internal class ProcessingCompletedEventArgs : EventArgs
   2.116          {
   2.117              /// <summary>
   2.118 +            /// The entry id of the message that has been processed.
   2.119 +            /// </summary>
   2.120 +            public string EntryId;
   2.121 +
   2.122 +            /// <summary>
   2.123              /// Whether the ProcessedMessage corresponds to a mirror (true) or the original message (false).
   2.124              /// </summary>
   2.125              public bool IsMirror;
   2.126 @@ -932,6 +930,7 @@
   2.127              /// </summary>
   2.128              public ProcessingCompletedEventArgs()
   2.129              {
   2.130 +                this.EntryId = null;
   2.131                  this.IsMirror = false;
   2.132                  this.ProcessedDecryptionFlags = pEpDecryptFlags.pEpDecryptFlagsNone;
   2.133                  this.ProcessedMessage = null;
   2.134 @@ -946,6 +945,7 @@
   2.135              /// <param name="rating">The rating after the processing completes.</param>
   2.136              public ProcessingCompletedEventArgs(pEpRating rating)
   2.137              {
   2.138 +                this.EntryId = null;
   2.139                  this.IsMirror = false;
   2.140                  this.ProcessedDecryptionFlags = pEpDecryptFlags.pEpDecryptFlagsNone;
   2.141                  this.ProcessedMessage = null;
     3.1 --- a/Wrappers/WatchedWindow.cs	Mon Apr 15 08:48:46 2019 +0200
     3.2 +++ b/Wrappers/WatchedWindow.cs	Mon Apr 15 08:49:51 2019 +0200
     3.3 @@ -1042,6 +1042,13 @@
     3.4  
     3.5              try
     3.6              {
     3.7 +                // Make sure that the calculated result corresponds to the currently selected mail item
     3.8 +                if (e?.EntryId?.Equals(this.CurrentMailItem?.EntryID) != true)
     3.9 +                {
    3.10 +                    Log.Verbose("MailItem_ProcessingComplete: Calculated rating doesn't correspond to current mail item. Skipping...");
    3.11 +                    return;
    3.12 +                }
    3.13 +
    3.14                  // Marshal code back to UI thread as necessary
    3.15                  KeySyncWizard.Wizard.Dispatcher.Invoke(new Action(() =>
    3.16                  {