Exemplo n.º 1
0
 protected override void _RemoveMember(MailAddressBase address)
 {
     var group = _serverData.Groups.Find(g => g.Address.ToString().Equals(Address.ToString()));
     if (group.InAddresses.All(a => !Equals(address.ToString(), a.ToString())))
         throw new ArgumentException();
     group.InAddresses.Remove(address);
 }
Exemplo n.º 2
0
 protected override void _AddMember(MailAddressBase address)
 {
     var group = _serverData.Groups.Find(g => g.Address.ToString().Equals(Address.ToString()));
     if (group.InAddresses.Any(a => a.Equals(address)))
     {
         throw new DuplicateNameException("You want to add already existed address");
     }
     group.InAddresses.Add(address);
 }
Exemplo n.º 3
0
        protected override void _RemoveAlias(MailAddressBase aliasToRemove)
        {
            var removeMailboxAlias = new SqlDelete(AliasTable.name)
                .Where(AliasTable.Columns.address, aliasToRemove.ToString());

            var dbManager = new PostfixAdminDbManager(Server.Id, Server.ConnectionString);
            using (var db = dbManager.GetAdminDb())
            {
                db.ExecuteNonQuery(removeMailboxAlias);
            }
        }
Exemplo n.º 4
0
        public MailGroupBase(MailAddressBase address, List<MailAddressBase> inAddresses)
        {
            if (address == null)
                throw new ArgumentException("Invalid address", "address");

            if (inAddresses == null)
                throw new ArgumentException("Invalid aliases", "inAddresses");
            
            Address = address;
            InAddresses = inAddresses;
        }
Exemplo n.º 5
0
        protected override void _RemoveMember(MailAddressBase address)
        {
            using (var db = GetDb())
            {
                var members = _GetMembers(db);

                if (members.All(a => a.name != address.ToString()))
                    throw new ArgumentException("You want to remove nonexistent address");

                UpdateGroupMembers(db, members.Select(m => m.name).Where(m => m != address.ToString()));
            }
        }
Exemplo n.º 6
0
        public MailGroupBase(MailAddressBase address, List <MailAddressBase> in_addresses)
        {
            if (address == null)
            {
                throw new ArgumentException("Invalid address", "address");
            }

            if (in_addresses == null)
            {
                throw new ArgumentException("Invalid aliases", "in_addresses");
            }

            Address     = address;
            InAddresses = in_addresses;
        }
Exemplo n.º 7
0
        public MailboxBase(MailAccountBase account, MailAddressBase address, List<MailAddressBase> aliases)
        {
            if (account == null)
                throw new ArgumentException("Invalid account", "account");

            if (address == null)
                throw new ArgumentException("Invalid address", "address");

            if (aliases == null)
                throw new ArgumentException("Invalid aliases", "aliases");

            Account = account;
            Address = address;
            Aliases = aliases;
        }
Exemplo n.º 8
0
        protected override void _AddMember(MailAddressBase address)
        {
            using (var db = GetDb())
            {
                var members = _GetMembers(db);

                if (members.Any(a => a.name == address.ToString()))
                    throw new DuplicateNameException("You want to add already existed address");

                var membersAddresses = members.Select(m => m.name).ToList();
                membersAddresses.Add(address.ToString());

                UpdateGroupMembers(db, membersAddresses);
            }
        }
Exemplo n.º 9
0
        protected override void _AddAlias(MailAddressBase aliasToAdd)
        {
            var insertMailboxAlias = new SqlInsert(AliasTable.name)
                .InColumnValue(AliasTable.Columns.address, aliasToAdd.ToString())
                .InColumnValue(AliasTable.Columns.redirect, Address.ToString())
                .InColumnValue(AliasTable.Columns.domain, aliasToAdd.Domain.Name)
                .InColumnValue(AliasTable.Columns.created, aliasToAdd.DateCreated)
                .InColumnValue(AliasTable.Columns.modified, aliasToAdd.DateCreated)
                .InColumnValue(AliasTable.Columns.active, true)
                .InColumnValue(AliasTable.Columns.is_group, false);

            var dbManager = new PostfixAdminDbManager(Server.Id, Server.ConnectionString);
            using (var db = dbManager.GetAdminDb())
            {
                 db.ExecuteNonQuery(insertMailboxAlias);
            }
        }
Exemplo n.º 10
0
        public MailboxBase(MailAccountBase account, MailAddressBase address, List <MailAddressBase> aliases)
        {
            if (account == null)
            {
                throw new ArgumentException("Invalid account", "account");
            }

            if (address == null)
            {
                throw new ArgumentException("Invalid address", "address");
            }

            if (aliases == null)
            {
                throw new ArgumentException("Invalid aliases", "aliases");
            }

            Account = account;
            Address = address;
            Aliases = aliases;
        }
Exemplo n.º 11
0
        protected override MailGroupBase _CreateMailGroup(MailAddressBase address, List<MailAddressBase> mailboxAddressList)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address", "MockServer::_CreateMailGroup");
            }

            if (_serverData.Groups.Any(r => r.Address.ToString().Equals(address.ToString())))
            {
                throw new ArgumentException();
            }

            var resultGroup =  new MailGroupBase(address, mailboxAddressList);
            _serverData.Groups.Add(resultGroup);
            return resultGroup;
        }
Exemplo n.º 12
0
        public IMailAddress AddAlias(string aliasName, IWebDomain domain, IMailServerFactory factory)
        {
            if (Aliases.Any(a => a.LocalPart == aliasName && a.Domain.Id == domain.Id))
                throw new DuplicateNameException("You want to add already existed alias");

            var addressBase = new MailAddressBase(aliasName, new WebDomainBase(domain))
                {
                    DateCreated = DateTime.UtcNow.ToDbStyle()
                };

            MailAddressDto aliasDto;
            using (var dbContextWithTran = TeamlabMailboxDal.CreateMailDbContext(true))
            {
                if (TeamlabAddressDal.IsAddressAlreadyRegistered(aliasName, domain.Name, dbContextWithTran.DbManager))
                    throw new DuplicateNameException("You want to add already existed alias");

                aliasDto = TeamlabAddressDal.AddMailboxAlias(Id, aliasName, addressBase.DateCreated,
                                                              domain.Id, domain.Name, domain.IsVerified, dbContextWithTran.DbManager);
                _AddAlias(addressBase);

                dbContextWithTran.CommitTransaction();
            }

            var alias = factory.CreateMailAddress(aliasDto.id, aliasDto.tenant, addressBase.LocalPart, domain);

            Aliases.Add(alias);

            return alias;
        }
Exemplo n.º 13
0
 protected abstract void _RemoveAlias(MailAddressBase aliasToRemove);
Exemplo n.º 14
0
 protected abstract void _AddAlias(MailAddressBase aliasToAdd);
Exemplo n.º 15
0
 protected abstract MailGroupBase _CreateMailGroup(MailAddressBase address, List<MailAddressBase> mailboxAddressList);
Exemplo n.º 16
0
 protected override void _RemoveAlias(MailAddressBase aliasToRemove)
 {
     var mailbox = _serverData.Mailboxes.Find(m => m.Address.ToString().Equals(Address.ToString()));
     mailbox.Aliases.Remove(aliasToRemove);
 }
Exemplo n.º 17
0
 protected abstract void _AddMember(MailAddressBase address);
Exemplo n.º 18
0
        protected override MailGroupBase _CreateMailGroup(MailAddressBase address, List<MailAddressBase> mailboxAddressList)
        {
            var creationDate = DateTime.UtcNow;

            var membersString = string.Join(",", mailboxAddressList.Select(addr => addr.ToString()));

            var insertAddresses = new SqlInsert(AliasTable.name)
                .InColumns(AliasTable.Columns.address, AliasTable.Columns.redirect, AliasTable.Columns.domain,
                           AliasTable.Columns.modified,
                           AliasTable.Columns.created, AliasTable.Columns.active, AliasTable.Columns.is_group)
                .Values(address.ToString(), membersString, address.Domain.Name, creationDate, creationDate, true, true);

            try
            {
                using (var db = _dbManager.GetAdminDb())
                {
                    db.ExecuteNonQuery(insertAddresses);
                }
            }
            catch (MySqlException ex)
            {
                if (ex.Message.StartsWith("Duplicate entry"))
                    throw new ArgumentException("You want to create already existing group");

                throw;
            }

            return new MailGroupBase(address, mailboxAddressList);
        }
Exemplo n.º 19
0
        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)));
        }
Exemplo n.º 20
0
 protected abstract void _RemoveMember(MailAddressBase address);
Exemplo n.º 21
0
        public void RemoveMember(int mailboxAddressId)
        {
            if (mailboxAddressId < 0)
                throw new ArgumentException("Negative parameter value", "mailboxAddressId");

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

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

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

                TeamlabMailGroupDal.DeleteAddressFromMailGroup(Id, mailboxAddressId, dbContextWithTran.DbManager);
                _RemoveMember(mailboxAddress);

                dbContextWithTran.CommitTransaction();
            }
        }