static public IEmailImapSettings GetImapSettingsFromCompany(CompanyDTO company)
        {
            var settings = new EmailImapSettings();

            if (company == null)
            {
                return(settings);
            }

            var smtpSettings = company.EmailAccounts.FirstOrDefault(e => e.Type == (int)EmailAccountType.Imap);

            if (smtpSettings == null)
            {
                return(settings);
            }

            settings.ImapHost     = smtpSettings.ServerHost;
            settings.ImapPort     = smtpSettings.ServerPort;
            settings.ImapUsername = smtpSettings.UserName;
            settings.ImapPassword = smtpSettings.Password;

            settings.AcceptingToAddresses = (smtpSettings.AcceptingToAddresses ?? "").Split(";,".ToCharArray(),
                                                                                            StringSplitOptions.RemoveEmptyEntries);

            settings.MaxProcessMessageErrorsCount = Int32.Parse(AppSettings.Support_MaxProcessMessageErrorsCount);
            settings.ProcessMessageThreadTimeout  = TimeSpan.FromSeconds(Int32.Parse(AppSettings.Support_ProcessMessageThreadTimeoutSecond));

            settings.AttachmentFolderPath        = smtpSettings.AttachmentDirectory;
            settings.AttachmentFolderRelativeUrl = smtpSettings.AttachmentFolderRelativeUrl;

            settings.IsDebug = AppSettings.IsDebug;

            return(settings);
        }
        public static IEmailImapSettings GetImapSettingsFromCompany(CompanyDTO company,
                                                                    int maxProcessMessageErrorsCount,
                                                                    int processMessageThreadTimeoutSecond)
        {
            var emailAccount = company.EmailAccounts.FirstOrDefault(a => a.Type == (int)EmailAccountType.Imap);

            if (emailAccount == null)
            {
                return(null);
            }

            var settings = new EmailImapSettings();

            settings.ImapHost     = emailAccount.ServerHost;
            settings.ImapPort     = emailAccount.ServerPort;
            settings.ImapUsername = emailAccount.UserName;
            settings.ImapPassword = emailAccount.Password;

            settings.AcceptingToAddresses = (emailAccount.AcceptingToAddresses ?? "").Split(";,".ToCharArray(),
                                                                                            StringSplitOptions.RemoveEmptyEntries);

            settings.MaxProcessMessageErrorsCount = maxProcessMessageErrorsCount;
            settings.ProcessMessageThreadTimeout  = TimeSpan.FromSeconds(processMessageThreadTimeoutSecond);

            settings.AttachmentFolderPath        = emailAccount.AttachmentDirectory;
            settings.AttachmentFolderRelativeUrl = emailAccount.AttachmentFolderRelativeUrl;

            return(settings);
        }
        static public IEmailImapSettings GetImapSettingsFromAppSettings()
        {
            var settings = new EmailImapSettings();

            settings.ImapHost     = AppSettings.Support_ServerHost;
            settings.ImapPort     = Int32.Parse(AppSettings.Support_ServerPort);
            settings.ImapUsername = AppSettings.Support_EmailUsername;
            settings.ImapPassword = AppSettings.Support_EmailPassword;

            settings.MaxProcessMessageErrorsCount = Int32.Parse(AppSettings.Support_MaxProcessMessageErrorsCount);
            settings.ProcessMessageThreadTimeout  = TimeSpan.FromSeconds(Int32.Parse(AppSettings.Support_ProcessMessageThreadTimeoutSecond));

            settings.AttachmentFolderPath        = AppSettings.Support_AttachmentDirectory;
            settings.AttachmentFolderRelativeUrl = AppSettings.Support_AttachmentFolderRelativeUrl;

            settings.IsDebug = AppSettings.IsDebug;

            return(settings);
        }