/// <summary> /// Main constructor. /// </summary> /// <param name="config">The configuration instance to use for this client</param> /// <param name="logger">Custom logger to use with this client. Use null for default logger.</param> public IMAPClient(IMAPConfig config, IMAPLogger logger, int maxWorkers) { _config = config; _imap = new IMAP(); _logger = logger ?? new IMAPLogger(config); //_imap.InfoLogged += Log; _imap.Logger = _logger; _folders = new IMAPFolderCollection(); Log(IMAPBase.LogTypeEnum.IMAP, "------------------------------------------------------"); Log(IMAPBase.LogTypeEnum.INFO, "InterIMAP Client Initialized"); if (config.CacheFile != String.Empty) { this.UsingCache = true; Log(IMAPBase.LogTypeEnum.INFO, String.Format("Using Local Cache File: {0}", config.CacheFile)); } if (config.AutoLogon) { Logon(); } if (UsingCache) { FileInfo finfo = new FileInfo(config.CacheFile); if (finfo.Exists) { // this config has a cache file specified. Load the cache into the object model LoadCache(); if (!OfflineMode && config.AutoSyncCache) { SyncCache(); } } else { _folders.Clear(); _folders = _imap.ProcessFolders(_config.DefaultFolderName); //IMAPFolderCollection tempFolders = _imap.ProcessFolders(_config.DefaultFolderName); foreach (IMAPFolder f in _folders) { f.SetClient(this); if (_config.AutoGetMsgID) { f.GetMessageIDs(false); } } BuildNewCache(); } } }
/// <summary> /// Login using currently specified connection settings. Called automatically if AutoLogon is true. /// </summary> public void Logon() { if (this.LoggedOn || this._config == null) { return; } if (!_imap.Login(_config.Host, _config.UserName, _config.Password, _config.UseSSL)) { if (!UsingCache) { Log(IMAPBase.LogTypeEnum.ERROR, "Cannot connect to server and no cache is available. System cannot proceed. Quiting..."); throw new IMAPException(IMAPException.IMAPErrorEnum.IMAP_ERR_CONNECT); } OfflineMode = true; Log(IMAPBase.LogTypeEnum.WARN, "Login Failed. Switching to Offline Mode"); return; } Log(IMAPBase.LogTypeEnum.INFO, "Login Successful"); if (!UsingCache) { XmlDocument doc = new XmlDocument(); _folders.Clear(); _folders = _imap.ProcessFolders(_config.DefaultFolderName); foreach (IMAPFolder f in _folders) { f.SetClient(this); if (_config.AutoGetMsgID) { f.GetMessageIDs(false); } } } }