Merge with default Redesign_Ribbon
authorThomas
Fri, 08 Jun 2018 12:43:37 +0200
branchRedesign_Ribbon
changeset 22354ed3cbdcd122
parent 2232 d2a6cda25b83
parent 2234 45d69c611c73
Merge with default
CryptableMailItem.cs
DecryptionStack.cs
MsgProcessor.cs
PEPMessage.cs
ThisAddIn.cs
UI/KeySyncWizard.xaml.cs
     1.1 --- a/CryptableMailItem.cs	Thu Jun 07 11:37:46 2018 +0200
     1.2 +++ b/CryptableMailItem.cs	Fri Jun 08 12:43:37 2018 +0200
     1.3 @@ -776,20 +776,6 @@
     1.4          }
     1.5  
     1.6          /// <summary>
     1.7 -        /// Returns whether this cryptable mail item has BCC recipients or not
     1.8 -        /// </summary>
     1.9 -        public bool HasBCC
    1.10 -        {
    1.11 -            get
    1.12 -            {
    1.13 -                lock (mutexMailItem)
    1.14 -                {
    1.15 -                    return (string.IsNullOrEmpty(this.internalMailItem.BCC) == false);
    1.16 -                }
    1.17 -            }
    1.18 -        }
    1.19 -
    1.20 -        /// <summary>
    1.21          /// Gets or sets whether this cryptable mail item has already been sent.
    1.22          /// </summary>
    1.23          public bool HasBeenSent { get; set; } = false;
     2.1 --- a/DecryptionStack.cs	Thu Jun 07 11:37:46 2018 +0200
     2.2 +++ b/DecryptionStack.cs	Fri Jun 08 12:43:37 2018 +0200
     2.3 @@ -224,7 +224,7 @@
     2.4              // Try to increment the decryption counter
     2.5              if (this.IncrementDecryptionCounter() == false)
     2.6              {
     2.7 -                Log.Verbose("DecryptionStack.DecryptionTimer_Tick: decryption queue full");
     2.8 +                Log.Verbose("DecryptionStack.DecryptionTimer_Tick: decryption queue full. Items in queue: " + this.Count);
     2.9                  return;
    2.10              }
    2.11  
     3.1 --- a/MsgProcessor.cs	Thu Jun 07 11:37:46 2018 +0200
     3.2 +++ b/MsgProcessor.cs	Fri Jun 08 12:43:37 2018 +0200
     3.3 @@ -736,399 +736,61 @@
     3.4          }
     3.5  
     3.6          /// <summary>
     3.7 -        /// Processes the given PEP message mail item before sending.
     3.8 -        /// This will handle things like distribution lists, encryption, Bcc, etc.
     3.9 +        /// Processes the given PEP message mail item before sending. This will
    3.10 +        /// handle distribution lists and BCC.
    3.11          /// </summary>
    3.12 -        /// <param name="message">The original PEP message being sent.</param>
    3.13 -        /// <param name="isInSecureStore">Whether the PEP message being sent is in a secure (untrusted) store.</param>
    3.14 -        /// <param name="outMessages">The list of processed PEP messages.</param>
    3.15 -        /// <param name="outSavedSentMessage">The PEP message that should be saved in the sent folder.</param>
    3.16 -        /// <param name="outSavedSentMessageStoredRating">The pEp rating to be stored in the saved sent message.
    3.17 -        /// This is based on the original OutgoingRating. WARNING: Be careful about using this value externally on untrusted servers, 
    3.18 -        /// it should be saved to the mirror ONLY.</param>
    3.19 +        /// <param name="sourceMessage">The source message to process.</param>
    3.20 +        /// <param name="extraKeys">Any extra keys to encrypt the message for additionally.</param>
    3.21 +        /// <param name="processedMessage">The processed message.</param>
    3.22          /// <returns>The status of the method.</returns>
    3.23 -        public Globals.ReturnStatus ProcessSentMessage(PEPMessage message,
    3.24 -                                                       bool isInSecureStore,
    3.25 +        public Globals.ReturnStatus ProcessSentMessage(PEPMessage sourceMessage,
    3.26                                                         string[] extraKeys,
    3.27 -                                                       out PEPMessage[] outMessages,
    3.28 -                                                       out PEPMessage outSavedSentMessage,
    3.29 -                                                       out pEpRating outSavedSentMessageStoredRating)
    3.30 +                                                       out PEPMessage processedMessage)
    3.31          {
    3.32 -            PEPMessage[] encrypted;
    3.33 -            PEPMessage[] unencrypted;
    3.34 -            PEPMessage savedSentMessage;
    3.35 -            pEpRating savedSentMessageStoredRating;
    3.36 -            List<PEPMessage> result = new List<PEPMessage>();
    3.37 -            Globals.ReturnStatus status;
    3.38 +            Globals.ReturnStatus status = Globals.ReturnStatus.Failure;
    3.39 +            pEpEncFormat encFormat = pEpEncFormat.pEpEncPep;
    3.40  
    3.41 -            status = this.ProcessSentMessage(message,
    3.42 -                                             isInSecureStore,
    3.43 -                                             extraKeys,
    3.44 -                                             out encrypted,
    3.45 -                                             out unencrypted,
    3.46 -                                             out savedSentMessage,
    3.47 -                                             out savedSentMessageStoredRating);
    3.48 +            // Flatten recipients
    3.49 +            sourceMessage.FlattenAllRecipientIdentities();
    3.50  
    3.51 -            for (int i = 0; i < encrypted.Length; i++)
    3.52 +            // Add disclaimer if needed
    3.53 +            sourceMessage.AddDisclaimer();
    3.54 +
    3.55 +            /* Try to encrypt all messages except reader messages,
    3.56 +             * forcefully unencrypted messages and messages with BCC recipients.
    3.57 +             * If the message is a forcefully encrypted message, process it always.
    3.58 +             */
    3.59 +            if (((Globals.RELEASE_MODE == Globals.ReleaseMode.Reader) &&
    3.60 +                 (string.IsNullOrEmpty(sourceMessage.ForceProtectionId))) ||
    3.61 +                (sourceMessage.ForceUnencrypted) ||
    3.62 +                (sourceMessage.Bcc?.Count > 0))
    3.63              {
    3.64 -                result.Add(encrypted[i]);
    3.65 +                encFormat = pEpEncFormat.pEpEncNone;
    3.66              }
    3.67  
    3.68 -            for (int i = 0; i < unencrypted.Length; i++)
    3.69 +            // Process message
    3.70 +            if (this.Encrypt(sourceMessage, out processedMessage, extraKeys, pEpEncryptFlags.pEpEncryptFlagDefault, encFormat))
    3.71              {
    3.72 -                result.Add(unencrypted[i]);
    3.73 -            }
    3.74 -
    3.75 -            outMessages = result.ToArray();
    3.76 -            outSavedSentMessage = savedSentMessage;
    3.77 -            outSavedSentMessageStoredRating = savedSentMessageStoredRating;
    3.78 -
    3.79 -            return (status);
    3.80 -        }
    3.81 -
    3.82 -        /// <summary>
    3.83 -        /// Processes the given PEP message mail item before sending.
    3.84 -        /// This will handle things like distribution lists, encryption, Bcc, etc.
    3.85 -        /// </summary>
    3.86 -        /// <param name="message">The original PEP message being sent.</param>
    3.87 -        /// <param name="isInEncryptedStore">Whether the PEP message being sent is in an
    3.88 -        /// encrypted (untrusted) store or not.</param>
    3.89 -        /// <param name="outEncryptedMessages">The list of encrypted PEP messages to be sent.</param>
    3.90 -        /// <param name="outUnencryptedMessages">The list of unencrypted PEP messages to be sent.</param>
    3.91 -        /// <param name="outSavedSentMessage">The PEP message that should be saved in the sent folder.</param>
    3.92 -        /// <param name="outSavedSentMessageStoredRating">The pEp rating to be stored in the saved sent message.
    3.93 -        /// This is based on the original OutgoingRating. WARNING: Be careful about using this value externally on untrusted servers, 
    3.94 -        /// it should be saved to the mirror ONLY.</param>
    3.95 -        /// <returns>The status of the method.</returns>
    3.96 -        public Globals.ReturnStatus ProcessSentMessage(PEPMessage message,
    3.97 -                                                       bool isInEncryptedStore,
    3.98 -                                                       string[] extraKeys,
    3.99 -                                                       out PEPMessage[] outEncryptedMessages,
   3.100 -                                                       out PEPMessage[] outUnencryptedMessages,
   3.101 -                                                       out PEPMessage outSavedSentMessage,
   3.102 -                                                       out pEpRating outSavedSentMessageStoredRating)
   3.103 -        {
   3.104 -            bool result;
   3.105 -            pEpRating outgoingRating;
   3.106 -            PEPMessage newMessage;
   3.107 -            PEPMessage workingMessage = message.Copy();
   3.108 -            PEPMessage newEncryptedMessage = null;
   3.109 -            PEPMessage newUnencryptedMessage = null;
   3.110 -            PEPMessage savedSentMessage = null;
   3.111 -            pEpRating savedSentMessageStoredRating;
   3.112 -            List<PEPIdentity> bccUnencryptedGroup = new List<PEPIdentity>();
   3.113 -            List<PEPIdentity> bccEncryptedGroup = new List<PEPIdentity>();
   3.114 -            List<PEPMessage> unencryptedMessages = new List<PEPMessage>();
   3.115 -            List<PEPMessage> encryptedMessages = new List<PEPMessage>();
   3.116 -            List<PEPMessage> bccMessages = new List<PEPMessage>();
   3.117 -            Globals.ReturnStatus status = Globals.ReturnStatus.Success;
   3.118 -
   3.119 -            Log.Verbose("ProcessSentMessage: Started");
   3.120 -
   3.121 -            // Force the working message to outgoing direction.
   3.122 -            // This protects mostly for outgoing rating calculation which requires it.
   3.123 -            // However, if the message is ever incoming direction here, a failure occured elsewhere.
   3.124 -            if (workingMessage.Direction == pEpMsgDirection.pEpDirIncoming)
   3.125 -            {
   3.126 -                workingMessage.Direction = pEpMsgDirection.pEpDirOutgoing;
   3.127 -                Log.Warning("ProcessSentMessage: Message direction set to outgoing (was incorrectly incoming).");
   3.128 -            }
   3.129 -
   3.130 -            // Set stored sent message rating to outgoing rating
   3.131 -            // WARNING: Be careful about using this value externally on untrusted servers, it should be saved to the mirror ONLY.
   3.132 -            savedSentMessageStoredRating = this.GetOutgoingRating(workingMessage);
   3.133 -
   3.134 -            ///////////////////////////////////////////////////////////
   3.135 -            // Process HTML & Handle distribution lists
   3.136 -            //  This updates workingMessage
   3.137 -            ///////////////////////////////////////////////////////////
   3.138 -
   3.139 -            Log.Verbose("ProcessSentMessage: Flattening recipients.");
   3.140 -
   3.141 -            workingMessage.FlattenAllRecipientIdentities();
   3.142 -
   3.143 -            ///////////////////////////////////////////////////////////
   3.144 -            // Handle send unencrypted
   3.145 -            //  This uses the encrypted/unencrypted messages
   3.146 -            ///////////////////////////////////////////////////////////
   3.147 -
   3.148 -            Log.Verbose("ProcessSentMessage: Processing send unencrypted by identity.");
   3.149 -
   3.150 -            // Bcc
   3.151 -            for (int i = 0; i < workingMessage.Bcc.Count; i++)
   3.152 -            {
   3.153 -                if (workingMessage.Bcc[i].IsForceUnencryptedBool)
   3.154 -                {
   3.155 -                    if (newUnencryptedMessage == null)
   3.156 -                    {
   3.157 -                        newUnencryptedMessage = workingMessage.Copy();
   3.158 -                        newUnencryptedMessage.Bcc.Clear();
   3.159 -                        newUnencryptedMessage.Cc.Clear();
   3.160 -                        newUnencryptedMessage.To.Clear();
   3.161 -                    }
   3.162 -
   3.163 -                    newUnencryptedMessage.Bcc.Add(workingMessage.Bcc[i].Copy());
   3.164 -                }
   3.165 -                else
   3.166 -                {
   3.167 -                    if (newEncryptedMessage == null)
   3.168 -                    {
   3.169 -                        newEncryptedMessage = workingMessage.Copy();
   3.170 -                        newEncryptedMessage.Bcc.Clear();
   3.171 -                        newEncryptedMessage.Cc.Clear();
   3.172 -                        newEncryptedMessage.To.Clear();
   3.173 -                    }
   3.174 -
   3.175 -                    newEncryptedMessage.Bcc.Add(workingMessage.Bcc[i].Copy());
   3.176 -                }
   3.177 -            }
   3.178 -
   3.179 -            // Cc
   3.180 -            for (int i = 0; i < workingMessage.Cc.Count; i++)
   3.181 -            {
   3.182 -                if (workingMessage.Cc[i].IsForceUnencryptedBool)
   3.183 -                {
   3.184 -                    if (newUnencryptedMessage == null)
   3.185 -                    {
   3.186 -                        newUnencryptedMessage = workingMessage.Copy();
   3.187 -                        newUnencryptedMessage.Bcc.Clear();
   3.188 -                        newUnencryptedMessage.Cc.Clear();
   3.189 -                        newUnencryptedMessage.To.Clear();
   3.190 -                    }
   3.191 -
   3.192 -                    newUnencryptedMessage.Cc.Add(workingMessage.Cc[i].Copy());
   3.193 -                }
   3.194 -                else
   3.195 -                {
   3.196 -                    if (newEncryptedMessage == null)
   3.197 -                    {
   3.198 -                        newEncryptedMessage = workingMessage.Copy();
   3.199 -                        newEncryptedMessage.Bcc.Clear();
   3.200 -                        newEncryptedMessage.Cc.Clear();
   3.201 -                        newEncryptedMessage.To.Clear();
   3.202 -                    }
   3.203 -
   3.204 -                    newEncryptedMessage.Cc.Add(workingMessage.Cc[i].Copy());
   3.205 -                }
   3.206 -            }
   3.207 -
   3.208 -            // To
   3.209 -            for (int i = 0; i < workingMessage.To.Count; i++)
   3.210 -            {
   3.211 -                if (workingMessage.To[i].IsForceUnencryptedBool)
   3.212 -                {
   3.213 -                    if (newUnencryptedMessage == null)
   3.214 -                    {
   3.215 -                        newUnencryptedMessage = workingMessage.Copy();
   3.216 -                        newUnencryptedMessage.Bcc.Clear();
   3.217 -                        newUnencryptedMessage.Cc.Clear();
   3.218 -                        newUnencryptedMessage.To.Clear();
   3.219 -                    }
   3.220 -
   3.221 -                    newUnencryptedMessage.To.Add(workingMessage.To[i].Copy());
   3.222 -                }
   3.223 -                else
   3.224 -                {
   3.225 -                    if (newEncryptedMessage == null)
   3.226 -                    {
   3.227 -                        newEncryptedMessage = workingMessage.Copy();
   3.228 -                        newEncryptedMessage.Bcc.Clear();
   3.229 -                        newEncryptedMessage.Cc.Clear();
   3.230 -                        newEncryptedMessage.To.Clear();
   3.231 -                    }
   3.232 -
   3.233 -                    newEncryptedMessage.To.Add(workingMessage.To[i].Copy());
   3.234 -                }
   3.235 -            }
   3.236 -
   3.237 -            if (newUnencryptedMessage != null)
   3.238 -            {
   3.239 -                unencryptedMessages.Add(newUnencryptedMessage);
   3.240 -            }
   3.241 -
   3.242 -            if (newEncryptedMessage != null)
   3.243 -            {
   3.244 -                encryptedMessages.Add(newEncryptedMessage);
   3.245 -            }
   3.246 -
   3.247 -            ///////////////////////////////////////////////////////////
   3.248 -            // Handle Bcc
   3.249 -            //  This uses the encrypted messages
   3.250 -            ///////////////////////////////////////////////////////////
   3.251 -
   3.252 -            Log.Verbose("ProcessSentMessage: Processing Bcc");
   3.253 -
   3.254 -            // Remove any encrypted messages with Bcc for special processing
   3.255 -            for (int i = 0; i < encryptedMessages.Count; i++)
   3.256 -            {
   3.257 -                if ((encryptedMessages[i].Bcc != null) &&
   3.258 -                    (encryptedMessages[i].Bcc.Count > 0))
   3.259 -                {
   3.260 -                    bccMessages.Add(encryptedMessages[i]);
   3.261 -                    encryptedMessages.RemoveAt(i);
   3.262 -
   3.263 -                    // Reset index
   3.264 -                    i = -1;
   3.265 -                }
   3.266 -            }
   3.267 -
   3.268 -            // Process the Bcc messages
   3.269 -            for (int i = 0; i < bccMessages.Count; i++)
   3.270 -            {
   3.271 -                // First, add message without Bcc
   3.272 -                if ((bccMessages[i].Cc.Count > 0) ||
   3.273 -                    (bccMessages[i].To.Count > 0))
   3.274 -                {
   3.275 -                    newMessage = bccMessages[i].Copy();
   3.276 -                    newMessage.Bcc.Clear();
   3.277 -                    encryptedMessages.Add(newMessage);
   3.278 -                }
   3.279 -
   3.280 -                // Second, check each Bcc to see if it will receive an encrypted copy
   3.281 -                for (int j = 0; j < bccMessages[i].Bcc.Count; j++)
   3.282 -                {
   3.283 -                    newMessage = new PEPMessage();
   3.284 -                    newMessage.Direction = pEpMsgDirection.pEpDirOutgoing;
   3.285 -                    newMessage.From = bccMessages[i].From.Copy();
   3.286 -                    newMessage.To.Add(bccMessages[i].Bcc[j].Copy());
   3.287 -
   3.288 -                    // Calculate outgoing rating
   3.289 -                    outgoingRating = this.GetOutgoingRating(newMessage);
   3.290 -
   3.291 -                    // Group identities
   3.292 -                    if (outgoingRating >= pEpRating.pEpRatingReliable)
   3.293 -                    {
   3.294 -                        bccEncryptedGroup.Add(bccMessages[i].Bcc[j].Copy());
   3.295 -                    }
   3.296 -                    else
   3.297 -                    {
   3.298 -                        bccUnencryptedGroup.Add(bccMessages[i].Bcc[j].Copy());
   3.299 -                    }
   3.300 -                }
   3.301 -
   3.302 -                // Third, create individual mail items for encrypted Bcc
   3.303 -                for (int j = 0; j < bccEncryptedGroup.Count; j++)
   3.304 -                {
   3.305 -                    // New mail for each encrypted Bcc recipient
   3.306 -                    newMessage = bccMessages[i].Copy();
   3.307 -                    newMessage.Bcc.Clear();
   3.308 -                    newMessage.Cc.Clear();
   3.309 -                    newMessage.To.Clear();
   3.310 -
   3.311 -                    newMessage.Bcc.Add(bccEncryptedGroup[j]);
   3.312 -
   3.313 -                    encryptedMessages.Add(newMessage);
   3.314 -                }
   3.315 -
   3.316 -                // Fourth, create single mail item for unencrypted Bcc
   3.317 -                if (bccUnencryptedGroup.Count > 0)
   3.318 -                {
   3.319 -                    // Look for existing unencrypted email to use (there should always be only one of these)
   3.320 -                    if (unencryptedMessages.Count > 0)
   3.321 -                    {
   3.322 -                        newMessage = unencryptedMessages[0];
   3.323 -                    }
   3.324 -                    else
   3.325 -                    {
   3.326 -                        newMessage = bccMessages[i].Copy();
   3.327 -                        newMessage.Bcc.Clear();
   3.328 -                        newMessage.Cc.Clear();
   3.329 -                        newMessage.To.Clear();
   3.330 -                        unencryptedMessages.Add(newMessage);
   3.331 -                    }
   3.332 -
   3.333 -                    for (int j = 0; j < bccUnencryptedGroup.Count; j++)
   3.334 -                    {
   3.335 -                        newMessage.Bcc.Add(bccUnencryptedGroup[j]);
   3.336 -                    }
   3.337 -                }
   3.338 -            }
   3.339 -
   3.340 -            ///////////////////////////////////////////////////////////
   3.341 -            // Encrypt
   3.342 -            ///////////////////////////////////////////////////////////
   3.343 -
   3.344 -            Log.Verbose("ProcessSentMessage: Encrypting messages, count=" + encryptedMessages.Count.ToString());
   3.345 -
   3.346 -            for (int i = 0; i < encryptedMessages.Count; i++)
   3.347 -            {
   3.348 -                try
   3.349 -                {
   3.350 -                    // Get the new outgoing pEp rating since the message may have been modified during processing.
   3.351 -                    // This will be used to ensure the encrypt result is actually encrypted when it says it is.
   3.352 -                    outgoingRating = encryptedMessages[i].OutgoingRating;
   3.353 -
   3.354 -                    // Add disclaimer if needed
   3.355 -                    encryptedMessages[i].AddDisclaimer(outgoingRating);
   3.356 -
   3.357 -                    result = this.Encrypt(encryptedMessages[i], extraKeys, out newMessage);
   3.358 -                    encryptedMessages[i] = newMessage;
   3.359 -
   3.360 -                    /* Check to ensure the message was really encrypted.
   3.361 -                     * This is just a double check against presenting the user with one rating, but actually delivering another.
   3.362 -                     * If message is unencrypted (and no forcefully encrypted message), an error occured elsewhere, likely in the engine.
   3.363 -                     */
   3.364 -                    if ((result == false) ||
   3.365 -                        ((outgoingRating >= pEpRating.pEpRatingReliable) &&
   3.366 -                         ((newMessage.IsSecure == false) && string.IsNullOrEmpty(newMessage.ForceProtectionId))))
   3.367 -                    {
   3.368 -                        status = Globals.ReturnStatus.Failure;
   3.369 -                        Log.Error("ProcessSentMessage: Message encryption failed or doesn't match outgoing rating.");
   3.370 -                    }
   3.371 -                }
   3.372 -                catch (Exception ex)
   3.373 -                {
   3.374 -                    status = Globals.ReturnStatus.Failure;
   3.375 -                    Log.Error("ProcessSentMessage: Message encryption failed, " + ex.ToString());
   3.376 -                }
   3.377 -            }
   3.378 -
   3.379 -            ///////////////////////////////////////////////////////////
   3.380 -            // Create the saved sent message
   3.381 -            ///////////////////////////////////////////////////////////
   3.382 -
   3.383 -            Log.Verbose("ProcessSentMessage: Creating saved sent message.");
   3.384 -
   3.385 -            if (isInEncryptedStore)
   3.386 -            {
   3.387 -                if ((encryptedMessages.Count == 1) &&
   3.388 -                    (unencryptedMessages.Count == 0))
   3.389 -                {
   3.390 -                    // Use what is already encrypted
   3.391 -                    savedSentMessage = encryptedMessages[0].Copy();
   3.392 -                }
   3.393 -                else
   3.394 -                {
   3.395 -                    /* Note: Use the original message before processing to ensure it appears to the user
   3.396 -                     * the same as it was first composed. This is especially important for recipients.
   3.397 -                     */
   3.398 -                    workingMessage = message.Copy();
   3.399 -
   3.400 -                    result = this.Encrypt(workingMessage, extraKeys, out savedSentMessage);
   3.401 -
   3.402 -                    if (result == false)
   3.403 -                    {
   3.404 -                        status = Globals.ReturnStatus.Failure;
   3.405 -                        Log.Error("ProcessSentMessage: Encryption of saved sent message failed.");
   3.406 -                    }
   3.407 -                }
   3.408 +                Log.Verbose("ProcessSentMessage: Source message successfully encrypted.");
   3.409 +                status = Globals.ReturnStatus.Success;
   3.410              }
   3.411              else
   3.412              {
   3.413 -                savedSentMessage = message.Copy();
   3.414 +                processedMessage = null;
   3.415 +                status = Globals.ReturnStatus.Failure;
   3.416 +                Log.Error("ProcessSentMessage: Error encrypting source message.");
   3.417              }
   3.418  
   3.419 -            outEncryptedMessages = encryptedMessages.ToArray();
   3.420 -            outUnencryptedMessages = unencryptedMessages.ToArray();
   3.421 -            outSavedSentMessage = savedSentMessage;
   3.422 -            outSavedSentMessageStoredRating = savedSentMessageStoredRating;
   3.423 +            // Check that message is encrypted if outgoing rating was reliable or more
   3.424 +            if ((processedMessage == null) ||
   3.425 +                ((sourceMessage.OutgoingRating >= pEpRating.pEpRatingReliable) &&
   3.426 +                ((processedMessage.IsSecure == false) && string.IsNullOrEmpty(processedMessage.ForceProtectionId))))
   3.427 +            {
   3.428 +                status = Globals.ReturnStatus.Failure;
   3.429 +                Log.Error("ProcessSentMessage: Message encryption failed or doesn't match outgoing rating.");
   3.430 +            }
   3.431  
   3.432 -            Log.Verbose("ProcessSentMessage: Encrypted Count=" + outEncryptedMessages.Length.ToString() +
   3.433 -                        " Unencrypted Count=" + outUnencryptedMessages.Length.ToString());
   3.434 -            Log.Verbose("ProcessSentMessage: Completed.");
   3.435 -
   3.436 -            Log.Verbose("ProcessSentMessage: ReturnStatus=" + status.ToString());
   3.437 -            return (status);
   3.438 +            return status;
   3.439          }
   3.440  
   3.441          /// <summary>
   3.442 @@ -1338,23 +1000,10 @@
   3.443          /// <param name="destMessage">The output encrypted message.</param>
   3.444          /// <returns>True if successful, otherwise false.</returns>
   3.445          public bool Encrypt(PEPMessage sourceMessage,
   3.446 +                            out PEPMessage destMessage,
   3.447                              string[] extraKeys,
   3.448 -                            out PEPMessage destMessage)
   3.449 -        {
   3.450 -            return Encrypt(sourceMessage, extraKeys, 0, out destMessage);
   3.451 -        }
   3.452 -
   3.453 -        /// <summary>
   3.454 -        /// Encrypts the given PEPMessage.
   3.455 -        /// </summary>
   3.456 -        /// <param name="sourceMessage">The message to encrypt.</param>
   3.457 -        /// <param name="extraKeys">Any extra keys to encrypt the message with.</param>
   3.458 -        /// <param name="destMessage">The output encrypted message.</param>
   3.459 -        /// <returns>True if successful, otherwise false.</returns>
   3.460 -        public bool Encrypt(PEPMessage sourceMessage,
   3.461 -                            string[] extraKeys,
   3.462 -                            pEpEncryptFlags flags,
   3.463 -                            out PEPMessage destMessage)
   3.464 +                            pEpEncryptFlags flags = pEpEncryptFlags.pEpEncryptFlagDefault,
   3.465 +                            pEpEncFormat encFormat = pEpEncFormat.pEpEncPep)
   3.466          {
   3.467              bool success = false;
   3.468              TextMessage src;
   3.469 @@ -1376,18 +1025,6 @@
   3.470                          src.Sent = DateTime.Now.ToFileTimeUtc();
   3.471                      }
   3.472  
   3.473 -                    /* Try to encrypt all messages except reader messages and 
   3.474 -                     * forcefully unencrypted messages.
   3.475 -                     * If the message is a forcefully encrypted message, process it always.
   3.476 -                     */
   3.477 -                    pEpEncFormat encFormat = pEpEncFormat.pEpEncPep;
   3.478 -                    if (((Globals.RELEASE_MODE == Globals.ReleaseMode.Reader) &&
   3.479 -                         (string.IsNullOrEmpty(sourceMessage.ForceProtectionId))) ||
   3.480 -                        (sourceMessage.ForceUnencrypted))
   3.481 -                    {
   3.482 -                        encFormat = pEpEncFormat.pEpEncNone;
   3.483 -                    }
   3.484 -
   3.485                      ThisAddIn.PEPEngine.EncryptMessage(src, out dst, extraKeys, flags, encFormat);
   3.486                      success = true;
   3.487                  }
   3.488 @@ -1432,8 +1069,8 @@
   3.489          /// <param name="encryptionFormat">The encryption format.</param>
   3.490          /// <returns>True if successful, otherwise false.</returns>
   3.491          public bool EncryptAndAddPrivateKey(PEPMessage sourceMessage,
   3.492 +                                            out PEPMessage destMessage,
   3.493                                              string toFingerprint,
   3.494 -                                            out PEPMessage destMessage,
   3.495                                              pEpEncryptFlags flags = pEpEncryptFlags.pEpEncryptFlagDefault,
   3.496                                              pEpEncFormat encryptionFormat = pEpEncFormat.pEpEncPep)
   3.497          {
     4.1 --- a/PEPMessage.cs	Thu Jun 07 11:37:46 2018 +0200
     4.2 +++ b/PEPMessage.cs	Fri Jun 08 12:43:37 2018 +0200
     4.3 @@ -463,7 +463,13 @@
     4.4                  // If reader mode, always unencrypted
     4.5                  rating = pEpRating.pEpRatingUnencrypted;
     4.6  #else
     4.7 -                if (this.ForceUnencrypted)
     4.8 +                /* If message is forcefully unencrypted or has BCC recipients,
     4.9 +                 * always return Unencrypted.
    4.10 +                 * If message is forcefully encrypted, return Reliable.
    4.11 +                 * Else, calculate through engine.
    4.12 +                 */ 
    4.13 +                if ((this.ForceUnencrypted) ||
    4.14 +                    (this.Bcc?.Count > 0))
    4.15                  {
    4.16                      rating = pEpRating.pEpRatingUnencrypted;
    4.17                  }
    4.18 @@ -473,7 +479,7 @@
    4.19                  }
    4.20                  else
    4.21                  {
    4.22 -                    PEPMessage workingMessage = this.Copy();
    4.23 +                    PEPMessage workingMessage = this.Copy(true);
    4.24                      workingMessage.FlattenAllRecipientIdentities();
    4.25                      workingMessage.Direction = pEpMsgDirection.pEpDirOutgoing;
    4.26  
    4.27 @@ -1848,10 +1854,10 @@
    4.28                       * Therefore, it is sent to a single zero byte to be constant.
    4.29                       * The RTFBody is ignored when sending the actual message.
    4.30                       */
    4.31 -                    omi.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
    4.32                      omi.Body = null;
    4.33                      omi.HTMLBody = null;
    4.34                      omi.RTFBody = new byte[] { 0x00 };
    4.35 +                    omi.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
    4.36  
    4.37                      // Now, set the mail mime type to S/MIME multipart/signed, this is used later to add a special attachment
    4.38                      try
    4.39 @@ -2215,8 +2221,7 @@
    4.40          /// save the mail item after adding a disclaimer, it's the caller's responsibility
    4.41          /// to save if necessary.
    4.42          /// </summary>
    4.43 -        /// <param name="outgoingRating">The outgoing rating for this message.</param>
    4.44 -        public void AddDisclaimer(pEpRating outgoingRating)
    4.45 +        public void AddDisclaimer()
    4.46          {
    4.47              // We only add disclaimers to outgoing messages
    4.48              if (this.Direction == pEpMsgDirection.pEpDirOutgoing)
    4.49 @@ -2232,7 +2237,7 @@
    4.50                       *        at least reliable.
    4.51                       */
    4.52                      if ((accountSettings?.AddDisclaimer == PEPSettings.Disclaimer.AllMessages) ||
    4.53 -                        ((accountSettings?.AddDisclaimer == PEPSettings.Disclaimer.OnlyEncryptedMessages) && outgoingRating >= pEpRating.pEpRatingReliable))
    4.54 +                        ((accountSettings?.AddDisclaimer == PEPSettings.Disclaimer.OnlyEncryptedMessages) && this.OutgoingRating >= pEpRating.pEpRatingReliable))
    4.55                      {
    4.56                          // Add to plain text
    4.57                          if (string.IsNullOrEmpty(this._LongMsg) == false)
     5.1 --- a/ThisAddIn.cs	Thu Jun 07 11:37:46 2018 +0200
     5.2 +++ b/ThisAddIn.cs	Fri Jun 08 12:43:37 2018 +0200
     5.3 @@ -3448,324 +3448,51 @@
     5.4  
     5.5                      if (processMessage)
     5.6                      {
     5.7 -                        bool isInSecureStore;
     5.8                          string sendUnencryptedWarning = Properties.Resources.Message_SendError + Environment.NewLine + Environment.NewLine + Properties.Resources.Message_SendUnencryptedConfirmation;
     5.9                          DialogResult result;
    5.10 -                        Outlook.Account sendingAccount = null;
    5.11 -                        Outlook.Store sendingStore = null;
    5.12 -                        Outlook.MailItem inlineItem = null;
    5.13 -                        Outlook.Inspector insp;
    5.14 -                        Outlook.Explorer exp = null;
    5.15                          MsgProcessor processor;
    5.16 -                        PEPMessage sentMessage;
    5.17 -                        PEPMessage[] messages;
    5.18 -                        PEPMessage savedSentMessage;
    5.19 -                        pEpRating savedSentMessageStoredRating;
    5.20 -                        Globals.ReturnStatus createSts;
    5.21 -                        Globals.ReturnStatus processSts;
    5.22 +                        PEPMessage message;
    5.23 +                        Globals.ReturnStatus status;
    5.24  
    5.25                          try
    5.26                          {
    5.27 -                            // Encrypt unless the mail has BCC recipients
    5.28 -                            if (string.IsNullOrEmpty(omi.BCC))
    5.29 +                            Log.Verbose("Application_ItemSend: Starting encryption and message processing.");
    5.30 +
    5.31 +                            status = PEPMessage.Create(omi, out message);
    5.32 +                            if (status == Globals.ReturnStatus.Success)
    5.33                              {
    5.34 -                                Log.Verbose("Application_ItemSend: Starting encryption and message processing.");
    5.35 -
    5.36 -                                createSts = PEPMessage.Create(omi, out sentMessage);
    5.37 -                                isInSecureStore = omi.GetIsInSecureStore();
    5.38 -
    5.39 -                                if (createSts == Globals.ReturnStatus.Success)
    5.40 +                                PEPMessage processedMessage;
    5.41 +                                processor = new MsgProcessor();
    5.42 +                                if (processor.ProcessSentMessage(message, Globals.ThisAddIn.Settings.ExtraKeys, out processedMessage) != Globals.ReturnStatus.Success)
    5.43                                  {
    5.44 -                                    processor = new MsgProcessor();
    5.45 -                                    processSts = processor.ProcessSentMessage(sentMessage,
    5.46 -                                                                              isInSecureStore,
    5.47 -                                                                              this.Settings.ExtraKeys,
    5.48 -                                                                              out messages,
    5.49 -                                                                              out savedSentMessage,
    5.50 -                                                                              out savedSentMessageStoredRating);
    5.51 -
    5.52 -                                    // Importantly, check for processing failure before continuing
    5.53 -                                    if (processSts != Globals.ReturnStatus.Success)
    5.54 -                                    {
    5.55 -                                        throw (new Exception("Failed while processing the sent message."));
    5.56 -                                    }
    5.57 -
    5.58 -                                    if (messages.Length == 1)
    5.59 -                                    {
    5.60 -                                        Log.Verbose("Application_ItemSend: Applying to original mail item for send.");
    5.61 -
    5.62 -                                        /* If the processor produces only one message, it can be applied to and sent with
    5.63 -                                         * the original Outlook MailItem. This allows outlook to do all the standard processing for
    5.64 -                                         * send which greatly reduces the number of possible failure points.
    5.65 -                                         * 
    5.66 -                                         * If a failure occurs, the original mail item is applied back to the Outlook mail item
    5.67 -                                         * and an error dialog enables the user to send the message unencrypted. We currently 
    5.68 -                                         * differentiate between generic errors and the specific error where the unencrypted message
    5.69 -                                         * size is below the allowable limit, but the PGP/MIME encrypted one exceeds it.
    5.70 -                                         * 
    5.71 -                                         * Notes:
    5.72 -                                         * Do NOT include internal Header Fields (MAPI properties) on outgoing messages!
    5.73 -                                         * The sender does not need to be set as the encrypted content is applied to the original
    5.74 -                                         * MailItem (setSender=false)
    5.75 -                                         */
    5.76 -                                        try
    5.77 -                                        {
    5.78 -                                            messages[0].ApplyTo(omi, false, false, false);
    5.79 -
    5.80 -                                            if (messages[0].IsSecure == false)
    5.81 -                                            {
    5.82 -                                                // Avoid creation of 'winmail.dat' attachment
    5.83 -                                                omi.AvoidWinmailDatAttachment();
    5.84 -                                            }
    5.85 -                                        }
    5.86 -                                        catch (AttachmentSizeException ex)
    5.87 -                                        {
    5.88 -                                            // Adjust warning message for this concrete case
    5.89 -                                            sendUnencryptedWarning = Properties.Resources.Message_SendErrorAttachmentSize + Environment.NewLine + Environment.NewLine + Properties.Resources.Message_SendUnencryptedConfirmation;
    5.90 -                                            Log.Verbose("Application_ItemSend: Error with attachments while applying encrypted message. " + ex.ToString());
    5.91 -                                            sentMessage.ApplyTo(omi, false, false);
    5.92 -                                            throw;
    5.93 -                                        }
    5.94 -                                        catch (Exception ex)
    5.95 -                                        {
    5.96 -                                            Log.Verbose("Application_ItemSend: Error applying encrypted message. " + ex.ToString());
    5.97 -                                            sentMessage.ApplyTo(omi, false, false);
    5.98 -                                            throw;
    5.99 -                                        }
   5.100 -                                    }
   5.101 -                                    else
   5.102 -                                    {
   5.103 -                                        // Create and send individual processed messages
   5.104 -                                        Log.Verbose("Application_ItemSend: Sending message(s).");
   5.105 -                                        for (int i = 0; i < messages.Length; i++)
   5.106 -                                        {
   5.107 -                                            /* Send the messages directly and catch errors the same way as in case of
   5.108 -                                             * only one message being applied directly (see above).                                      
   5.109 -                                             */
   5.110 -                                            try
   5.111 -                                            {
   5.112 -                                                this.CreateAndSendMessage(messages[i], true, false);
   5.113 -
   5.114 -                                                if (messages[i].IsSecure == false)
   5.115 -                                                {
   5.116 -                                                    // Avoid creation of 'winmail.dat' attachment
   5.117 -                                                    omi.AvoidWinmailDatAttachment();
   5.118 -                                                }
   5.119 -                                            }
   5.120 -                                            catch (AttachmentSizeException ex)
   5.121 -                                            {
   5.122 -                                                // Adjust warning message for this concrete case
   5.123 -                                                sendUnencryptedWarning = Properties.Resources.Message_SendErrorAttachmentSize + Environment.NewLine + Environment.NewLine + Properties.Resources.Message_SendUnencryptedConfirmation;
   5.124 -                                                Log.Verbose("Application_ItemSend: Error with attachments while sending encrypted message. " + ex.ToString());
   5.125 -                                                throw;
   5.126 -                                            }
   5.127 -                                            catch (Exception ex)
   5.128 -                                            {
   5.129 -                                                Log.Verbose("Application_ItemSend: Error sending encrypted message. " + ex.ToString());
   5.130 -                                                throw;
   5.131 -                                            }
   5.132 -                                        }
   5.133 -
   5.134 -                                        // Save the sent message
   5.135 -                                        Log.Verbose("Application_ItemSend: Saving sent message.");
   5.136 -                                        try
   5.137 -                                        {
   5.138 -                                            sendingAccount = omi.SendUsingAccount;
   5.139 -
   5.140 -                                            /* Note: Do not save the sent message for ActiveSync accounts which are handled specially.
   5.141 -                                             * Outlook/ActiveSync specification doesn't allow the necessary manual control.
   5.142 -                                             * Alternatively ActiveSync sent folders are monitored for new sent items then decrypted as needed.
   5.143 -                                             */
   5.144 -                                            if (sendingAccount.AccountType != Outlook.OlAccountType.olEas)
   5.145 -                                            {
   5.146 -                                                // Getting delivery store can fail for new accounts when Outlook is not restarted
   5.147 -                                                try
   5.148 -                                                {
   5.149 -                                                    sendingStore = sendingAccount.DeliveryStore;
   5.150 -                                                }
   5.151 -                                                catch
   5.152 -                                                {
   5.153 -                                                    sendingStore = null;
   5.154 -                                                    Log.Warning("Application_ItemSend: Failure getting DeliveryStore to save sent message.");
   5.155 -                                                }
   5.156 -
   5.157 -                                                //Get sending account settings
   5.158 -                                                var acctSettings = this._Settings.GetAccountSettings(sendingAccount.SmtpAddress);
   5.159 -
   5.160 -                                                if (acctSettings == null)
   5.161 -                                                {
   5.162 -                                                    acctSettings = new PEPSettings.PEPAccountSettings
   5.163 -                                                    {
   5.164 -                                                        SmtpAddress = sendingAccount.SmtpAddress,
   5.165 -                                                        Type = sendingAccount.AccountType.ToString()
   5.166 -                                                    };
   5.167 -                                                    this._Settings.AccountSettingsList.Add(acctSettings);
   5.168 -                                                }
   5.169 -
   5.170 -                                                /* Create the actual mailitem in the sent folder.
   5.171 -                                                 * It's important to note the following about the rating:
   5.172 -                                                 *   - Rating is generated from the Outgoing rating in the msg processor
   5.173 -                                                 *   - This rating should be used in the future when showing the message in the UI
   5.174 -                                                 *     Therefore it should be stored and the decrypt methods know to look for it.
   5.175 -                                                 *   - However! Since a mirror does not exist at this point, the rating MUST NOT BE SAVED
   5.176 -                                                 *     on an untrusted server
   5.177 -                                                 *   - Set rating to undefined in CreateNewSentMail() to avoid setting the property.
   5.178 -                                                 *   - If a rating is not stored here (it's an encrypted store, ActiveSync account, etc.), 
   5.179 -                                                 *     decrypt will recalculate it when next shown in the UI.
   5.180 -                                                 *     It will then simply be whatever the latest OutgoingRating is.
   5.181 -                                                 *     It's stored at this point so will always be this in the future (unless the mailitem is moved between folders)
   5.182 -                                                 */
   5.183 -                                                if (isInSecureStore)
   5.184 -                                                {
   5.185 -                                                    // Do not store rating
   5.186 -                                                    savedSentMessageStoredRating = pEpRating.pEpRatingUndefined;
   5.187 -                                                }
   5.188 -
   5.189 -                                                this.CreateNewSentMail(sendingStore,
   5.190 -                                                                       acctSettings,
   5.191 -                                                                       savedSentMessage,
   5.192 -                                                                       savedSentMessageStoredRating);
   5.193 -                                            }
   5.194 -                                        }
   5.195 -                                        catch (Exception ex)
   5.196 -                                        {
   5.197 -                                            Log.Error("Application_ItemSend: Failed to create sent mail item, " + ex.ToString());
   5.198 -                                        }
   5.199 -                                        finally
   5.200 -                                        {
   5.201 -                                            if (sendingAccount != null)
   5.202 -                                            {
   5.203 -                                                //Marshal.ReleaseComObject(sendingAccount);
   5.204 -                                                sendingAccount = null;
   5.205 -                                            }
   5.206 -
   5.207 -                                            if (sendingStore != null)
   5.208 -                                            {
   5.209 -                                                //Marshal.ReleaseComObject(sendingStore);
   5.210 -                                                sendingStore = null;
   5.211 -                                            }
   5.212 -                                        }
   5.213 -
   5.214 -                                        // Don't send the original message
   5.215 -                                        // At this point everything related to sending is complete so the original send can be cancelled
   5.216 -                                        cancel = true;
   5.217 -
   5.218 -                                        // Close inspector/window
   5.219 -                                        Log.Verbose("Application_ItemSend: Closing inspector and deleting original message.");
   5.220 -                                        insp = Application.ActiveInspector();
   5.221 -                                        if (insp != null)
   5.222 -                                        {
   5.223 -                                            ((Outlook._Inspector)insp).Close(Outlook.OlInspectorClose.olDiscard);
   5.224 -                                            // Marshal.ReleaseComObject(insp);
   5.225 -                                            insp = null;
   5.226 -                                        }
   5.227 -                                        else
   5.228 -                                        {
   5.229 -                                            /* Close in-line response
   5.230 -                                             * 
   5.231 -                                             * The in-line response has a limited API and cannot be closed directly.
   5.232 -                                             * It is also not easy to call .Close on the ActiveInlineResponse MailItem.
   5.233 -                                             * This is because .Close can't be called during send, and after send the MailItem 
   5.234 -                                             * is moved and the reference is lost. It may be possible to search by store/item ID then
   5.235 -                                             * call .Close but it's complicated.
   5.236 -                                             * 
   5.237 -                                             * Therefore, there are two simpler work-arounds:
   5.238 -                                             *  (1) Calling clear selection on the explorer which removes any draft being displayed.
   5.239 -                                             *      However, this does not work in conversation view for some reason, so...
   5.240 -                                             *  (2) Pop-out the ActiveInlineResponse item by calling .Display on it.
   5.241 -                                             *      Then closing it as an inspector.
   5.242 -                                             */
   5.243 -                                            exp = Application.ActiveExplorer();
   5.244 -                                            if (exp != null)
   5.245 -                                            {
   5.246 -                                                try
   5.247 -                                                {
   5.248 -                                                    // Warning: this does not work in conversation view
   5.249 -                                                    ((Outlook._Explorer)exp).ClearSelection();
   5.250 -                                                }
   5.251 -                                                catch
   5.252 -                                                {
   5.253 -                                                    try
   5.254 -                                                    {
   5.255 -                                                        // Pull the item out of the in-line response
   5.256 -                                                        // Note: it will be closed automatically when delete is called on the draft
   5.257 -                                                        inlineItem = ((Outlook.MailItem)((Outlook._Explorer)exp).ActiveInlineResponse);
   5.258 -                                                        ((Outlook._MailItem)inlineItem).Display();
   5.259 -                                                    }
   5.260 -                                                    catch { }
   5.261 -                                                    finally
   5.262 -                                                    {
   5.263 -                                                        if (inlineItem != null)
   5.264 -                                                        {
   5.265 -                                                            // Marshal.ReleaseComObject(inlineItem);
   5.266 -                                                            inlineItem = null;
   5.267 -                                                        }
   5.268 -                                                    }
   5.269 -                                                }
   5.270 -
   5.271 -                                                // Marshal.ReleaseComObject(exp);
   5.272 -                                                exp = null;
   5.273 -                                            }
   5.274 -                                        }
   5.275 -
   5.276 -                                        // Delete the originally composed mail item/draft
   5.277 -                                        sendingAccount = omi.SendUsingAccount;
   5.278 -
   5.279 -                                        // Getting delivery store can fail for new accounts when Outlook is not restarted
   5.280 -                                        try
   5.281 -                                        {
   5.282 -                                            sendingStore = sendingAccount.DeliveryStore;
   5.283 -                                        }
   5.284 -                                        catch
   5.285 -                                        {
   5.286 -                                            sendingStore = null;
   5.287 -                                            Log.Warning("Application_ItemSend: Failure getting DeliveryStore to delete composed message.");
   5.288 -                                        }
   5.289 -
   5.290 -                                        omi.PermanentlyDelete(sendingStore);
   5.291 -
   5.292 -                                        if (sendingAccount != null)
   5.293 -                                        {
   5.294 -                                            //Marshal.ReleaseComObject(sendingAccount);
   5.295 -                                            sendingAccount = null;
   5.296 -                                        }
   5.297 -
   5.298 -                                        if (sendingStore != null)
   5.299 -                                        {
   5.300 -                                            //Marshal.ReleaseComObject(sendingStore);
   5.301 -                                            sendingStore = null;
   5.302 -                                        }
   5.303 -                                    }
   5.304 +                                    throw new Exception("Error processing message.");
   5.305                                  }
   5.306 -                                else if (createSts == Globals.ReturnStatus.FailureNoConnection)
   5.307 +
   5.308 +                                processedMessage.ApplyTo(omi, false, false, false);
   5.309 +
   5.310 +                                if (processedMessage.IsSecure == false)
   5.311                                  {
   5.312 -                                    // Don't send the original message
   5.313 -                                    cancel = true;
   5.314 -
   5.315 -                                    if (omi?.GetIsAutoConsume() != true)
   5.316 -                                    {
   5.317 -                                        MessageBox.Show(Properties.Resources.Message_SendingNoConnection,
   5.318 -                                                        Properties.Resources.Message_TitlePEPError,
   5.319 -                                                        MessageBoxButtons.OK,
   5.320 -                                                        MessageBoxIcon.Warning);
   5.321 -                                    }
   5.322 +                                    // Avoid creation of 'winmail.dat' attachment
   5.323 +                                    omi.AvoidWinmailDatAttachment();
   5.324                                  }
   5.325 -                                else
   5.326 +                            }
   5.327 +                            else if (status == Globals.ReturnStatus.FailureNoConnection)
   5.328 +                            {
   5.329 +                                // Don't send the original message
   5.330 +                                cancel = true;
   5.331 +
   5.332 +                                if (omi?.GetIsAutoConsume() != true)
   5.333                                  {
   5.334 -                                    // Throw the error out to the main catch
   5.335 -                                    throw (new Exception("Failed to create PEPMessage"));
   5.336 +                                    MessageBox.Show(Properties.Resources.Message_SendingNoConnection,
   5.337 +                                                    Properties.Resources.Message_TitlePEPError,
   5.338 +                                                    MessageBoxButtons.OK,
   5.339 +                                                    MessageBoxIcon.Warning);
   5.340                                  }
   5.341                              }
   5.342                              else
   5.343                              {
   5.344 -                                // Always log (not as only in verbose) to show when user sent unencrypted
   5.345 -                                Log.Info("Application_ItemSend: Sending unencrypted because message has BCCs.");
   5.346 -
   5.347 -                                // Add disclaimer if needed
   5.348 -                                omi.AddDisclaimer();
   5.349 -
   5.350 -                                // Avoid creation of 'winmail.dat' attachment
   5.351 -                                omi.AvoidWinmailDatAttachment();
   5.352 +                                // Throw the error out to the main catch
   5.353 +                                throw (new Exception("Failed to create PEPMessage"));
   5.354                              }
   5.355                          }
   5.356                          catch (Exception ex)
     6.1 --- a/UI/KeySyncWizard.xaml.cs	Thu Jun 07 11:37:46 2018 +0200
     6.2 +++ b/UI/KeySyncWizard.xaml.cs	Fri Jun 08 12:43:37 2018 +0200
     6.3 @@ -1562,7 +1562,7 @@
     6.4                              (this.ExportPrivateKey))
     6.5                          {
     6.6                              // Encrypt and add private key
     6.7 -                            if (msgProcessor.EncryptAndAddPrivateKey(message, this.Partner.Fingerprint, out msg))
     6.8 +                            if (msgProcessor.EncryptAndAddPrivateKey(message, out msg, this.Partner.Fingerprint))
     6.9                              {
    6.10                                  Log.Verbose("SendSyncMessage: Private key message successfully created.");
    6.11                                  message = msg;
    6.12 @@ -1579,7 +1579,7 @@
    6.13                                   (messageType == MessageTypes.PublicKeyMessage))
    6.14                          {
    6.15                              // Encrypt using partner fpr as extra key
    6.16 -                            if (msgProcessor.Encrypt(message, new string[] { this.Partner.Fingerprint }, out msg))
    6.17 +                            if (msgProcessor.Encrypt(message, out msg, new string[] { this.Partner.Fingerprint }))
    6.18                              {
    6.19                                  Log.Verbose("SendSyncMessage: Public key message successfully created.");
    6.20                                  message = msg;