/// <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> /// Default constructor. Requires to be initialized with an IMAPConfig instance /// </summary> /// <param name="config"></param> /// <param name="extraParams">Used to pass in the ID of the current message worker</param> public IMAPLogger(IMAPConfig config, params object[] extraParams) { _config = config; _debugLevel = config.DebugDetail; _workerID = -1; if (extraParams.Length > 0) { _workerID = Convert.ToInt32(extraParams[0]); } }
/// <summary> /// Creates a config object based on previously saved settings /// </summary> /// <param name="configFile"></param> public IMAPConfig(string configFile) { IMAPConfig c = new IMAPConfig(); Stream s = File.Open(configFile, FileMode.Open); BinaryFormatter b = new BinaryFormatter(); c = (IMAPConfig)b.Deserialize(s); this._host = c.Host; this._userName = c.UserName; this._password = c.Password; this._useSSL = c.UseSSL; this._defaultFolderName = c.DefaultFolderName; this._autoLogon = c.AutoLogon; this._debugMode = c.DebugMode; this._cacheFile = c.CacheFile; this._autoGetMsgID = c.AutoGetMsgID; this._autoSyncCache = c.AutoSyncCache; this._logFile = c.LogFile; this._debugDetail = c.DebugDetail; s.Close(); }
/// <summary> /// Default constructor. Only used for deserialization purposes. /// </summary> public IMAPClient() { _config = null; _imap = new IMAP(); _folders = new IMAPFolderCollection(); }