/// <summary>
        /// Synchronizes email messages.
        /// </summary>
        /// <param name="syncAction">Sync action for <see cref="Envelope"/> instance.</param>
        /// <param name="crmFolders">Specific directories to synchronize.</param>
        /// <param name="loadAll">Defines the need to download all messages.</param>
        public void SyncMailMessages(Func <MailMessage, Envelope, bool, string, bool> syncAction, Dictionary <string, List <Guid> > crmFolders, bool loadAll = true)
        {
            SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(_userConnection);

            try {
                if (loadAll)
                {
                    _log.Info(string.Format("[{0}] | Loading emails from all folders", _currentMailboxName));
                    SyncAllFolders(syncAction, crmFolders);
                }
                else
                {
                    _log.Info(string.Format("[{0}] | Loading emails from selected folders", _currentMailboxName));
                    SyncSelectedFolders(syncAction, crmFolders);
                }
                helper.CleanUpSynchronizationError(_currentMailboxName);
            } catch (Exception ex) {
                helper.ProcessSynchronizationError(_currentMailboxName, ex);
                if (ex is MailBeeException)
                {
                    throw new ImapException(LocSyncError.ToString(), ex);
                }
                throw ex;
            }
        }
Exemple #2
0
        private IImapClient GetImapClient(string mailServerUId, string mailboxName, string mailboxPassword)
        {
            var currentMailServer = new Terrasoft.Configuration.MailServer(UserConnection);

            if (!currentMailServer.FetchFromDB(mailServerUId) || !currentMailServer.GetTypedColumnValue <bool>("AllowEmailDownloading"))
            {
                return(null);
            }
            var imapServerCredentials = new MailCredentials {
                Host         = currentMailServer.GetTypedColumnValue <string>("Address"),
                Port         = currentMailServer.GetTypedColumnValue <int>("Port"),
                UseSsl       = currentMailServer.GetTypedColumnValue <bool>("UseSSL"),
                StartTls     = currentMailServer.GetTypedColumnValue <bool>("IsStartTls"),
                UserName     = mailboxName,
                UserPassword = mailboxPassword
            };
            SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(UserConnection);

            try {
                return(ClassFactory.Get <IImapClient>("OldEmailIntegration",
                                                      new ConstructorArgument("credentials", imapServerCredentials),
                                                      new ConstructorArgument("errorMessages", new Terrasoft.Mail.ImapErrorMessages()),
                                                      new ConstructorArgument("userConnection", UserConnection),
                                                      new ConstructorArgument("login", true)));
            } catch (Exception ex) {
                helper.ProcessSynchronizationError(mailboxName, ex, true);
                throw;
            }
        }
Exemple #3
0
        private ImapClient GetImapClient(string mailServerUId, string mailboxName, string mailboxPassword)
        {
            var currentMailServer = new Terrasoft.Configuration.MailServer(UserConnection);

            if (!currentMailServer.FetchFromDB(mailServerUId) || !currentMailServer.GetTypedColumnValue <bool>("AllowEmailDownloading"))
            {
                return(null);
            }
            var imapServerCredentials = new MailCredentials {
                Host         = currentMailServer.GetTypedColumnValue <string>("Address"),
                Port         = currentMailServer.GetTypedColumnValue <int>("Port"),
                UseSsl       = currentMailServer.GetTypedColumnValue <bool>("UseSSL"),
                StartTls     = currentMailServer.GetTypedColumnValue <bool>("IsStartTls"),
                UserName     = mailboxName,
                UserPassword = mailboxPassword
            };
            ImapClient imapClient;
            SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(UserConnection);

            try {
                imapClient = new ImapClient(imapServerCredentials, MailSynchronizer.GetImapErrorMessages(UserConnection), UserConnection, true);
            } catch (Exception ex) {
                helper.ProcessSynchronizationError(mailboxName, ex, true);
                throw;
            }
            return(imapClient);
        }
Exemple #4
0
 /// <summary>
 /// It represents a class for performing synchronization operations on objects.
 /// </summary>
 /// <param name="userConnection">User connection.</param>
 /// <param name="senderEmailAddress">Sender email address.</param>
 public ExchangeAppointmentSyncProvider(UserConnection userConnection, string senderEmailAddress)
     : base(ExchangeConsts.AppointmentStoreId, userConnection.CurrentUser.TimeZone, senderEmailAddress)
 {
     UserSettings = new AppointmentExchangeSettings(userConnection, senderEmailAddress);
     SetVersion(userConnection);
     ActivityCategoryId = ExchangeConsts.ActivityMeetingCategoryId;
     _userConnection    = userConnection;
     _syncErrorHelper   = SynchronizationErrorHelper.GetInstance(userConnection);
 }
Exemple #5
0
 /// <summary>
 /// Initialize new instance of <see cref="ExchangeContactSyncProviderImpl" /> with passed <paramref name="settings"/>.
 /// </summary>
 /// <param name="userConnection"><see cref="UserConnection"/> instance.</param>
 /// <param name="senderEmailAddress">Sender email address.</param>
 /// <param name="settings"><see cref="ContactExchangeSettings"/> instance.</param>
 public ExchangeContactSyncProviderImpl(UserConnection userConnection, string senderEmailAddress,
                                        ContactExchangeSettings settings = null) :
     base(ExchangeConsts.ExchangeContactStoreId, userConnection.CurrentUser.TimeZone, senderEmailAddress)
 {
     _userConnection  = userConnection;
     UserSettings     = settings ?? new ContactExchangeSettings(userConnection, senderEmailAddress);
     Version          = UserSettings.LastSyncDate;
     AccountsMap      = new Dictionary <string, Guid>();
     _syncErrorHelper = SynchronizationErrorHelper.GetInstance(userConnection);
 }
Exemple #6
0
 /// <summary>
 /// Initialize new instance of <see cref="ExchangeEmailSyncProvider" /> with passed synchronization settings.
 /// </summary>
 /// <param name="userConnection"><see cref="UserConnection"/> instance.</param>
 /// <param name="senderEmailAddress">Sender email address.</param>
 /// <param name="userSettings"><see cref="EmailExchangeSettings"/> instance.</param>
 public ExchangeEmailSyncProvider(UserConnection userConnection, string senderEmailAddress, EmailExchangeSettings userSettings = null)
     : base(new Guid(EmailStoreId), userConnection.CurrentUser.TimeZone, senderEmailAddress)
 {
     _userConnection            = userConnection;
     UserSettings               = userSettings ?? new EmailExchangeSettings(userConnection, senderEmailAddress);
     Version                    = UserSettings.LastSyncDate;
     _lastSyncDateMinutesOffset = UserSettings.LastSyncDateMinutesOffset;
     InitSyncSessionId();
     _syncErrorHelper = SynchronizationErrorHelper.GetInstance(userConnection);
 }
Exemple #7
0
        /// <summary>
        /// Sends e-mail message <paramref name="emailMessage"/>.
        /// </summary>
        /// <param name="emailMessage">E-mail message.</param>
        /// <param name="ignoreRights">Flag that indicates whether to ignore rights.</param>
        public virtual void Send(EmailMessage emailMessage, bool ignoreRights = false)
        {
            SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(_userConnection);

            try {
                IEmailClient emailClient = _emailClientFactory
                                           .CreateEmailClient(emailMessage.From.ExtractEmailAddress(), ignoreRights);
                emailClient.Send(emailMessage, ignoreRights);
                ClearSyncError(helper, emailClient, emailMessage.From);
            } catch (Exception ex) {
                helper.ProcessSynchronizationError(emailMessage.From, ex);
                throw;
            }
        }
Exemple #8
0
 /// <summary>
 /// Returns inited <see cref="ExchangeTaskSyncProvider"/> instance.
 /// </summary>
 /// <param name="userConnection">User connection.</param>
 /// <param name="senderEmailAddress">Sender email address.</param>
 /// <param name="settings"><see cref="ActivityExchangeSettings"/> instance.</param>
 public ExchangeTaskSyncProvider(UserConnection userConnection, string senderEmailAddress, ActivityExchangeSettings settings = null)
     : base(ExchangeConsts.ExchangeTaskStoreId, userConnection.CurrentUser.TimeZone, senderEmailAddress)
 {
     _userConnection = userConnection;
     UserSettings    = settings ?? new TaskExchangeSettings(userConnection, senderEmailAddress);
     if (UserSettings.LastSyncDate < UserSettings.ImportActivitiesFrom)
     {
         Version = UserSettings.ImportActivitiesFrom;
     }
     else
     {
         Version = UserSettings.LastSyncDate;
     }
     ActivityCategoryId = ExchangeConsts.ActivityTaskCategoryId;
     _syncErrorHelper   = SynchronizationErrorHelper.GetInstance(userConnection);
 }
        /// <summary>
        /// Returns <see cref="CredentialsValidationInfo"/> instance.
        /// </summary>
        /// <param name="exception"><see cref="Exception"/> instance.</param>
        /// <param name="senderEmailAddress"><see cref="MailboxSyncSettings"/> instance address.</param>
        /// <returns><see cref="CredentialsValidationInfo"/> instance.</returns>
        private CredentialsValidationInfo GetCredentialsValidationErrorInfo(Exception exception, string senderEmailAddress)
        {
            var validationInfo = new CredentialsValidationInfo()
            {
                IsValid = false
            };
            string exceptionClassName         = exception.GetType().ToString();
            string exceptionMessage           = exception.Message;
            SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(UserConnection);
            Entity message = helper.GetExceptionMessage(exceptionClassName, exceptionMessage);

            if (message != null)
            {
                validationInfo.Message = string.Format(message.GetTypedColumnValue <string>("UserMessage"),
                                                       senderEmailAddress);
                validationInfo.Data = message.GetTypedColumnValue <string>("Action");
            }
            return(validationInfo);
        }
Exemple #10
0
        private IImapClient GetImapClientByMailboxId(string mailboxId, out string mailboxName)
        {
            mailboxName = string.Empty;
            var mailboxEntitySchema = UserConnection.EntitySchemaManager.GetInstanceByName("MailboxSyncSettings");
            var mailbox             = mailboxEntitySchema.CreateEntity(UserConnection);

            if (!mailbox.FetchFromDB(new Guid(mailboxId)))
            {
                return(null);
            }
            mailboxName = mailbox.GetTypedColumnValue <string>("UserName");
            var mailServerUId          = mailbox.GetTypedColumnValue <Guid>("MailServerId");
            var mailServerEntitySchema = UserConnection.EntitySchemaManager.GetInstanceByName("MailServer");
            var currentMailServer      = mailServerEntitySchema.CreateEntity(UserConnection);

            if (!currentMailServer.FetchFromDB(mailServerUId) || !currentMailServer.GetTypedColumnValue <bool>("AllowEmailDownloading"))
            {
                return(null);
            }
            var imapServerCredentials = new MailCredentials {
                Host               = currentMailServer.GetTypedColumnValue <string>("Address"),
                Port               = currentMailServer.GetTypedColumnValue <int>("Port"),
                UseSsl             = currentMailServer.GetTypedColumnValue <bool>("UseSSL"),
                UserName           = mailbox.GetTypedColumnValue <string>("UserName"),
                UserPassword       = mailbox.GetTypedColumnValue <string>("UserPassword"),
                StartTls           = currentMailServer.GetTypedColumnValue <bool>("IsStartTls"),
                SenderEmailAddress = mailbox.GetTypedColumnValue <string>("SenderEmailAddress"),
            };

            try {
                return(ClassFactory.Get <IImapClient>("OldEmailIntegration",
                                                      new ConstructorArgument("credentials", imapServerCredentials),
                                                      new ConstructorArgument("errorMessages", new Terrasoft.Mail.ImapErrorMessages()),
                                                      new ConstructorArgument("userConnection", UserConnection),
                                                      new ConstructorArgument("login", true)));
            } catch (Exception ex) {
                SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(UserConnection);
                helper.ProcessSynchronizationError(imapServerCredentials.SenderEmailAddress, ex, true);
                throw;
            }
        }
Exemple #11
0
        private ImapClient GetImapClientByMailboxId(string mailboxId, out string mailboxName)
        {
            mailboxName = string.Empty;
            var mailbox = new Terrasoft.Configuration.MailboxSyncSettings(UserConnection);

            if (!mailbox.FetchFromDB(new Guid(mailboxId)))
            {
                return(null);
            }
            mailboxName = mailbox.GetTypedColumnValue <string>("UserName");
            var mailServerUId     = mailbox.GetTypedColumnValue <Guid>("MailServerId");
            var currentMailServer = new Terrasoft.Configuration.MailServer(UserConnection);

            if (!currentMailServer.FetchFromDB(mailServerUId) || !currentMailServer.GetTypedColumnValue <bool>("AllowEmailDownloading"))
            {
                return(null);
            }
            var imapServerCredentials = new MailCredentials {
                Host               = currentMailServer.GetTypedColumnValue <string>("Address"),
                Port               = currentMailServer.GetTypedColumnValue <int>("Port"),
                UseSsl             = currentMailServer.GetTypedColumnValue <bool>("UseSSL"),
                UserName           = mailbox.GetTypedColumnValue <string>("UserName"),
                UserPassword       = mailbox.GetTypedColumnValue <string>("UserPassword"),
                StartTls           = currentMailServer.GetTypedColumnValue <bool>("IsStartTls"),
                SenderEmailAddress = mailbox.GetTypedColumnValue <string>("SenderEmailAddress"),
            };
            SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(UserConnection);
            ImapClient imapClient;

            try {
                imapClient = new ImapClient(imapServerCredentials, MailSynchronizer.GetImapErrorMessages(UserConnection), UserConnection, true);
            } catch (Exception ex) {
                helper.ProcessSynchronizationError(imapServerCredentials.SenderEmailAddress, ex, true);
                throw;
            }
            return(imapClient);
        }