Example #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);
     }
 }
Example #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));
                }
            }
        }
Example #3
0
        private ImapMailReader(IIMapServerSettings mailConfig)
        {
            if (mailConfig.IsSecureSocket)
            {
                Client.ConnectSsl(mailConfig.ImapServer, mailConfig.Port);
            }
            else
            {
                Client.Connect(mailConfig.ImapServer, mailConfig.Port);
            }

            Client.Login(mailConfig.UserLogin, mailConfig.UserPassword);
        }
Example #4
0
 public IImapMailReader GetActiveImapSession(IIMapServerSettings imapSetting)
 {
     return(ImapSessionCache[imapSetting]);
 }
Example #5
0
 public ImapMailReader CreateConnection(IIMapServerSettings mailConfig)
 {
     return(new ImapMailReader(mailConfig));
 }