Beispiel #1
0
        private void DisconnectClientsIfNeeded()
        {
            try {
                _newMailHandler?.Cancel();

                if (_imapInboxIdler != null)
                {
                    _imapInboxIdler.CountChanged       -= ImapInboxIdlerOnCountChanged;
                    _imapInboxIdler.MessageExpunged    -= ImapInboxIdlerOnMessageExpunged;
                    _imapInboxIdler.UidValidityChanged -= ImapInboxIdlerOnUidValidityChanged;
                }

                _imapInboxIdler?.Dispose();
                _imapInboxIdler = null;

                if (_imapIdlerTask != null && _imapIdlerTask.IsCanceled)
                {
                    _imapIdlerTask?.Dispose();
                }

                _imapClient?.Dispose();
                _imapClient = null;

                _smtpClient?.Dispose();
                _smtpClient = null;
            } catch (Exception e) {
                _config.Tracer?.TraceError($"An error has occured while disconnecting clients - {e}", $"{this}");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Start to listen for events from the imap server and publish new message events when needed
        /// </summary>
        /// <remarks>This does not blocks the thread and it can throw exception</remarks>
        /// <exception cref="Exception"></exception>
        public void StartListening()
        {
            if (_imapIdlerTask != null)
            {
                throw new Exception($"{this}: Use {nameof(StopListening)} to stop listening before trying to {nameof(StartListening)}");
            }

            _config.Tracer?.TraceVerbose($"{nameof(StartListening)}", $"{this}");

            DisconnectClientsIfNeeded();

            _imapInboxIdler = new ImapInboxIdler(_config);
            _imapClient     = new ImapInboxClient(_config);
            _smtpClient     = new SmtpBasicClient(_config);

            ConnectClients();

            SynchronizeMailCount(_imapClient.Count());
        }
Beispiel #3
0
 internal MailActuator(ImapInboxClient imapClient, SmtpBasicClient smtpClient) : base(smtpClient)
 {
     _imapClient = imapClient;
 }