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); } }
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)); } } }
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); }
public IImapMailReader GetActiveImapSession(IIMapServerSettings imapSetting) { return(ImapSessionCache[imapSetting]); }
public ImapMailReader CreateConnection(IIMapServerSettings mailConfig) { return(new ImapMailReader(mailConfig)); }