Check if we have an entry id before caching
authorThomas
Thu, 11 Oct 2018 14:44:29 +0200
changeset 2406dcffbae23df9
parent 2405 5153acd8eb86
child 2407 20224390f6c0
Check if we have an entry id before caching
CryptableMailItem.cs
     1.1 --- a/CryptableMailItem.cs	Thu Oct 11 12:18:26 2018 +0200
     1.2 +++ b/CryptableMailItem.cs	Thu Oct 11 14:44:29 2018 +0200
     1.3 @@ -1653,7 +1653,7 @@
     1.4                                  }
     1.5                                  else
     1.6                                  {
     1.7 -                                    // Apply message and save
     1.8 +                                    // Trusted server: apply message and save
     1.9                                      processedMessage.ApplyTo(this.internalMailItem, true, false);
    1.10                                      saveInternalMailItem = true;
    1.11                                  }
    1.12 @@ -1701,25 +1701,29 @@
    1.13                  this._LastProcessedRating = result.Rating;
    1.14                  this._LastProcessedStatus = status;
    1.15  
    1.16 -                // Save rating in db
    1.17 -                PEPDatabase.StoreOrUpdateRating(entryId, result.Rating);
    1.18 +                // If it's an incoming message, do some caching (entry ids of drafts are empty)
    1.19 +                if (string.IsNullOrEmpty(entryId) == false)
    1.20 +                {
    1.21 +                    // Save rating in db
    1.22 +                    PEPDatabase.StoreOrUpdateRating(entryId, result.Rating);
    1.23  
    1.24 -                // Save message in cache
    1.25 -                if (isSecurelyStored)
    1.26 -                {
    1.27 -                    if (Mirror != null)
    1.28 +                    // Save message in cache
    1.29 +                    if (isSecurelyStored)
    1.30                      {
    1.31 -                        PEPCache.AddItemToCache(entryId, new PEPCache.CacheItem { Mirror = Mirror, Rating = result.Rating });
    1.32 +                        if (Mirror != null)
    1.33 +                        {
    1.34 +                            PEPCache.AddItemToCache(entryId, new PEPCache.CacheItem { Mirror = Mirror, Rating = result.Rating });
    1.35 +                        }
    1.36 +                        else if (Message != null)
    1.37 +                        {
    1.38 +                            PEPCache.AddItemToCache(entryId, new PEPCache.CacheItem { Mirror = Message, Rating = result.Rating });
    1.39 +                        }
    1.40                      }
    1.41 -                    else if (Message != null)
    1.42 +                    else
    1.43                      {
    1.44 -                        PEPCache.AddItemToCache(entryId, new PEPCache.CacheItem { Mirror = Message, Rating = result.Rating });
    1.45 +                        PEPCache.AddItemToCache(entryId, new PEPCache.CacheItem { Mirror = null, Rating = result.Rating });
    1.46                      }
    1.47                  }
    1.48 -                else
    1.49 -                {
    1.50 -                    PEPCache.AddItemToCache(entryId, new PEPCache.CacheItem { Mirror = null, Rating = result.Rating });
    1.51 -                }
    1.52  
    1.53                  // Release objects
    1.54                  mirrorMailItem = null;
    1.55 @@ -1816,7 +1820,7 @@
    1.56                  /* If there are MAPI properties to set, we have to marshal
    1.57                   * this call to the main thread. If not, we can just dispose it
    1.58                   * on the current one.
    1.59 -                 */ 
    1.60 +                 */
    1.61                  if (result?.PropertiesToSet?.Count > 0)
    1.62                  {
    1.63                      KeySyncWizard.Wizard.Dispatcher.Invoke(new Action(() =>