public int RemoveMailGroup(int id) { if (!IsAdmin) { throw new SecurityException("Need admin privileges."); } if (id < 0) { throw new ArgumentException(@"Invalid mailgroup id.", "id"); } MailServer.DeleteMailGroup(id, MailServerFactory); return(id); }
public int RemoveMailbox(int id) { if (id < 0) { throw new ArgumentException(@"Invalid domain id.", "id"); } var mailbox = MailServer.GetMailbox(id, MailServerFactory); if (mailbox == null) { throw new ItemNotFoundException("Account not found."); } var isSharedDomain = mailbox.Address.Domain.Tenant == Defines.SHARED_TENANT_ID; if (!IsAdmin && !isSharedDomain) { throw new SecurityException("Need admin privileges."); } if (isSharedDomain && !IsAdmin && mailbox.Account.TeamlabAccount.ID != SecurityContext.CurrentAccount.ID) { throw new SecurityException("Removing of a shared mailbox is allowed only for the current account if user is not admin."); } 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); return(id); }