Exemplo n.º 1
0
        public void ReadInboxEmails()
        {
            var imapSettings  = SettingsBuilder.GetImapSettingsFromCompany(_company);
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(_company);
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

            var emailProcessing = new EmailProcessingService(_log, _dbFactory,
                                                             emailService,
                                                             actionService,
                                                             _company,
                                                             _time);

            IList <IEmailRule> inboxRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(_log, _time),
                new AddMatchIdsEmailRule(_log, _time),
                new SetAnswerIdEmailRule(_log, _time), //NOTE: also using in Inbox for processing Amazon autocommunicate emails
                //new FeedbackBlackListEmailRule(_log, _time),
                new ReturnRequestEmailRule(_log, _time, emailService, actionService, _company, true, false),
                new OrderDeliveryInquiryEmailRule(_log, _time, emailService, actionService),
                new AddressNotChangedEmailRule(_log, _time, emailService, actionService),
                //new DhlInvoiceEmailRule(_log, _time, _dbFactory),
                //new AddCommentEmailRule(_log, actionService, _time),
                new PrepareBodyEmailRule(_log, _time),
            };

            var email = new EmailReaderService(imapSettings, _log, _dbFactory, _time);

            email.ReadEmails(EmailHelper.InboxFolder, DateTime.Now.AddDays(-5), imapSettings.AcceptingToAddresses, null, null);
            emailProcessing.ProcessEmails(email.EmailProcessResultList, inboxRules);
        }
Exemplo n.º 2
0
        public void ReadSentEmails()
        {
            var imapSettings  = SettingsBuilder.GetImapSettingsFromCompany(_company);
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(_company);
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

            var emailProcessing = new EmailProcessingService(_log, _dbFactory,
                                                             emailService,
                                                             actionService,
                                                             _company,
                                                             _time);

            IList <IEmailRule> sentRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(_log, _time),
                new AddMatchIdsEmailRule(_log, _time),
                new SetAnswerIdEmailRule(_log, _time),
                new SetSentByEmailRule(_log, _time)
            };

            var email = new EmailReaderService(imapSettings, _log, _dbFactory, _time);

            email.ReadEmails(EmailHelper.SentFolder, DateTime.Now.AddDays(-15), null, imapSettings.AcceptingToAddresses, null);
            emailProcessing.ProcessEmails(email.EmailProcessResultList, sentRules);
        }
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        log       = GetLogger();

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }
            var time              = new TimeService(dbFactory);
            var addressService    = AddressService.Default;
            var emailImapSettings = SettingsBuilder.GetImapSettingsFromCompany(company,
                                                                               Int32.Parse(AppSettings.Support_MaxProcessMessageErrorsCount),
                                                                               Int32.Parse(AppSettings.Support_ProcessMessageThreadTimeoutSecond));
            var emailSmtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailReaderService = new EmailReaderService(
                emailImapSettings,
                GetLogger(),
                dbFactory,
                time);
            var emailService  = new EmailService(log, emailSmtpSettings, addressService);
            var systemActions = new SystemActionService(log, time);


            var emailProcessingService = new EmailProcessingService(
                log,
                dbFactory,
                emailService,
                systemActions,
                company,
                time);

            //Inbox Folder
            emailReaderService.ReadEmails(EmailHelper.InboxFolder, null, emailImapSettings.AcceptingToAddresses, null, CancellationToken);
            IList <IEmailRule> inboxRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(log, time),
                new AddMatchIdsEmailRule(log, time),
                new SetAnswerIdEmailRule(log, time), //NOTE: also using in Inbox for processing Amazon autocommunicate emails
                new CancellationEmailRule(log, time, emailService, systemActions, company),
                new RemoveSignatureEmailRule(log, time, emailService, systemActions),
                new FeedbackBlackListEmailRule(log, time),
                new ReturnRequestEmailRule(log, time, emailService, systemActions, company, true, false),
                new OrderDeliveryInquiryEmailRule(log, time, emailService, systemActions),
                new AddressNotChangedEmailRule(log, time, emailService, systemActions),
                new DhlInvoiceEmailRule(log, time, dbFactory),
                new AddCommentEmailRule(log, systemActions, time),
                new PrepareBodyEmailRule(log, time),
            };

            emailProcessingService.ProcessEmails(emailReaderService.EmailProcessResultList, inboxRules);

            //Sent Folder
            emailReaderService.ReadEmails(EmailHelper.SentFolder, null, null, emailImapSettings.AcceptingToAddresses, CancellationToken);
            IList <IEmailRule> sentRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(log, time),
                new AddMatchIdsEmailRule(log, time),
                new SetAnswerIdEmailRule(log, time),
                new SetSentByEmailRule(log, time)
            };

            emailProcessingService.ProcessEmails(emailReaderService.EmailProcessResultList, sentRules);

            //Update Settings
            var settingService = new SettingsService(dbFactory);

            using (var db = dbFactory.GetRWDb())
            {
                settingService.SetUnansweredMessageCount(db.Emails.GetUnansweredEmailCount());
            }
        }