Esempio n. 1
0
        public override void DeleteMailGroup(int mailgroupId, IMailServerFactory factory)
        {
            if (mailgroupId < 0)
            {
                throw new ArgumentException("mailgroup_id has negative value");
            }

            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            var mailgroup = GetMailGroup(mailgroupId, factory);

            if (mailgroup == null)
            {
                throw new ArgumentException("Mailgroup is missing");
            }

            using (var dbContextWithTran = TeamlabMailGroupDal.CreateMailDbContext(true))
            {
                TeamlabMailGroupDal.DeleteMailGroup(mailgroup.Id, dbContextWithTran.DbManager);
                _DeleteMailGroup(new MailGroupBase(mailgroup));
                dbContextWithTran.CommitTransaction();
            }
        }
        public void AddMember(int mailboxAddressId, IMailServerFactory factory)
        {
            if (mailboxAddressId < 0)
            {
                throw new ArgumentException("Negative parameter value", "mailboxAddressId");
            }

            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            MailAddressDto addressDto;

            using (var dbContextWithTran = TeamlabMailGroupDal.CreateMailDbContext(true))
            {
                addressDto = TeamlabAddressDal.GetMailAddress(mailboxAddressId, dbContextWithTran.DbManager);

                if (addressDto == null)
                {
                    throw new ArgumentException("Address not exists");
                }

                if (Address.Domain.Tenant != addressDto.domain.tenant)
                {
                    throw new ArgumentException("Address not belongs to this domain");
                }

                if (InAddresses.Any(addr => addr.Id == mailboxAddressId))
                {
                    throw new ArgumentException("Address already exists");
                }

                var mailboxAddress = new MailAddressBase(addressDto.name, new WebDomainBase(addressDto.domain.name));

                TeamlabMailGroupDal.AddAddressToMailGroup(Id, mailboxAddressId, dbContextWithTran.DbManager);
                _AddMember(mailboxAddress);
                dbContextWithTran.CommitTransaction();
            }

            InAddresses.Add(factory.CreateMailAddress(addressDto.id, addressDto.tenant, addressDto.name,
                                                      factory.CreateWebDomain(addressDto.domain.id,
                                                                              addressDto.domain.tenant,
                                                                              addressDto.domain.name,
                                                                              addressDto.domain.is_virified,
                                                                              Server)));
        }
Esempio n. 3
0
        public override ICollection <IMailGroup> GetMailGroups(IMailServerFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            var tlGroups = TeamlabMailGroupDal.GetMailGroups();

            var serverGroups = _GetMailGroups(tlGroups.Select(g => g.address.ToString()).ToList());

            return((serverGroups.Select(
                        serverGroup => tlGroups.First(g => g.address.ToString() == serverGroup.Address.ToString()))
                    .Select(tlGroup => new
            {
                tlGroup,
                domain =
                    factory.CreateWebDomain(tlGroup.address.domain.id,
                                            tlGroup.address.domain.tenant,
                                            tlGroup.address.domain.name,
                                            tlGroup.address.domain.is_virified, this)
            }).Select(@t => new
            {
                @t,
                address =
                    factory.CreateMailAddress(@t.tlGroup.address.id,
                                              @t.tlGroup.address.tenant,
                                              @t.tlGroup.address.name,
                                              @t.domain)
            }).Select(@t => new
            {
                @t,
                groupInAddresses =
                    @[email protected](
                        a =>
                        factory.CreateMailAddress(a.id, a.tenant, a.name,
                                                  @[email protected]))
                    .ToList()
            })
                    .Select(
                        @t =>
                        factory.CreateMailGroup(@t.@[email protected], @t.@[email protected]_tenant,
                                                @[email protected], @t.groupInAddresses.ToList(), this)))
                   .ToList());
        }
        public ICollection <IMailAddress> GetMembers(IMailServerFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            var server_addresses = _GetMembers();
            var tl_addresses     = TeamlabMailGroupDal.GetGroupAddresses(Id);

            return((from tl_address in tl_addresses
                    let address_for_update = server_addresses.FirstOrDefault(a => a.ToString() == tl_address.ToString())
                                             where address_for_update != null
                                             let domain =
                        factory.CreateWebDomain(tl_address.domain.id, tl_address.domain.tenant, tl_address.domain.name, tl_address.domain.is_virified, Server)
                        select factory.CreateMailAddress(tl_address.id, tl_address.tenant, tl_address.name, domain))
                   .ToList());
        }
Esempio n. 5
0
        public override IMailGroup GetMailGroup(int mailgroupId, IMailServerFactory factory)
        {
            if (mailgroupId < 0)
            {
                throw new ArgumentException("mailgroup_id has negative value");
            }

            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            var mailgroupDto = TeamlabMailGroupDal.GetMailGroup(mailgroupId);

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

            var mailgroupBase = _GetMailGroup(mailgroupDto.address.ToString());

            if (mailgroupBase == null)
            {
                throw new Exception("Mailgroup is missing on server");
            }

            var mailgroupDomain = factory.CreateWebDomain(mailgroupDto.address.domain.id, mailgroupDto.address.domain.tenant, mailgroupDto.address.domain.name, mailgroupDto.address.domain.is_virified, this);

            var mailgroupAddress = factory.CreateMailAddress(mailgroupDto.address.id, mailgroupDto.address.tenant, mailgroupDto.address.name, mailgroupDomain);

            var mailgroupAddresses =
                mailgroupDto.addresses
                .Select(alias =>
                        factory.CreateMailAddress(alias.id, alias.tenant, alias.name, mailgroupDomain))
                .ToList();

            var mailgroup = factory.CreateMailGroup(mailgroupDto.id, mailgroupDto.id_tenant,
                                                    mailgroupAddress, mailgroupAddresses.ToList(), this);

            return(mailgroup);
        }
        public void RemoveMember(int mailbox_address_id)
        {
            if (mailbox_address_id < 0)
            {
                throw new ArgumentException("Negative parameter value", "mailbox_address_id");
            }

            using (var db_context_with_tran = TeamlabMailGroupDal.CreateMailDbContext(true))
            {
                var address_dto = TeamlabAddressDal.GetMailAddress(mailbox_address_id, db_context_with_tran.DbManager);

                if (address_dto == null)
                {
                    throw new ArgumentException("Address not exists");
                }

                var mailbox_address = new MailAddressBase(address_dto.name, new WebDomainBase(address_dto.domain.name));

                TeamlabMailGroupDal.DeleteAddressFromMailGroup(Id, mailbox_address_id, db_context_with_tran.DbManager);
                _RemoveMember(mailbox_address);

                db_context_with_tran.CommitTransaction();
            }
        }
Esempio n. 7
0
        public override ICollection <IMailGroup> GetMailGroups(IMailServerFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            var tl_groups = TeamlabMailGroupDal.GetMailGroups();

            var server_groups = _GetMailGroups(tl_groups.Select(g => g.address.ToString()).ToList());

            var list_mail_groups = new List <IMailGroup>();

            foreach (var server_group in server_groups)
            {
                var tl_group = tl_groups.First(g => g.address.ToString() == server_group.Address.ToString());

                var domain =
                    factory.CreateWebDomain(tl_group.address.domain.id, tl_group.address.domain.tenant, tl_group.address.domain.name, tl_group.address.domain.is_virified, this);

                var address =
                    factory.CreateMailAddress(tl_group.address.id, tl_group.address.tenant, tl_group.address.name, domain);

                var group_in_addresses =
                    tl_group.addresses
                    .Select(a => factory.CreateMailAddress(a.id, a.tenant, a.name, domain))
                    .ToList();

                var mailgroup = factory.CreateMailGroup(tl_group.id, tl_group.id_tenant,
                                                        address, group_in_addresses.ToList(), this);

                list_mail_groups.Add(mailgroup);
            }

            return(list_mail_groups);
        }
Esempio n. 8
0
        public override IMailGroup CreateMailGroup(string groupName, IWebDomain domain, List <int> addressIds, IMailServerFactory factory)
        {
            if (string.IsNullOrEmpty(groupName))
            {
                throw new ArgumentNullException("groupName", "ServerModel::CreateMailGroup");
            }

            if (domain == null)
            {
                throw new ArgumentNullException("domain");
            }

            if (addressIds == null)
            {
                throw new ArgumentNullException("addressIds");
            }

            if (!addressIds.Any())
            {
                throw new ArgumentException("Empty address_ids list");
            }

            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            MailGroupDto mailgroupDto;

            using (var dbContextWithTran = TeamlabMailGroupDal.CreateMailDbContext(true))
            {
                var addressDtoList = TeamlabMailAddressDal.GetMailAddresses(addressIds, dbContextWithTran.DbManager);

                var addressBaseList =
                    addressDtoList
                    .Select(dto =>
                            new MailAddressBase(dto.name,
                                                new WebDomainBase(dto.domain.name)))
                    .ToList();

                var mailgroupBase = new MailGroupBase(new MailAddressBase(groupName, new WebDomainBase(domain)),
                                                      addressBaseList)
                {
                    Address = { DateCreated = DateTime.UtcNow }
                };

                mailgroupDto = TeamlabMailGroupDal.SaveMailGroup(mailgroupBase.Address.LocalPart,
                                                                 mailgroupBase.Address.DateCreated,
                                                                 domain.Id,
                                                                 domain.Name,
                                                                 domain.IsVerified,
                                                                 addressDtoList, dbContextWithTran.DbManager);
                _CreateMailGroup(mailgroupBase.Address, addressBaseList);

                dbContextWithTran.CommitTransaction();
            }

            var mailgroupAddress = factory.CreateMailAddress(mailgroupDto.address.id, mailgroupDto.address.tenant, mailgroupDto.address.name, domain);

            var inAddresses =
                mailgroupDto.addresses.Select(
                    addressDto => factory.CreateMailAddress(addressDto.id, addressDto.tenant, addressDto.name, domain))
                .ToList();

            var mailgroup = factory.CreateMailGroup(mailgroupDto.id, mailgroupDto.id_tenant,
                                                    mailgroupAddress, inAddresses.ToList(), this);

            return(mailgroup);
        }