small fixes and changes for stability 1.1.10
authorVolker Birk <vb@pep-project.org>
Tue, 06 Dec 2016 14:56:11 +0100
changeset 1517a16847bc6bb4
parent 1516 0a838ded02dd
child 1518 6eab00617312
small fixes and changes for stability
CryptableMailItem.cs
MsgProcessor.cs
UI/ValueConverters.cs
     1.1 --- a/CryptableMailItem.cs	Thu Dec 01 15:39:37 2016 +0100
     1.2 +++ b/CryptableMailItem.cs	Tue Dec 06 14:56:11 2016 +0100
     1.3 @@ -5,6 +5,7 @@
     1.4  using System.Runtime.InteropServices;
     1.5  using System.Threading;
     1.6  using Outlook = Microsoft.Office.Interop.Outlook;
     1.7 +using System.Diagnostics;
     1.8  
     1.9  namespace pEp
    1.10  {
    1.11 @@ -248,10 +249,10 @@
    1.12              {
    1.13                  this.Send?.Invoke(ref cancel);
    1.14              }
    1.15 -            catch (Exception e)
    1.16 +            catch (Exception)
    1.17              {
    1.18                  inSend = false;
    1.19 -                throw e;
    1.20 +                throw;
    1.21              }
    1.22              inSend = false;
    1.23              return;
    1.24 @@ -689,6 +690,19 @@
    1.25              }
    1.26              set
    1.27              {
    1.28 +                // read the MailItem to a file
    1.29 +
    1.30 +                if (value == Outlook.OlRemoteStatus.olMarkedForDownload)
    1.31 +                {
    1.32 +                    string filename = System.IO.Path.GetTempFileName();
    1.33 +                    internalMailItem.SaveAs(filename, Outlook.OlSaveAsType.olMSGUnicode);
    1.34 +                    System.IO.File.Delete(filename);
    1.35 +                }
    1.36 +                else
    1.37 +                {
    1.38 +                    Debug.Assert(false, "do not use this function, it is unstable in Outlook 2010 and Outlook 2013");
    1.39 +                }
    1.40 +                /*
    1.41                  lock (mutexMailItem)
    1.42                  {
    1.43                      this.internalMailItem.MarkForDownload = value;
    1.44 @@ -696,6 +710,7 @@
    1.45                      // Raise event - must be called last
    1.46                      this.RaisePropertyChangedEvent(nameof(this.MarkForDownload));
    1.47                  }
    1.48 +                */
    1.49              }
    1.50          }
    1.51  
     2.1 --- a/MsgProcessor.cs	Thu Dec 01 15:39:37 2016 +0100
     2.2 +++ b/MsgProcessor.cs	Tue Dec 06 14:56:11 2016 +0100
     2.3 @@ -53,11 +53,6 @@
     2.4           * 
     2.5           *************************************************************/
     2.6  
     2.7 -        /// <summary>
     2.8 -        /// cache timestamps of last processed messages
     2.9 -        /// </summary>
    2.10 -        private Dictionary<string, DateTime> LastProcessed = new Dictionary<string, DateTime>();
    2.11 -
    2.12          // not const because a TimeSpan cannot be const, but meant to be read only.
    2.13          private static TimeSpan SECOND = new TimeSpan(0, 0, 1);
    2.14  
    2.15 @@ -96,8 +91,6 @@
    2.16                  args.ProcessedMessage = processedMessage;
    2.17                  args.ProcessedRating = processedRating;
    2.18                  args.ProcessedStatus = sts;
    2.19 -
    2.20 -                LastProcessed.Add(msgCont.EntryId, DateTime.Now);
    2.21              }
    2.22  
    2.23              e.Result = args;
    2.24 @@ -297,30 +290,199 @@
    2.25              pEpRating tRating2;
    2.26              Globals.ReturnStatus status = Globals.ReturnStatus.Success;
    2.27  
    2.28 -            if (LastProcessed.ContainsKey(entryID) && LastProcessed[entryID].CompareTo(DateTime.Now.Subtract(SECOND)) > 0)
    2.29 +            if (message == null)
    2.30              {
    2.31                  status = Globals.ReturnStatus.Failure;
    2.32 +                Log.Verbose("ProcessMessage: Can't process null message");
    2.33              }
    2.34              else
    2.35              {
    2.36 -                if (message == null)
    2.37 +                if (messageCreationStatus == Globals.ReturnStatus.Success)
    2.38                  {
    2.39 -                    status = Globals.ReturnStatus.Failure;
    2.40 -                    Log.Verbose("ProcessMessage: Can't process null message");
    2.41 -                }
    2.42 -                else
    2.43 -                {
    2.44 -                    if (messageCreationStatus == Globals.ReturnStatus.Success)
    2.45 +                    // In secure (untrusted) store or marked NeverUnsecure
    2.46 +                    if (isInSecureStore || message.NeverUnsecure)
    2.47                      {
    2.48 -                        // In secure (untrusted) store or marked NeverUnsecure
    2.49 -                        if (isInSecureStore || message.NeverUnsecure)
    2.50 +                        Log.Verbose("ProcessMessage: In secure store or marked never unsecure.");
    2.51 +
    2.52 +                        // Sent folder
    2.53 +                        if (isInSentFolder)
    2.54                          {
    2.55 -                            Log.Verbose("ProcessMessage: In secure store or marked never unsecure.");
    2.56 +                            Log.Verbose("ProcessMessage: In sent folder.");
    2.57  
    2.58 -                            // Sent folder
    2.59 -                            if (isInSentFolder)
    2.60 +                            // Secure mail in a secure (untrusted) store or marked NeverUnsecure
    2.61 +                            // This will use a mirror
    2.62 +                            if (message.IsSecure)
    2.63                              {
    2.64 -                                Log.Verbose("ProcessMessage: In sent folder.");
    2.65 +                                Log.Verbose("ProcessMessage: Is secure.");
    2.66 +                                isMirror = true;
    2.67 +
    2.68 +                                if (mirror == null)
    2.69 +                                {
    2.70 +                                    Log.Verbose("ProcessMessage: Mirror not found, creating and decrypting.");
    2.71 +
    2.72 +                                    success = this.Decrypt(message,
    2.73 +                                                            out newMessage,
    2.74 +                                                            out decryptionKeyList,
    2.75 +                                                            out decryptionFlags,
    2.76 +                                                            out tRating);
    2.77 +                                    tRating2 = this.GetOutgoingRating(message);
    2.78 +
    2.79 +                                    if (success)
    2.80 +                                    {
    2.81 +                                        processedMessage = newMessage.Copy();
    2.82 +                                        processedMessage.Rating = tRating2;
    2.83 +
    2.84 +                                        processedRating = tRating2; // Outgoing rating
    2.85 +                                    }
    2.86 +                                    else
    2.87 +                                    {
    2.88 +                                        // Do nothing, decryption failed
    2.89 +                                        status = Globals.ReturnStatus.Failure;
    2.90 +                                        Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
    2.91 +
    2.92 +                                        processedRating = tRating;
    2.93 +                                    }
    2.94 +                                }
    2.95 +                                else
    2.96 +                                {
    2.97 +                                    Log.Verbose("ProcessMessage: Mirror exists");
    2.98 +
    2.99 +                                    if (mirror.Rating == pEpRating.pEpRatingUndefined)
   2.100 +                                    {
   2.101 +                                        tRating = this.GetOutgoingRating(message);
   2.102 +                                        processedMessage = mirror.Copy();
   2.103 +                                        processedMessage.Rating = tRating;
   2.104 +
   2.105 +                                        processedRating = tRating;
   2.106 +                                    }
   2.107 +                                    else
   2.108 +                                    {
   2.109 +                                        processedRating = mirror.Rating;
   2.110 +                                    }
   2.111 +                                }
   2.112 +                            }
   2.113 +                            // Unsecure mail in a secure (untrusted) store or marked NeverUnsecure
   2.114 +                            // This does not have a mirror
   2.115 +                            else
   2.116 +                            {
   2.117 +                                Log.Verbose("ProcessMessage: Is unsecure.");
   2.118 +                                processedRating = pEpRating.pEpRatingUnencrypted;
   2.119 +                            }
   2.120 +                        }
   2.121 +                        // Incoming
   2.122 +                        else if (message.Direction == pEpMsgDirection.pEpDirIncoming)
   2.123 +                        {
   2.124 +                            Log.Verbose("ProcessMessage: Is incoming.");
   2.125 +
   2.126 +                            // Secure mail in a secure (untrusted) store or marked NeverUnsecure
   2.127 +                            // This will use a mirror
   2.128 +                            if (message.IsSecure)
   2.129 +                            {
   2.130 +                                Log.Verbose("ProcessMessage: Is secure.");
   2.131 +                                isMirror = true;
   2.132 +
   2.133 +                                if (mirror == null)
   2.134 +                                {
   2.135 +                                    Log.Verbose("ProcessMessage: Mirror not found, creating and decrypting.");
   2.136 +
   2.137 +                                    success = this.Decrypt(message,
   2.138 +                                                            out newMessage,
   2.139 +                                                            out decryptionKeyList,
   2.140 +                                                            out decryptionFlags,
   2.141 +                                                            out tRating);
   2.142 +
   2.143 +                                    if (success)
   2.144 +                                    {
   2.145 +                                        processedMessage = newMessage.Copy();
   2.146 +                                        processedMessage.Rating = tRating;
   2.147 +                                    }
   2.148 +                                    else
   2.149 +                                    {
   2.150 +                                        // Do nothing, decryption failed
   2.151 +                                        status = Globals.ReturnStatus.Failure;
   2.152 +                                        Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.153 +                                    }
   2.154 +
   2.155 +                                    processedRating = tRating;
   2.156 +                                }
   2.157 +                                else
   2.158 +                                {
   2.159 +                                    Log.Verbose("ProcessMessage: Mirror exists, verifying rating.");
   2.160 +
   2.161 +                                    tRating = this.Decrypt(message,
   2.162 +                                                            out newMessage,
   2.163 +                                                            out decryptionKeyList,
   2.164 +                                                            out decryptionFlags);
   2.165 +                                    tRating2 = mirror.Rating;
   2.166 +
   2.167 +                                    // Compare ratings and update as needed
   2.168 +                                    if (tRating != tRating2)
   2.169 +                                    {
   2.170 +                                        processedMessage = mirror.Copy();
   2.171 +                                        processedMessage.Rating = tRating;
   2.172 +                                        processedRating = tRating;
   2.173 +                                    }
   2.174 +                                    else
   2.175 +                                    {
   2.176 +                                        processedRating = tRating2;
   2.177 +                                    }
   2.178 +                                }
   2.179 +                            }
   2.180 +                            // Unsecure mail in a secure (untrusted) store or marked NeverUnsecure
   2.181 +                            // This does not have a mirror
   2.182 +                            else
   2.183 +                            {
   2.184 +                                Log.Verbose("ProcessMessage: Is unsecure.");
   2.185 +                                processedRating = pEpRating.pEpRatingUnencrypted;
   2.186 +
   2.187 +                                // Call Decrypt to process the message, keylist and decrypted message can be ignored
   2.188 +                                this.Decrypt(message,
   2.189 +                                                out newMessage,
   2.190 +                                                out decryptionKeyList,
   2.191 +                                                out decryptionFlags);
   2.192 +                            }
   2.193 +                        }
   2.194 +                        // Outgoing
   2.195 +                        else
   2.196 +                        {
   2.197 +                            if (isDraft)
   2.198 +                            {
   2.199 +                                Log.Verbose("ProcessMessage: Is outgoing draft.");
   2.200 +
   2.201 +                                if (message.IsSecure)
   2.202 +                                {
   2.203 +                                    Log.Verbose("ProcessMessage: Is secure.");
   2.204 +
   2.205 +                                    success = this.Decrypt(message,
   2.206 +                                                            out newMessage,
   2.207 +                                                            out decryptionKeyList,
   2.208 +                                                            out decryptionFlags,
   2.209 +                                                            out tRating);
   2.210 +
   2.211 +                                    if (success)
   2.212 +                                    {
   2.213 +                                        processedMessage = newMessage.Copy();
   2.214 +                                        processedMessage.Rating = pEpRating.pEpRatingUndefined; // Never save Rating in this case
   2.215 +                                    }
   2.216 +                                    else
   2.217 +                                    {
   2.218 +                                        // Do nothing, decryption failed
   2.219 +                                        status = Globals.ReturnStatus.Failure;
   2.220 +                                        Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.221 +                                    }
   2.222 +
   2.223 +                                    processedRating = this.GetOutgoingRating(message);
   2.224 +                                }
   2.225 +                                else
   2.226 +                                {
   2.227 +                                    Log.Verbose("ProcessMessage: Is unsecure.");
   2.228 +                                    processedRating = this.GetOutgoingRating(message);
   2.229 +                                }
   2.230 +                            }
   2.231 +                            // Sent but no longer in sent folder
   2.232 +                            else
   2.233 +                            {
   2.234 +                                Log.Verbose("ProcessMessage: Is outgoing (assumed previously sent).");
   2.235  
   2.236                                  // Secure mail in a secure (untrusted) store or marked NeverUnsecure
   2.237                                  // This will use a mirror
   2.238 @@ -334,10 +496,10 @@
   2.239                                          Log.Verbose("ProcessMessage: Mirror not found, creating and decrypting.");
   2.240  
   2.241                                          success = this.Decrypt(message,
   2.242 -                                                               out newMessage,
   2.243 -                                                               out decryptionKeyList,
   2.244 -                                                               out decryptionFlags,
   2.245 -                                                               out tRating);
   2.246 +                                                                out newMessage,
   2.247 +                                                                out decryptionKeyList,
   2.248 +                                                                out decryptionFlags,
   2.249 +                                                                out tRating);
   2.250                                          tRating2 = this.GetOutgoingRating(message);
   2.251  
   2.252                                          if (success)
   2.253 @@ -382,192 +544,155 @@
   2.254                                      processedRating = pEpRating.pEpRatingUnencrypted;
   2.255                                  }
   2.256                              }
   2.257 -                            // Incoming
   2.258 -                            else if (message.Direction == pEpMsgDirection.pEpDirIncoming)
   2.259 +                        }
   2.260 +                    }
   2.261 +                    // In unsecure (trusted) store
   2.262 +                    else
   2.263 +                    {
   2.264 +                        Log.Verbose("ProcessMessage: In unsecure store.");
   2.265 +
   2.266 +                        // Sent folder
   2.267 +                        if (isInSentFolder)
   2.268 +                        {
   2.269 +                            Log.Verbose("ProcessMessage: In sent folder.");
   2.270 +
   2.271 +                            // Secure mail in an unsecure (trusted) store
   2.272 +                            if (message.IsSecure)
   2.273                              {
   2.274 -                                Log.Verbose("ProcessMessage: Is incoming.");
   2.275 +                                Log.Verbose("ProcessMessage: Is secure.");
   2.276  
   2.277 -                                // Secure mail in a secure (untrusted) store or marked NeverUnsecure
   2.278 -                                // This will use a mirror
   2.279 +                                success = this.Decrypt(message,
   2.280 +                                                        out newMessage,
   2.281 +                                                        out decryptionKeyList,
   2.282 +                                                        out decryptionFlags,
   2.283 +                                                        out tRating);
   2.284 +                                tRating2 = this.GetOutgoingRating(message);
   2.285 +
   2.286 +                                if (success)
   2.287 +                                {
   2.288 +                                    processedMessage = newMessage.Copy();
   2.289 +                                    processedMessage.Rating = tRating2;
   2.290 +
   2.291 +                                    processedRating = tRating2; // Outgoing rating
   2.292 +                                }
   2.293 +                                else
   2.294 +                                {
   2.295 +                                    // Do nothing, decryption failed
   2.296 +                                    status = Globals.ReturnStatus.Failure;
   2.297 +                                    Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.298 +
   2.299 +                                    processedRating = tRating;
   2.300 +                                }
   2.301 +                            }
   2.302 +                            // Unsecure mail in an unsecure (trusted) store
   2.303 +                            else
   2.304 +                            {
   2.305 +                                Log.Verbose("ProcessMessage: Is unsecure.");
   2.306 +
   2.307 +                                // If the rating is undefined, just set it to unencrypted
   2.308 +                                if (message.Rating == pEpRating.pEpRatingUndefined)
   2.309 +                                {
   2.310 +                                    processedRating = pEpRating.pEpRatingUnencrypted;
   2.311 +                                }
   2.312 +                                else
   2.313 +                                {
   2.314 +                                    processedRating = message.Rating;
   2.315 +                                }
   2.316 +                            }
   2.317 +                        }
   2.318 +                        // Incoming
   2.319 +                        else if (message.Direction == pEpMsgDirection.pEpDirIncoming)
   2.320 +                        {
   2.321 +                            Log.Verbose("ProcessMessage: Is incoming.");
   2.322 +
   2.323 +                            // Secure mail in an unsecure (trusted) store
   2.324 +                            if (message.IsSecure)
   2.325 +                            {
   2.326 +                                Log.Verbose("ProcessMessage: Is secure.");
   2.327 +
   2.328 +                                success = this.Decrypt(message,
   2.329 +                                                        out newMessage,
   2.330 +                                                        out decryptionKeyList,
   2.331 +                                                        out decryptionFlags,
   2.332 +                                                        out tRating);
   2.333 +
   2.334 +                                if (success)
   2.335 +                                {
   2.336 +                                    processedMessage = newMessage.Copy();
   2.337 +                                    processedMessage.Rating = tRating;
   2.338 +                                }
   2.339 +                                else
   2.340 +                                {
   2.341 +                                    // Do nothing, decryption failed
   2.342 +                                    status = Globals.ReturnStatus.Failure;
   2.343 +                                    Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.344 +                                }
   2.345 +
   2.346 +                                processedRating = tRating;
   2.347 +                            }
   2.348 +                            // Unsecure mail in an unsecure (trusted) store
   2.349 +                            else
   2.350 +                            {
   2.351 +                                Log.Verbose("ProcessMessage: Is unsecure.");
   2.352 +
   2.353 +                                // If the rating is undefined, just set it to unencrypted
   2.354 +                                if (message.Rating == pEpRating.pEpRatingUndefined)
   2.355 +                                {
   2.356 +                                    processedRating = pEpRating.pEpRatingUnencrypted;
   2.357 +                                }
   2.358 +                                else
   2.359 +                                {
   2.360 +                                    processedRating = message.Rating;
   2.361 +                                }
   2.362 +
   2.363 +                                // Call Decrypt to process the message, keylist and decrypted message can be ignored
   2.364 +                                this.Decrypt(message,
   2.365 +                                                out newMessage,
   2.366 +                                                out decryptionKeyList,
   2.367 +                                                out decryptionFlags);
   2.368 +                            }
   2.369 +                        }
   2.370 +                        // Outgoing
   2.371 +                        else
   2.372 +                        {
   2.373 +                            if (isDraft)
   2.374 +                            {
   2.375 +                                Log.Verbose("ProcessMessage: Is outgoing draft.");
   2.376 +
   2.377                                  if (message.IsSecure)
   2.378                                  {
   2.379                                      Log.Verbose("ProcessMessage: Is secure.");
   2.380 -                                    isMirror = true;
   2.381  
   2.382 -                                    if (mirror == null)
   2.383 +                                    success = this.Decrypt(message,
   2.384 +                                                            out newMessage,
   2.385 +                                                            out decryptionKeyList,
   2.386 +                                                            out decryptionFlags,
   2.387 +                                                            out tRating);
   2.388 +
   2.389 +                                    if (success)
   2.390                                      {
   2.391 -                                        Log.Verbose("ProcessMessage: Mirror not found, creating and decrypting.");
   2.392 -
   2.393 -                                        success = this.Decrypt(message,
   2.394 -                                                               out newMessage,
   2.395 -                                                               out decryptionKeyList,
   2.396 -                                                               out decryptionFlags,
   2.397 -                                                               out tRating);
   2.398 -
   2.399 -                                        if (success)
   2.400 -                                        {
   2.401 -                                            processedMessage = newMessage.Copy();
   2.402 -                                            processedMessage.Rating = tRating;
   2.403 -                                        }
   2.404 -                                        else
   2.405 -                                        {
   2.406 -                                            // Do nothing, decryption failed
   2.407 -                                            status = Globals.ReturnStatus.Failure;
   2.408 -                                            Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.409 -                                        }
   2.410 -
   2.411 -                                        processedRating = tRating;
   2.412 +                                        processedMessage = newMessage.Copy();
   2.413 +                                        processedMessage.Rating = pEpRating.pEpRatingUndefined; // Never save Rating in this case
   2.414                                      }
   2.415                                      else
   2.416                                      {
   2.417 -                                        Log.Verbose("ProcessMessage: Mirror exists, verifying rating.");
   2.418 +                                        // Do nothing, decryption failed
   2.419 +                                        status = Globals.ReturnStatus.Failure;
   2.420 +                                        Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.421 +                                    }
   2.422  
   2.423 -                                        tRating = this.Decrypt(message,
   2.424 -                                                               out newMessage,
   2.425 -                                                               out decryptionKeyList,
   2.426 -                                                               out decryptionFlags);
   2.427 -                                        tRating2 = mirror.Rating;
   2.428 -
   2.429 -                                        // Compare ratings and update as needed
   2.430 -                                        if (tRating != tRating2)
   2.431 -                                        {
   2.432 -                                            processedMessage = mirror.Copy();
   2.433 -                                            processedMessage.Rating = tRating;
   2.434 -                                            processedRating = tRating;
   2.435 -                                        }
   2.436 -                                        else
   2.437 -                                        {
   2.438 -                                            processedRating = tRating2;
   2.439 -                                        }
   2.440 -                                    }
   2.441 +                                    processedRating = this.GetOutgoingRating(message);
   2.442                                  }
   2.443 -                                // Unsecure mail in a secure (untrusted) store or marked NeverUnsecure
   2.444 -                                // This does not have a mirror
   2.445                                  else
   2.446                                  {
   2.447                                      Log.Verbose("ProcessMessage: Is unsecure.");
   2.448 -                                    processedRating = pEpRating.pEpRatingUnencrypted;
   2.449 -
   2.450 -                                    // Call Decrypt to process the message, keylist and decrypted message can be ignored
   2.451 -                                    this.Decrypt(message,
   2.452 -                                                 out newMessage,
   2.453 -                                                 out decryptionKeyList,
   2.454 -                                                 out decryptionFlags);
   2.455 +                                    processedRating = this.GetOutgoingRating(message);
   2.456                                  }
   2.457                              }
   2.458 -                            // Outgoing
   2.459 +                            // Sent but no longer in sent folder
   2.460                              else
   2.461                              {
   2.462 -                                if (isDraft)
   2.463 -                                {
   2.464 -                                    Log.Verbose("ProcessMessage: Is outgoing draft.");
   2.465 -
   2.466 -                                    if (message.IsSecure)
   2.467 -                                    {
   2.468 -                                        Log.Verbose("ProcessMessage: Is secure.");
   2.469 -
   2.470 -                                        success = this.Decrypt(message,
   2.471 -                                                               out newMessage,
   2.472 -                                                               out decryptionKeyList,
   2.473 -                                                               out decryptionFlags,
   2.474 -                                                               out tRating);
   2.475 -
   2.476 -                                        if (success)
   2.477 -                                        {
   2.478 -                                            processedMessage = newMessage.Copy();
   2.479 -                                            processedMessage.Rating = pEpRating.pEpRatingUndefined; // Never save Rating in this case
   2.480 -                                        }
   2.481 -                                        else
   2.482 -                                        {
   2.483 -                                            // Do nothing, decryption failed
   2.484 -                                            status = Globals.ReturnStatus.Failure;
   2.485 -                                            Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.486 -                                        }
   2.487 -
   2.488 -                                        processedRating = this.GetOutgoingRating(message);
   2.489 -                                    }
   2.490 -                                    else
   2.491 -                                    {
   2.492 -                                        Log.Verbose("ProcessMessage: Is unsecure.");
   2.493 -                                        processedRating = this.GetOutgoingRating(message);
   2.494 -                                    }
   2.495 -                                }
   2.496 -                                // Sent but no longer in sent folder
   2.497 -                                else
   2.498 -                                {
   2.499 -                                    Log.Verbose("ProcessMessage: Is outgoing (assumed previously sent).");
   2.500 -
   2.501 -                                    // Secure mail in a secure (untrusted) store or marked NeverUnsecure
   2.502 -                                    // This will use a mirror
   2.503 -                                    if (message.IsSecure)
   2.504 -                                    {
   2.505 -                                        Log.Verbose("ProcessMessage: Is secure.");
   2.506 -                                        isMirror = true;
   2.507 -
   2.508 -                                        if (mirror == null)
   2.509 -                                        {
   2.510 -                                            Log.Verbose("ProcessMessage: Mirror not found, creating and decrypting.");
   2.511 -
   2.512 -                                            success = this.Decrypt(message,
   2.513 -                                                                   out newMessage,
   2.514 -                                                                   out decryptionKeyList,
   2.515 -                                                                   out decryptionFlags,
   2.516 -                                                                   out tRating);
   2.517 -                                            tRating2 = this.GetOutgoingRating(message);
   2.518 -
   2.519 -                                            if (success)
   2.520 -                                            {
   2.521 -                                                processedMessage = newMessage.Copy();
   2.522 -                                                processedMessage.Rating = tRating2;
   2.523 -
   2.524 -                                                processedRating = tRating2; // Outgoing rating
   2.525 -                                            }
   2.526 -                                            else
   2.527 -                                            {
   2.528 -                                                // Do nothing, decryption failed
   2.529 -                                                status = Globals.ReturnStatus.Failure;
   2.530 -                                                Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.531 -
   2.532 -                                                processedRating = tRating;
   2.533 -                                            }
   2.534 -                                        }
   2.535 -                                        else
   2.536 -                                        {
   2.537 -                                            Log.Verbose("ProcessMessage: Mirror exists");
   2.538 -
   2.539 -                                            if (mirror.Rating == pEpRating.pEpRatingUndefined)
   2.540 -                                            {
   2.541 -                                                tRating = this.GetOutgoingRating(message);
   2.542 -                                                processedMessage = mirror.Copy();
   2.543 -                                                processedMessage.Rating = tRating;
   2.544 -
   2.545 -                                                processedRating = tRating;
   2.546 -                                            }
   2.547 -                                            else
   2.548 -                                            {
   2.549 -                                                processedRating = mirror.Rating;
   2.550 -                                            }
   2.551 -                                        }
   2.552 -                                    }
   2.553 -                                    // Unsecure mail in a secure (untrusted) store or marked NeverUnsecure
   2.554 -                                    // This does not have a mirror
   2.555 -                                    else
   2.556 -                                    {
   2.557 -                                        Log.Verbose("ProcessMessage: Is unsecure.");
   2.558 -                                        processedRating = pEpRating.pEpRatingUnencrypted;
   2.559 -                                    }
   2.560 -                                }
   2.561 -                            }
   2.562 -                        }
   2.563 -                        // In unsecure (trusted) store
   2.564 -                        else
   2.565 -                        {
   2.566 -                            Log.Verbose("ProcessMessage: In unsecure store.");
   2.567 -
   2.568 -                            // Sent folder
   2.569 -                            if (isInSentFolder)
   2.570 -                            {
   2.571 -                                Log.Verbose("ProcessMessage: In sent folder.");
   2.572 +                                Log.Verbose("ProcessMessage: Is outgoing (assumed previously sent).");
   2.573  
   2.574                                  // Secure mail in an unsecure (trusted) store
   2.575                                  if (message.IsSecure)
   2.576 @@ -575,10 +700,10 @@
   2.577                                      Log.Verbose("ProcessMessage: Is secure.");
   2.578  
   2.579                                      success = this.Decrypt(message,
   2.580 -                                                           out newMessage,
   2.581 -                                                           out decryptionKeyList,
   2.582 -                                                           out decryptionFlags,
   2.583 -                                                           out tRating);
   2.584 +                                                            out newMessage,
   2.585 +                                                            out decryptionKeyList,
   2.586 +                                                            out decryptionFlags,
   2.587 +                                                            out tRating);
   2.588                                      tRating2 = this.GetOutgoingRating(message);
   2.589  
   2.590                                      if (success)
   2.591 @@ -613,174 +738,30 @@
   2.592                                      }
   2.593                                  }
   2.594                              }
   2.595 -                            // Incoming
   2.596 -                            else if (message.Direction == pEpMsgDirection.pEpDirIncoming)
   2.597 -                            {
   2.598 -                                Log.Verbose("ProcessMessage: Is incoming.");
   2.599 -
   2.600 -                                // Secure mail in an unsecure (trusted) store
   2.601 -                                if (message.IsSecure)
   2.602 -                                {
   2.603 -                                    Log.Verbose("ProcessMessage: Is secure.");
   2.604 -
   2.605 -                                    success = this.Decrypt(message,
   2.606 -                                                           out newMessage,
   2.607 -                                                           out decryptionKeyList,
   2.608 -                                                           out decryptionFlags,
   2.609 -                                                           out tRating);
   2.610 -
   2.611 -                                    if (success)
   2.612 -                                    {
   2.613 -                                        processedMessage = newMessage.Copy();
   2.614 -                                        processedMessage.Rating = tRating;
   2.615 -                                    }
   2.616 -                                    else
   2.617 -                                    {
   2.618 -                                        // Do nothing, decryption failed
   2.619 -                                        status = Globals.ReturnStatus.Failure;
   2.620 -                                        Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.621 -                                    }
   2.622 -
   2.623 -                                    processedRating = tRating;
   2.624 -                                }
   2.625 -                                // Unsecure mail in an unsecure (trusted) store
   2.626 -                                else
   2.627 -                                {
   2.628 -                                    Log.Verbose("ProcessMessage: Is unsecure.");
   2.629 -
   2.630 -                                    // If the rating is undefined, just set it to unencrypted
   2.631 -                                    if (message.Rating == pEpRating.pEpRatingUndefined)
   2.632 -                                    {
   2.633 -                                        processedRating = pEpRating.pEpRatingUnencrypted;
   2.634 -                                    }
   2.635 -                                    else
   2.636 -                                    {
   2.637 -                                        processedRating = message.Rating;
   2.638 -                                    }
   2.639 -
   2.640 -                                    // Call Decrypt to process the message, keylist and decrypted message can be ignored
   2.641 -                                    this.Decrypt(message,
   2.642 -                                                 out newMessage,
   2.643 -                                                 out decryptionKeyList,
   2.644 -                                                 out decryptionFlags);
   2.645 -                                }
   2.646 -                            }
   2.647 -                            // Outgoing
   2.648 -                            else
   2.649 -                            {
   2.650 -                                if (isDraft)
   2.651 -                                {
   2.652 -                                    Log.Verbose("ProcessMessage: Is outgoing draft.");
   2.653 -
   2.654 -                                    if (message.IsSecure)
   2.655 -                                    {
   2.656 -                                        Log.Verbose("ProcessMessage: Is secure.");
   2.657 -
   2.658 -                                        success = this.Decrypt(message,
   2.659 -                                                               out newMessage,
   2.660 -                                                               out decryptionKeyList,
   2.661 -                                                               out decryptionFlags,
   2.662 -                                                               out tRating);
   2.663 -
   2.664 -                                        if (success)
   2.665 -                                        {
   2.666 -                                            processedMessage = newMessage.Copy();
   2.667 -                                            processedMessage.Rating = pEpRating.pEpRatingUndefined; // Never save Rating in this case
   2.668 -                                        }
   2.669 -                                        else
   2.670 -                                        {
   2.671 -                                            // Do nothing, decryption failed
   2.672 -                                            status = Globals.ReturnStatus.Failure;
   2.673 -                                            Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.674 -                                        }
   2.675 -
   2.676 -                                        processedRating = this.GetOutgoingRating(message);
   2.677 -                                    }
   2.678 -                                    else
   2.679 -                                    {
   2.680 -                                        Log.Verbose("ProcessMessage: Is unsecure.");
   2.681 -                                        processedRating = this.GetOutgoingRating(message);
   2.682 -                                    }
   2.683 -                                }
   2.684 -                                // Sent but no longer in sent folder
   2.685 -                                else
   2.686 -                                {
   2.687 -                                    Log.Verbose("ProcessMessage: Is outgoing (assumed previously sent).");
   2.688 -
   2.689 -                                    // Secure mail in an unsecure (trusted) store
   2.690 -                                    if (message.IsSecure)
   2.691 -                                    {
   2.692 -                                        Log.Verbose("ProcessMessage: Is secure.");
   2.693 -
   2.694 -                                        success = this.Decrypt(message,
   2.695 -                                                               out newMessage,
   2.696 -                                                               out decryptionKeyList,
   2.697 -                                                               out decryptionFlags,
   2.698 -                                                               out tRating);
   2.699 -                                        tRating2 = this.GetOutgoingRating(message);
   2.700 -
   2.701 -                                        if (success)
   2.702 -                                        {
   2.703 -                                            processedMessage = newMessage.Copy();
   2.704 -                                            processedMessage.Rating = tRating2;
   2.705 -
   2.706 -                                            processedRating = tRating2; // Outgoing rating
   2.707 -                                        }
   2.708 -                                        else
   2.709 -                                        {
   2.710 -                                            // Do nothing, decryption failed
   2.711 -                                            status = Globals.ReturnStatus.Failure;
   2.712 -                                            Log.Error("ProcessMessage: Decryption failed, " + tRating.ToString());
   2.713 -
   2.714 -                                            processedRating = tRating;
   2.715 -                                        }
   2.716 -                                    }
   2.717 -                                    // Unsecure mail in an unsecure (trusted) store
   2.718 -                                    else
   2.719 -                                    {
   2.720 -                                        Log.Verbose("ProcessMessage: Is unsecure.");
   2.721 -
   2.722 -                                        // If the rating is undefined, just set it to unencrypted
   2.723 -                                        if (message.Rating == pEpRating.pEpRatingUndefined)
   2.724 -                                        {
   2.725 -                                            processedRating = pEpRating.pEpRatingUnencrypted;
   2.726 -                                        }
   2.727 -                                        else
   2.728 -                                        {
   2.729 -                                            processedRating = message.Rating;
   2.730 -                                        }
   2.731 -                                    }
   2.732 -                                }
   2.733 -                            }
   2.734                          }
   2.735                      }
   2.736 -                    else if (messageCreationStatus == Globals.ReturnStatus.FailureNoConnection)
   2.737 +                }
   2.738 +                else if (messageCreationStatus == Globals.ReturnStatus.FailureNoConnection)
   2.739 +                {
   2.740 +                    status = Globals.ReturnStatus.FailureNoConnection;
   2.741 +
   2.742 +                    // Try to use the last stored rating, do no other processing
   2.743 +                    if ((isInSecureStore || message.NeverUnsecure) &&
   2.744 +                        (message.IsSecure) &&
   2.745 +                        (mirror != null))
   2.746                      {
   2.747 -                        status = Globals.ReturnStatus.FailureNoConnection;
   2.748 -
   2.749 -                        // Try to use the last stored rating, do no other processing
   2.750 -                        if ((isInSecureStore || message.NeverUnsecure) &&
   2.751 -                            (message.IsSecure) &&
   2.752 -                            (mirror != null))
   2.753 -                        {
   2.754 -                            processedRating = mirror.Rating; // Undefined if not already existing
   2.755 -                        }
   2.756 -                        else
   2.757 -                        {
   2.758 -                            processedRating = message.Rating; // Undefined if not already existing
   2.759 -                        }
   2.760 +                        processedRating = mirror.Rating; // Undefined if not already existing
   2.761                      }
   2.762                      else
   2.763                      {
   2.764 -                        status = Globals.ReturnStatus.Failure;
   2.765 -                        processedRating = pEpRating.pEpRatingCannotDecrypt;
   2.766 +                        processedRating = message.Rating; // Undefined if not already existing
   2.767                      }
   2.768                  }
   2.769 -            }
   2.770 -
   2.771 -            if (status == Globals.ReturnStatus.Success)
   2.772 -            {
   2.773 -                LastProcessed.Add(entryID, DateTime.Now);
   2.774 +                else
   2.775 +                {
   2.776 +                    status = Globals.ReturnStatus.Failure;
   2.777 +                    processedRating = pEpRating.pEpRatingCannotDecrypt;
   2.778 +                }
   2.779              }
   2.780  
   2.781              // Set outputs
     3.1 --- a/UI/ValueConverters.cs	Thu Dec 01 15:39:37 2016 +0100
     3.2 +++ b/UI/ValueConverters.cs	Tue Dec 06 14:56:11 2016 +0100
     3.3 @@ -158,7 +158,8 @@
     3.4  
     3.5              if (value == null)
     3.6              {
     3.7 -                throw new ArgumentNullException();
     3.8 +                return new System.Windows.Media.Imaging.BitmapImage();
     3.9 +//                throw new ArgumentNullException();
    3.10              }
    3.11  
    3.12              if (value is Icon)