Exemplo n.º 1
0
        /// <summary>
        /// Stops synchronization process for the specific sender email.
        /// </summary>
        /// <param name="senderEmailAddress">Sender email address.</param>
        /// <param name="serverTypeId">Mail server type identifier.</param>
        protected virtual void StopSyncProcess(string senderEmailAddress, Guid serverTypeId)
        {
            var parameters = new Dictionary <string, object> {
                { "SenderEmailAddress", senderEmailAddress },
                { "CurrentUserId", UserConnection.CurrentUser.Id }
            };

            MailSynchronizer.RemoveSyncJob(UserConnection, parameters);
        }
Exemplo n.º 2
0
        public virtual bool ScriptTask1Execute(ProcessExecutingContext context)
        {
                        #if !NETSTANDARD2_0 // TODO CRM-42546
            var secureText          = UserConnection.DataValueTypeManager.GetInstanceByName("SecureText") as SecureTextDataValueType;
            var currentUserId       = CurrentUserId != Guid.Empty ? CurrentUserId : UserConnection.CurrentUser.Id;
            EntitySchemaQuery query = new EntitySchemaQuery(UserConnection.EntitySchemaManager,
                                                            "MailboxSyncSettings");
            query.AddColumn("UserName");
            query.AddColumn("UserPassword");
            query.AddColumn("MailServer.Address");
            query.AddColumn("MailServer.Port");
            query.AddColumn("MailServer.UseSSL");
            query.AddColumn("MailServer.IsStartTls");
            query.AddColumn("SenderEmailAddress");
            query.Filters.Add(query.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                               "SysAdminUnit.Id", currentUserId));
            query.Filters.Add(query.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                               "MailServer.AllowEmailDownloading", true));
            query.Filters.Add(query.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                               "EnableMailSynhronization", true));
            query.Filters.Add(query.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                               "SenderEmailAddress", SenderEmailAddress));
            var select = query.GetSelectQuery(UserConnection);

            MailCredentials credentials = new MailCredentials();
            using (var dbExecutor = UserConnection.EnsureDBConnection()) {
                using (var reader = select.ExecuteReader(dbExecutor)) {
                    if (!reader.Read())
                    {
                        var parameters = new Dictionary <string, object> {
                            { "SenderEmailAddress", SenderEmailAddress },
                            { "CurrentUserId", currentUserId }
                        };
                        MailSynchronizer.RemoveSyncJob(UserConnection, parameters);
                        throw new ArgumentException("user does not have mail account");
                    }
                    credentials.UserName = reader.GetColumnValue <string>(reader.GetName(0));
                    string rawPassword = reader.GetColumnValue <string>(reader.GetName(1));
                    if (!rawPassword.IsNullOrEmpty())
                    {
                        credentials.UserPassword = secureText.GetValueForLoad(UserConnection, rawPassword).ToString();
                    }
                    credentials.Host               = reader.GetColumnValue <string>(reader.GetName(2));
                    credentials.Port               = reader.GetColumnValue <int>(reader.GetName(3));
                    credentials.UseSsl             = reader.GetColumnValue <bool>(reader.GetName(4));
                    credentials.StartTls           = reader.GetColumnValue <bool>(reader.GetName(5));
                    credentials.SenderEmailAddress = reader.GetColumnValue <string>(reader.GetName(6));
                }
            }
            using (var mailSynchronizer = new MailSynchronizer(UserConnection, credentials)) {
                mailSynchronizer.ValidateImapClient();
                mailSynchronizer.SyncImapMail();
            }
                        #endif
            return(true);
        }
Exemplo n.º 3
0
 public string CreateDeleteSyncJob(bool create, int interval)
 {
     try {
         if (create)
         {
             MailSynchronizer.CreateSyncJob(UserConnection, interval);
         }
         else
         {
             MailSynchronizer.RemoveSyncJob(UserConnection);
         }
     } catch (ImapException e) {
         return(e.Message);
     }
     return(string.Empty);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Stops synchronization process for the specific sender email.
 /// </summary>
 /// <param name="senderEmailAddress">Sender email address.</param>
 /// <param name="serverTypeId">Mail server type identifier.</param>
 protected override void StopSyncProcess(string senderEmailAddress, Guid serverTypeId)
 {
     if (serverTypeId == ExchangeConsts.ExchangeMailServerTypeId)
     {
         var exchangeUtility = ClassFactory.Get <IExchangeUtility>();
         exchangeUtility.RemoveAllSyncJob(UserConnection, senderEmailAddress, serverTypeId);
     }
     else
     {
         var parameters = new Dictionary <string, object> {
             { "SenderEmailAddress", senderEmailAddress },
             { "CurrentUserId", UserConnection.CurrentUser.Id }
         };
         MailSynchronizer.RemoveSyncJob(UserConnection, parameters);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Creates (or deletes, if necessary) Imap synchronization job.
        /// </summary>
        /// <param name="userConnection">User connection.</param>
        /// <param name="interval">Synchronization interval.</param>
        /// <param name="create">Determines if synchronization job creation is necessary.</param>
        /// <param name="senderEmailAddress">Sender email address.</param>
        private string CreateDeleteImapJob(UserConnection userConnection, int interval, bool create,
                                           string senderEmailAddress)
        {
            var parameters = new Dictionary <string, object> {
                { "SenderEmailAddress", senderEmailAddress },
                { "CurrentUserId", userConnection.CurrentUser.Id }
            };

            if (create)
            {
                MailSynchronizer.CreateSyncJob(userConnection, interval, parameters);
            }
            else
            {
                MailSynchronizer.RemoveSyncJob(userConnection, parameters);
            }
            return(string.Empty);
        }