예제 #1
0
        public bool AccountExists(string mailboxName)
        {
            Tree       users = AMSHelper.GetUsersConfig();
            AmsMailbox accnt = new AmsMailbox(mailboxName);

            return(accnt.Load(users));
        }
예제 #2
0
        public MailAccount[] GetAccounts(string domainName)
        {
            Tree config = AMSHelper.GetUsersConfig();
            List <MailAccount> accounts = new List <MailAccount>();

            AmsMailbox[] mbList = AmsMailbox.GetMailboxes(config, domainName);
            foreach (AmsMailbox mb in mbList)
            {
                accounts.Add(mb.ToMailAccount());
            }

            return(accounts.ToArray());
        }
예제 #3
0
        public MailGroup GetGroup(string groupName)
        {
            Tree       config   = AMSHelper.GetUsersConfig();
            AmsMailbox amsGroup = new AmsMailbox(groupName);

            if (amsGroup.Load(config))
            {
                amsGroup.LoadAccountConfig();
                return(amsGroup.ToMailGroup());
            }

            return(null);
        }
예제 #4
0
        public MailAccount GetAccount(string mailboxName)
        {
            Tree       config     = AMSHelper.GetUsersConfig();
            AmsMailbox amsMailbox = new AmsMailbox(mailboxName);

            if (amsMailbox.Load(config))
            {
                amsMailbox.LoadAccountConfig();
                return(amsMailbox.ToMailAccount());
            }

            return(null);
        }
예제 #5
0
        public bool GroupExists(string groupName)
        {
            Tree       config   = AMSHelper.GetUsersConfig();
            AmsMailbox amsGroup = new AmsMailbox(groupName);

            if (amsGroup.Load(config))
            {
                amsGroup.LoadAccountConfig();

                return(amsGroup.IsMailGroup());
            }

            return(false);
        }
예제 #6
0
        public MailGroup[] GetGroups(string domainName)
        {
            List <MailGroup> groups = new List <MailGroup>();
            Tree             config = AMSHelper.GetUsersConfig();

            AmsMailbox[] amsGroups = AmsMailbox.GetMailGroups(config, domainName);

            foreach (AmsMailbox amsGroup in amsGroups)
            {
                groups.Add(amsGroup.ToMailGroup());
            }

            return(groups.ToArray());
        }
예제 #7
0
        public void CreateAccount(MailAccount mailbox)
        {
            Tree       users = AMSHelper.GetUsersConfig();
            AmsMailbox accnt = new AmsMailbox(mailbox.Name);

            if (accnt.Load(users))
            {
                throw new Exception("Mailbox is already registered.");
            }

            accnt.Read(mailbox);

            if (!accnt.Save(users))
            {
                throw new Exception("Couldn't create a mailbox.");
            }
        }
예제 #8
0
        public void DeleteGroup(string groupName)
        {
            Tree       config   = AMSHelper.GetUsersConfig();
            AmsMailbox amsGroup = new AmsMailbox(groupName);

            if (amsGroup.Load(config))
            {
                if (!amsGroup.Delete(config))
                {
                    throw new Exception("Couldn't delete specified mail group.");
                }
            }
            else
            {
                throw new Exception("Couldn't find specified mail group.");
            }
        }
예제 #9
0
        public void DeleteAccount(string mailboxName)
        {
            Tree       config     = AMSHelper.GetUsersConfig();
            AmsMailbox amsMailbox = new AmsMailbox(mailboxName);

            if (amsMailbox.Load(config))
            {
                if (!amsMailbox.Delete(config))
                {
                    throw new Exception("Couldn't delete a specified account.");
                }
            }
            else
            {
                throw new Exception("Couldn't load account settings.");
            }
        }
예제 #10
0
        public void CreateGroup(MailGroup group)
        {
            Tree       users    = AMSHelper.GetUsersConfig();
            AmsMailbox amsGroup = new AmsMailbox(group.Name);

            if (amsGroup.Load(users))
            {
                throw new Exception("Mail group is already exists.");
            }

            amsGroup.Read(group);

            if (!amsGroup.Save(users))
            {
                throw new Exception("Couldn't create a mail group.");
            }
        }
예제 #11
0
        public bool Delete(Tree config)
        {
            if (config.ChildNodes.Contains(domainConfig))
            {
                config.ChildNodes.Remove(domainConfig);
            }

            Tree            usersConfig   = AMSHelper.GetUsersConfig();
            List <TreeNode> nodesToDelete = new List <TreeNode>();

            foreach (TreeNode node in usersConfig.ChildNodes)
            {
                if (string.Compare(node["domain"], domainName, true) == 0)
                {
                    nodesToDelete.Add(node);
                }
            }

            while (nodesToDelete.Count > 0)
            {
                usersConfig.ChildNodes.Remove(nodesToDelete[0]);
                nodesToDelete.RemoveAt(0);
            }

            Tree listsConfig = AMSHelper.GetMailListsConfig();

            foreach (TreeNode node in listsConfig.ChildNodes)
            {
                if (string.Compare(node["domain"], domainName, true) == 0)
                {
                    nodesToDelete.Add(node);
                }
            }

            while (nodesToDelete.Count > 0)
            {
                listsConfig.ChildNodes.Remove(nodesToDelete[0]);
                nodesToDelete.RemoveAt(0);
            }

            return(AMSHelper.RemoveDomain(domainName) &&
                   AMSHelper.SetUsersConfig(usersConfig) &&
                   AMSHelper.SetMailListsConfig(listsConfig) &&
                   AMSHelper.SetDomainsConfig(config));
        }
예제 #12
0
        public void UpdateGroup(MailGroup group)
        {
            Tree       config   = AMSHelper.GetUsersConfig();
            AmsMailbox amsGroup = new AmsMailbox(group.Name);

            if (amsGroup.Load(config))
            {
                amsGroup.LoadAccountConfig();
                amsGroup.Read(group);

                if (!amsGroup.Save(config))
                {
                    throw new Exception("Couldn't update specified mail group.");
                }
            }
            else
            {
                throw new Exception("Couldn't find specified mail group.");
            }
        }
예제 #13
0
        public void UpdateAccount(MailAccount mailbox)
        {
            Tree       config     = AMSHelper.GetUsersConfig();
            AmsMailbox amsMailbox = new AmsMailbox(mailbox.Name);

            if (amsMailbox.Load(config))
            {
                amsMailbox.LoadAccountConfig();
                amsMailbox.Read(mailbox);

                if (!amsMailbox.Save(config))
                {
                    throw new Exception("Couldn't update specified mailbox.");
                }
            }
            else
            {
                throw new Exception("Couldn't find specified mailbox.");
            }
        }