Exemple #1
0
 private void UpdateSessionCache(IIMapServerSettings setting)
 {
     if (!ImapSessionCache.ContainsKey(setting)) // Add if session doesn't already exist
     {
         ImapSessionCache.TryAdd(setting, _imapMailReader.CreateConnection(setting));
     }
     else
     {
         RefreshSessionIfExpired(setting);
     }
 }
Exemple #2
0
        private void RefreshSessionIfExpired(IIMapServerSettings setting)
        {
            var session = ImapSessionCache.FirstOrDefault(s => s.Key == setting).Value;

            if (session != null && !session.IsConnected())
            {
                IImapMailReader removed;
                if (ImapSessionCache.TryRemove(setting, out removed) && removed != null)
                {
                    ImapSessionCache.TryAdd(setting, _imapMailReader.CreateConnection(setting));
                }
            }
        }