Beispiel #1
0
        protected override void Do()
        {
            try
            {
                SetProgress((int?)MailOperationRemoveMailboxProgress.Init, "Setup tenant and user");

                CoreContext.TenantManager.SetCurrentTenant(_mailBox.Tenant);

                try
                {
                    SecurityContext.AuthenticateMe(_mailBox.Account.TeamlabAccount.ID);
                }
                catch
                {
                    // User was removed
                    SecurityContext.AuthenticateMe(Core.Configuration.Constants.CoreSystem);
                }

                var user = _mailBox.Account.TeamlabAccount.ID.ToString();

                SetProgress((int?)MailOperationRemoveMailboxProgress.RemoveFromDb, "Remove mailbox from Db");

                var groups = _mailServer.GetMailGroups(_mailServerFactory);

                var groupsContainsMailbox = groups.Where(g => g.InAddresses.Contains(_mailBox.Address))
                                            .Select(g => g);

                foreach (var mailGroup in groupsContainsMailbox)
                {
                    if (mailGroup.InAddresses.Count == 1)
                    {
                        _mailServer.DeleteMailGroup(mailGroup.Id, _mailServerFactory);
                    }
                    else
                    {
                        mailGroup.RemoveMember(_mailBox.Address.Id);
                    }
                }

                _mailServer.DeleteMailbox(_mailBox);

                SetProgress((int?)MailOperationRemoveMailboxProgress.RecalculateFolder, "Recalculate folders counters");

                _mailBoxManager.RecalculateFolders(_mailBox.Tenant, user);

                SetProgress((int?)MailOperationRemoveMailboxProgress.ClearCache, "Clear accounts cache");

                _mailBoxManager.CachedAccounts.Clear(user);
            }
            catch (Exception e)
            {
                Logger.Error("Mail operation error -> Remove mailbox: {0}", e);
                Error = "InternalServerError";
            }
        }
Beispiel #2
0
        public virtual void AliasAddAndRemoveSyncronizationWithServerTest()
        {
            peter_alias   = peter_mailbox.AddAlias(peter_alias.LocalPart, peter_alias.Domain, TestContext.ServerFactory);
            peter_mailbox = server.GetMailbox(peter_mailbox.Id, TestContext.ServerFactory);
            Assert.IsTrue(peter_mailbox.Aliases.Contains(peter_alias));

            peter_mailbox.RemoveAlias(peter_alias.Id);
            peter_mailbox = server.GetMailbox(peter_mailbox.Id, TestContext.ServerFactory);
            Assert.IsFalse(peter_mailbox.Aliases.Contains(peter_alias));
            server.DeleteMailbox(peter_mailbox);
        }
Beispiel #3
0
        public void Clean()
        {
            if (peter_mailbox != null)
            {
                server.DeleteMailbox(peter_mailbox);
                peter_mailbox = null;
            }

            if (peter_domain != null)
            {
                server.DeleteWebDomain(peter_domain, TestContext.ServerFactory);
                peter_domain = null;
            }
        }