예제 #1
0
        public virtual async Task Setup()
        {
            SetupInProgress = true;
            
            Trace.WriteLine($"{MailBoxName} starting setup");

            int retryTime = 5000;

            //if setup fails let's try again soon
            while (!await SetupClients())
            {
                Trace.WriteLine($"{MailBoxName} SetupClients failed - retry time is: {retryTime / 1000} seconds");
                await Task.Delay(retryTime);

                if (retryTime < 160000)
                {
                    retryTime = retryTime*2;
                }
            }

            Trace.WriteLine(MailBoxName + " SetupClients finished");

            retryTime = 5000;

            Freshening = false;

            //make worker get initial list of messages and then start idling
            while (!await FreshenMailBox())
            {
                Trace.WriteLine($"{MailBoxName} FreshenMailBox failed - retry time is: {retryTime/1000} seconds");
                await Task.Delay(retryTime);

                if (retryTime < 160000)
                {
                    retryTime = retryTime*2;
                }
            }

            while (!SetupEvents())
            {
                Trace.WriteLine($"{MailBoxName} SetupEvents failed - retry time is: {retryTime / 1000} seconds");
                await Task.Delay(retryTime);

                if (retryTime < 160000)
                {
                    retryTime = retryTime*2;
                }
            }

            Trace.WriteLine($"{MailBoxName} FreshMailBox finished");

            //get folders TODO: do we need this?
            //EmailFolders = await _imapWorker.GetMailFolders();

            //setup email filterer
            _emailFilterer = new EmailFilterer(this);

            //filter all new messages
            #pragma warning disable 4014
            Task.Run(async () =>
            {
                await Task.Delay(30000);
                await _emailFilterer.FilterAllMessages(EmailList);
            }).ConfigureAwait(false);
            #pragma warning restore 4014
            
            WorkerStartTime = DateTime.Now;
            IdlerStartTime = DateTime.Now;

            SetupInProgress = false;
        }
예제 #2
0
        public void Dispose()
        {
            Trace.WriteLine($"{MailBoxName} Dispose Called");

            _imapIdler.MessageArrived -= ImapIdlerOnMessageArrived;
            _imapIdler.MessageExpunged -= ImapIdlerOnMessageExpunged;
            _imapIdler.MessageSeen -= ImapIdlerOnMessageSeen;
            _emailSender.ExceptionHappened -= EmailSenderOnExceptionHappened;
            _imapIdler.IntegrityCheck -= ImapIdlerOnIntegrityCheck;

            NewMessageReceived = null;
            MessageRemoved = null;

            _imapWorker = null;
            _imapIdler = null;
            _emailSender = null;
            _emailFilterer = null;
            _mbLogger = null;
            _config = null;
            logger = null;
        }