public override ICollection <IMailbox> GetMailboxes(IMailServerFactory factory) { if (factory == null) { throw new ArgumentNullException("factory"); } var mailboxList = new List <IMailbox>(); using (var dbContext = TeamlabMailboxDal.CreateMailDbContext()) { var mailboxDtoList = TeamlabMailboxDal.GetMailboxes(dbContext.DbManager); var mailboxBaseList = _GetMailboxes(mailboxDtoList.ConvertAll(d => d.mailbox.address)); mailboxList.AddRange(from serverMailbox in mailboxBaseList let mailboxDto = mailboxDtoList.Find(d => d.mailbox.address == serverMailbox.Address.ToString()) let domain = factory.CreateWebDomain(mailboxDto.mailbox_address.domain.id, mailboxDto.mailbox_address.domain.tenant, mailboxDto.mailbox_address.domain.name, mailboxDto.mailbox_address.domain.is_virified, this) let mailboxAddress = factory.CreateMailAddress(mailboxDto.mailbox_address.id, mailboxDto.mailbox_address.tenant, mailboxDto.mailbox_address.name, domain) let aliasesDtoList = TeamlabMailAddressDal.GetMailboxAliases(mailboxDto.mailbox.id, dbContext.DbManager) let aliases = aliasesDtoList.Select(a => factory.CreateMailAddress(a.id, a.tenant, a.name, domain)).ToList() let teamlabAccount = CoreContext.Authentication.GetAccountByID(new Guid(mailboxDto.mailbox.user)) let account = factory.CreateMailAccount(teamlabAccount, serverMailbox.Account.Login) select factory.CreateMailbox(mailboxDto.mailbox.id, mailboxDto.mailbox.tenant, mailboxAddress, mailboxDto.mailbox.name, account, aliases.ToList(), this)); } return(mailboxList); }
public override ICollection <IWebDomain> GetWebDomains(IMailServerFactory factory) { if (factory == null) { throw new ArgumentNullException("factory"); } var domainsDtoList = TeamlabDomainDal.GetTenantDomains(); if (!domainsDtoList.Any()) { return(new Collection <IWebDomain>()); } var domainsBaseList = _GetWebDomains(domainsDtoList.ConvertAll(d => d.name)); var webDomains = domainsBaseList.Select(domainBase => { var domainDto = domainsDtoList.Find(dalDomain => dalDomain.name == domainBase.Name); var webdomain = factory.CreateWebDomain(domainDto.id, domainDto.tenant, domainDto.name, domainDto.is_virified, this); return(webdomain); }).OrderBy(obj => obj.Tenant).ToList(); return(webDomains); }
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 }; 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); }
public override IWebDomain GetWebDomain(int domainId, IMailServerFactory factory) { if (domainId < 0) { throw new ArgumentException("domain_id has negative value", "domainId"); } if (factory == null) { throw new ArgumentNullException("factory"); } var domainDto = TeamlabDomainDal.GetDomain(domainId); if (domainDto == null) { throw new Exception("Domain is missing"); } var domainBase = _GetWebDomain(domainDto.name); if (domainBase == null) { throw new Exception("Server domain is missing"); } var webdomain = factory.CreateWebDomain(domainDto.id, domainDto.tenant, domainDto.name, domainDto.is_virified, this); return(webdomain); }
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 override IMailbox GetMailbox(int mailboxId, IMailServerFactory factory) { if (mailboxId < 0) { throw new ArgumentException("mailbox_id has negative value"); } if (factory == null) { throw new ArgumentNullException("factory"); } MailboxWithAddressDto mailboxDto; List <MailAddressDto> aliasesDtoList; using (var dbContext = TeamlabMailboxDal.CreateMailDbContext()) { mailboxDto = TeamlabMailboxDal.GetMailbox(mailboxId, dbContext.DbManager); aliasesDtoList = TeamlabMailAddressDal.GetMailboxAliases(mailboxId, dbContext.DbManager); } if (mailboxDto == null) { return(null); } var mailboxBase = _GetMailbox(mailboxDto.mailbox_address.ToString()); if (mailboxBase == null) { throw new Exception("Mailbox is missing on server"); } var mailboxDomain = factory.CreateWebDomain(mailboxDto.mailbox_address.domain.id, mailboxDto.mailbox_address.domain.tenant, mailboxDto.mailbox_address.domain.name, mailboxDto.mailbox_address.domain.is_virified, this); var mailboxAddress = factory.CreateMailAddress(mailboxDto.mailbox_address.id, mailboxDto.mailbox_address.tenant, mailboxDto.mailbox_address.name, mailboxDomain); var account = CoreContext.Authentication.GetAccountByID(new Guid(mailboxDto.mailbox.user)); var mailboxAccount = factory.CreateMailAccount(account, mailboxBase.Account.Login); var mailboxAliases = aliasesDtoList .Select(alias => factory.CreateMailAddress(alias.id, alias.tenant, alias.name, mailboxDomain)) .ToList(); var mailbox = factory.CreateMailbox(mailboxDto.mailbox.id, mailboxDto.mailbox.tenant, mailboxAddress, mailboxDto.mailbox.name, mailboxAccount, mailboxAliases.ToList(), this); return(mailbox); }
public override IDnsSettings GetFreeDnsRecords(IMailServerFactory factory) { var dnsDto = TeamlabDnsDal.GetFreeDnsRecords() ?? TeamlabDnsDal.CreateFreeDnsRecords(SetupInfo.DnsPresets.DkimSelector, SetupInfo.DnsPresets.DomainCheckPrefix, SetupInfo.DnsPresets.SpfValue); var txtName = SetupInfo.DnsPresets.CurrentOrigin; var dns = factory.CreateDnsSettings(dnsDto.id, dnsDto.tenant, dnsDto.user, "", dnsDto.dkim_selector, dnsDto.dkim_private_key, dnsDto.dkim_public_key, txtName, dnsDto.domain_chek, txtName, dnsDto.spf, SetupInfo.DnsPresets.MxHost, SetupInfo.DnsPresets.MxPriority); return(dns); }
public MailRemoveMailserverMailboxOperation(Tenant tenant, IAccount user, IMailbox mailBox, MailBoxManager mailBoxManager, MailServerBase mailServer, IMailServerFactory mailServerFactory) : base(tenant, user) { _mailBox = mailBox; _mailBoxManager = mailBoxManager; _mailServer = mailServer; _mailServerFactory = mailServerFactory; SetSource(_mailBox.Id.ToString()); }
public override void UpdateMailbox(IMailbox mailbox, string name, IMailServerFactory factory) { var newMailbox = factory.CreateMailbox(mailbox.Id, mailbox.Tenant, mailbox.Address, name, mailbox.Account, mailbox.Aliases.ToList(), this); using (var dbContextWithTran = TeamlabMailboxDal.CreateMailDbContext(true)) { TeamlabMailboxDal.UpdateMailbox(newMailbox.Account.TeamlabAccount, newMailbox.Id, newMailbox.Name, dbContextWithTran.DbManager); _UpdateMailbox(new MailboxBase(newMailbox)); 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))); }
public IDnsSettings GetDns(IMailServerFactory factory) { var dnsDto = TeamlabDnsDal.GetDomainDnsRecords(Id); if (dnsDto == null) { return(null); } var txtName = Server.SetupInfo.DnsPresets.CurrentOrigin; var dns = factory.CreateDnsSettings(dnsDto.id, dnsDto.tenant, dnsDto.user, Name, dnsDto.dkim_selector, dnsDto.dkim_private_key, dnsDto.dkim_public_key, txtName, dnsDto.domain_chek, txtName, dnsDto.spf, Server.SetupInfo.DnsPresets.MxHost, Server.SetupInfo.DnsPresets.MxPriority, Server.Logger); return(dns); }
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()); }
public override IWebDomain CreateWebDomain(string name, bool isVerified, IMailServerFactory factory) { if (factory == null) throw new ArgumentNullException("factory"); WebDomainDto domainDto; using (var dbContextWithTran = TeamlabDomainDal.CreateMailDbContext(true)) { domainDto = TeamlabDomainDal.AddWebDomain(name, isVerified, dbContextWithTran.DbManager); _CreateWebDomain(name); dbContextWithTran.CommitTransaction(); } var webdomain = factory.CreateWebDomain(domainDto.id, domainDto.tenant, domainDto.name, domainDto.is_virified, this); return webdomain; }
public override IWebDomain CreateWebDomain(string name, bool isVerified, IMailServerFactory factory) { if (factory == null) { throw new ArgumentNullException("factory"); } WebDomainDto domainDto; using (var dbContextWithTran = TeamlabDomainDal.CreateMailDbContext(true)) { domainDto = TeamlabDomainDal.AddWebDomain(name, isVerified, dbContextWithTran.DbManager); _CreateWebDomain(name); dbContextWithTran.CommitTransaction(); } var webdomain = factory.CreateWebDomain(domainDto.id, domainDto.tenant, domainDto.name, domainDto.is_virified, this); return(webdomain); }
public override void DeleteWebDomain(IWebDomain webDomain, IMailServerFactory factory) { if (webDomain == null) { throw new ArgumentNullException("webDomain", "ServerModel::DeleteWebDomain"); } if (factory == null) { throw new ArgumentNullException("factory", "ServerModel::DeleteWebDomain"); } using (var dbContextWithTran = TeamlabDomainDal.CreateMailDbContext(true)) { TeamlabDomainDal.DeleteDomain(webDomain.Id, dbContextWithTran.DbManager); _DeleteWebDomain(new WebDomainBase(webDomain)); TeamlabDnsDal.RemoveUsedDns(webDomain.Id, dbContextWithTran.DbManager); dbContextWithTran.CommitTransaction(); } }
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 IDnsSettings AddDns(int dnsId, IMailServerFactory factory) { IDnsSettings dnsRecords; using (var dbContextWithTran = TeamlabDnsDal.CreateMailDbContext(true)) { var dnsDto = TeamlabDnsDal.LinkDnsToDomain(dnsId, Id, dbContextWithTran.DbManager); var txtName = Server.SetupInfo.DnsPresets.CurrentOrigin; dnsRecords = factory.CreateDnsSettings(dnsDto.id, dnsDto.tenant, dnsDto.user, Name, dnsDto.dkim_selector, dnsDto.dkim_private_key, dnsDto.dkim_public_key, txtName, dnsDto.domain_chek, txtName, dnsDto.spf, Server.SetupInfo.DnsPresets.MxHost, Server.SetupInfo.DnsPresets.MxPriority, Server.Logger); var dkimBase = new DkimRecordBase(dnsRecords.DkimSelector, dnsRecords.DkimPrivateKey, dnsRecords.DkimPublicKey); _AddDkim(dkimBase); dbContextWithTran.CommitTransaction(); } return dnsRecords; }
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); }
public IDnsSettings AddDns(int dnsId, IMailServerFactory factory) { IDnsSettings dnsRecords; using (var dbContextWithTran = TeamlabDnsDal.CreateMailDbContext(true)) { var dnsDto = TeamlabDnsDal.LinkDnsToDomain(dnsId, Id, dbContextWithTran.DbManager); var txtName = Server.SetupInfo.DnsPresets.CurrentOrigin; dnsRecords = factory.CreateDnsSettings(dnsDto.id, dnsDto.tenant, dnsDto.user, Name, dnsDto.dkim_selector, dnsDto.dkim_private_key, dnsDto.dkim_public_key, txtName, dnsDto.domain_chek, txtName, dnsDto.spf, Server.SetupInfo.DnsPresets.MxHost, Server.SetupInfo.DnsPresets.MxPriority, Server.Logger); var dkimBase = new DkimRecordBase(dnsRecords.DkimSelector, dnsRecords.DkimPrivateKey, dnsRecords.DkimPublicKey); _AddDkim(dkimBase); dbContextWithTran.CommitTransaction(); } return(dnsRecords); }
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))); }
public abstract ICollection<IMailGroup> GetMailGroups(IMailServerFactory factory);
public abstract IMailbox CreateMailbox(string localpart, string password, IWebDomain domain, IMailAccount account, IMailServerFactory factory);
public override IMailbox CreateMailbox(string localpart, string password, IWebDomain domain, IMailAccount account, IMailServerFactory factory) { if (string.IsNullOrEmpty(localpart)) throw new ArgumentNullException("localpart"); if(domain == null) throw new ArgumentNullException("domain"); if (account == null) throw new ArgumentNullException("account"); if (localpart.Length + domain.Name.Length > 318) // 318 because of @ sign throw new ArgumentException("Address of mailbox exceed limitation of 319 characters.", "localpart"); var mailboxBase = new MailboxBase(new MailAccountBase(account.Login), new MailAddressBase(localpart, new WebDomainBase(domain)), new List<MailAddressBase>()) { DateCreated = DateTime.UtcNow }; MailboxWithAddressDto mailboxWithAddressDto; using (var dbContextWithTran = TeamlabMailboxDal.CreateMailDbContext(true)) { mailboxWithAddressDto = TeamlabMailboxDal.CreateMailbox(account.TeamlabAccount, mailboxBase.Address.ToString(), password, mailboxBase.Address.LocalPart, mailboxBase.Address.DateCreated, domain.Id, domain.Name, domain.IsVerified, dbContextWithTran.DbManager); _CreateMailbox(account.Login, password, localpart, domain.Name); dbContextWithTran.CommitTransaction(); } var mailboxAddress = factory.CreateMailAddress(mailboxWithAddressDto.mailbox_address.id, mailboxWithAddressDto.mailbox_address.tenant, mailboxWithAddressDto.mailbox_address.name, domain) ; var mailbox = factory.CreateMailbox(mailboxWithAddressDto.mailbox.id, mailboxWithAddressDto.mailbox.tenant, mailboxAddress, account, new List<IMailAddress>(), this); return mailbox; }
public void SetUp() { factory = TestContext.ServerFactory; server = TestContext.CreateServer(); }
public abstract IWebDomain CreateWebDomain(string name, bool isVerified, IMailServerFactory factory);
public abstract ICollection<IWebDomain> GetWebDomains(IMailServerFactory factory);
public abstract IMailGroup CreateMailGroup(string groupName, IWebDomain domain, List<int> addressIds, IMailServerFactory factory);
public abstract INotificationAddress CreateNotificationAddress(string localpart, string password, IWebDomain domain, IMailServerFactory factory);
public abstract ICollection <IMailbox> GetMailboxes(IMailServerFactory factory);
public abstract ICollection <IMailGroup> GetMailGroups(IMailServerFactory factory);
public abstract IMailGroup GetMailGroup(int id, IMailServerFactory factory);
public abstract IWebDomain GetWebDomain(int domainId, IMailServerFactory factory);
public abstract void DeleteWebDomain(IWebDomain webDomain, IMailServerFactory factory);
public override ICollection<IMailbox> GetMailboxes(IMailServerFactory factory) { if (factory == null) throw new ArgumentNullException("factory"); var mailboxList = new List<IMailbox>(); using (var dbContext = TeamlabMailboxDal.CreateMailDbContext()) { var mailboxDtoList = TeamlabMailboxDal.GetMailboxes(dbContext.DbManager); var mailboxBaseList = _GetMailboxes(mailboxDtoList.ConvertAll(d => d.mailbox.address)); mailboxList.AddRange(from serverMailbox in mailboxBaseList let mailboxDto = mailboxDtoList.Find(d => d.mailbox.address == serverMailbox.Address.ToString()) let domain = factory.CreateWebDomain(mailboxDto.mailbox_address.domain.id, mailboxDto.mailbox_address.domain.tenant, mailboxDto.mailbox_address.domain.name, mailboxDto.mailbox_address.domain.is_virified, this) let mailboxAddress = factory.CreateMailAddress(mailboxDto.mailbox_address.id, mailboxDto.mailbox_address.tenant, mailboxDto.mailbox_address.name, domain) let aliasesDtoList = TeamlabMailAddressDal.GetMailboxAliases(mailboxDto.mailbox.id, dbContext.DbManager) let aliases = aliasesDtoList.Select(a => factory.CreateMailAddress(a.id, a.tenant, a.name, domain)).ToList() let teamlabAccount = CoreContext.Authentication.GetAccountByID(new Guid(mailboxDto.mailbox.user)) let account = factory.CreateMailAccount(teamlabAccount, serverMailbox.Account.Login) select factory.CreateMailbox(mailboxDto.mailbox.id, mailboxDto.mailbox.tenant, mailboxAddress, account, aliases.ToList(), this)); } return mailboxList; }
public abstract void DeleteMailGroup(int mailgroupId, IMailServerFactory factory);
public abstract IMailGroup GetMailGroup(int id, IMailServerFactory factory);
public override ICollection<IWebDomain> GetWebDomains(IMailServerFactory factory) { if(factory == null) throw new ArgumentNullException("factory"); var domainsDtoList = TeamlabDomainDal.GetTenantDomains(); if(!domainsDtoList.Any()) return new Collection<IWebDomain>(); var domainsBaseList = _GetWebDomains(domainsDtoList.ConvertAll(d => d.name)); var webDomains = domainsBaseList.Select(domainBase => { var domainDto = domainsDtoList.Find(dalDomain => dalDomain.name == domainBase.Name); var webdomain = factory.CreateWebDomain(domainDto.id, domainDto.tenant, domainDto.name, domainDto.is_virified, this); return webdomain; }).OrderBy(obj=>obj.Tenant).ToList(); return webDomains; }
public abstract IWebDomain GetWebDomain(int domainId, IMailServerFactory factory);
public abstract IDnsSettings GetFreeDnsRecords(IMailServerFactory factory);
public abstract void DeleteWebDomain(IWebDomain webDomain, IMailServerFactory factory);
public abstract IMailbox GetMailbox(int mailboxId, IMailServerFactory factory);
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; }
public abstract ICollection<IMailbox> GetMailboxes(IMailServerFactory factory);
public override IMailbox GetMailbox(int mailboxId, IMailServerFactory factory) { if (mailboxId < 0) throw new ArgumentException("mailbox_id has negative value"); if(factory == null) throw new ArgumentNullException("factory"); MailboxWithAddressDto mailboxDto; List<MailAddressDto> aliasesDtoList; using (var dbContext = TeamlabMailboxDal.CreateMailDbContext()) { mailboxDto = TeamlabMailboxDal.GetMailbox(mailboxId, dbContext.DbManager); aliasesDtoList = TeamlabMailAddressDal.GetMailboxAliases(mailboxId, dbContext.DbManager); } if (mailboxDto == null) return null; var mailboxBase = _GetMailbox(mailboxDto.mailbox_address.ToString()); if (mailboxBase == null) throw new Exception("Mailbox is missing on server"); var mailboxDomain = factory.CreateWebDomain(mailboxDto.mailbox_address.domain.id, mailboxDto.mailbox_address.domain.tenant, mailboxDto.mailbox_address.domain.name, mailboxDto.mailbox_address.domain.is_virified, this); var mailboxAddress = factory.CreateMailAddress(mailboxDto.mailbox_address.id, mailboxDto.mailbox_address.tenant, mailboxDto.mailbox_address.name, mailboxDomain); var account = CoreContext.Authentication.GetAccountByID(new Guid(mailboxDto.mailbox.user)); var mailboxAccount = factory.CreateMailAccount(account, mailboxBase.Account.Login); var mailboxAliases = aliasesDtoList .Select(alias => factory.CreateMailAddress(alias.id, alias.tenant, alias.name, mailboxDomain)) .ToList(); var mailbox = factory.CreateMailbox(mailboxDto.mailbox.id, mailboxDto.mailbox.tenant, mailboxAddress, mailboxAccount, mailboxAliases.ToList(), this); return mailbox; }
public override void DeleteWebDomain(IWebDomain webDomain, IMailServerFactory factory) { if (webDomain == null) throw new ArgumentNullException("webDomain", "ServerModel::DeleteWebDomain"); if (factory == null) throw new ArgumentNullException("factory", "ServerModel::DeleteWebDomain"); using (var dbContextWithTran = TeamlabDomainDal.CreateMailDbContext(true)) { TeamlabDomainDal.DeleteDomain(webDomain.Id, dbContextWithTran.DbManager); _DeleteWebDomain(new WebDomainBase(webDomain)); TeamlabDnsDal.RemoveUsedDns(webDomain.Id, dbContextWithTran.DbManager); dbContextWithTran.CommitTransaction(); } }
public abstract ICollection <IWebDomain> GetWebDomains(IMailServerFactory factory);
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); 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; }
public abstract IMailGroup CreateMailGroup(string groupName, IWebDomain domain, List <int> addressIds, IMailServerFactory factory);
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 abstract void DeleteMailGroup(int mailgroupId, IMailServerFactory factory);
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 abstract IMailbox CreateMailbox(string localpart, string password, IWebDomain domain, IMailAccount account, IMailServerFactory factory);
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 abstract IMailbox GetMailbox(int mailboxId, IMailServerFactory factory);
public override IDnsSettings GetFreeDnsRecords(IMailServerFactory factory) { var dnsDto = TeamlabDnsDal.GetFreeDnsRecords() ?? TeamlabDnsDal.CreateFreeDnsRecords(SetupInfo.DnsPresets.DkimSelector, SetupInfo.DnsPresets.DomainCheckPrefix, SetupInfo.DnsPresets.SpfValue); var txtName = SetupInfo.DnsPresets.CurrentOrigin; var dns = factory.CreateDnsSettings(dnsDto.id, dnsDto.tenant, dnsDto.user, "", dnsDto.dkim_selector, dnsDto.dkim_private_key, dnsDto.dkim_public_key, txtName, dnsDto.domain_chek, txtName, dnsDto.spf, SetupInfo.DnsPresets.MxHost, SetupInfo.DnsPresets.MxPriority); return dns; }
public abstract IDnsSettings GetFreeDnsRecords(IMailServerFactory factory);
public override IWebDomain GetWebDomain(int domainId, IMailServerFactory factory) { if(domainId < 0) throw new ArgumentException("domain_id has negative value", "domainId"); if (factory == null) throw new ArgumentNullException("factory"); var domainDto = TeamlabDomainDal.GetDomain(domainId); if (domainDto == null) return null; var domainBase = _GetWebDomain(domainDto.name); if(domainBase == null) throw new Exception("Server domain is missing"); var webdomain = factory.CreateWebDomain(domainDto.id, domainDto.tenant, domainDto.name, domainDto.is_virified, this); return webdomain; }
public IDnsSettings GetDns(IMailServerFactory factory) { var dnsDto = TeamlabDnsDal.GetDomainDnsRecords(Id); if (dnsDto == null) return null; var txtName = Server.SetupInfo.DnsPresets.CurrentOrigin; var dns = factory.CreateDnsSettings(dnsDto.id, dnsDto.tenant, dnsDto.user, Name, dnsDto.dkim_selector, dnsDto.dkim_private_key, dnsDto.dkim_public_key, txtName, dnsDto.domain_chek, txtName, dnsDto.spf, Server.SetupInfo.DnsPresets.MxHost, Server.SetupInfo.DnsPresets.MxPriority, Server.Logger); return dns; }
public ICollection<IMailAddress> GetMembers(IMailServerFactory factory) { if(factory == null) throw new ArgumentNullException("factory"); var serverAddresses = _GetMembers(); var tlAddresses = TeamlabMailGroupDal.GetGroupAddresses(Id); return (from tlAddress in tlAddresses let addressForUpdate = serverAddresses.FirstOrDefault(a => a.ToString() == tlAddress.ToString()) where addressForUpdate != null let domain = factory.CreateWebDomain(tlAddress.domain.id, tlAddress.domain.tenant, tlAddress.domain.name, tlAddress.domain.is_virified, Server) select factory.CreateMailAddress(tlAddress.id, tlAddress.tenant, tlAddress.name, domain)) .ToList(); }