Exemplo n.º 1
0
        public void Read(MailList maillist)
        {
            nodeConfig["domain"]                   = AmsMailbox.GetDomainName(maillist.Name);
            nodeConfig["enabled"]                  = maillist.Enabled ? "1" : "0";
            nodeConfig["user"]                     = AmsMailbox.GetAccountName(maillist.Name);
            nodeConfig["triggertext"]              = "TRIGGER";
            nodeConfig["usetriggeredreplyto"]      = "0";
            nodeConfig["triggeredreplyto"]         = string.Empty;
            nodeConfig["usetriggeredfrom"]         = string.Empty;
            nodeConfig["triggeredfrom"]            = string.Empty;
            nodeConfig["maxtriggersperday"]        = "100";
            nodeConfig["useonlymemberscantrigger"] = "0";
            nodeConfig["maxaddresses"]             = "5000";

            // copy mail list members
            TreeNode addresses = listConfig.ChildNodes["addresses"];

            if (addresses == null)
            {
                addresses          = new TreeNode();
                addresses.NodeName = "addresses";
                listConfig.ChildNodes.Add(addresses);
            }
            addresses.ChildNodes.Clear();

            foreach (string member in maillist.Members)
            {
                TreeNode node = new TreeNode(addresses);
                node.NodeValue = member;
                addresses.ChildNodes.Add(node);
            }
        }
Exemplo n.º 2
0
        public bool AccountExists(string mailboxName)
        {
            Tree       users = AMSHelper.GetUsersConfig();
            AmsMailbox accnt = new AmsMailbox(mailboxName);

            return(accnt.Load(users));
        }
Exemplo n.º 3
0
        public static Tree GetAccountDelivery(string mailboxName)
        {
            string account        = AmsMailbox.GetAccountName(mailboxName);
            string domain         = AmsMailbox.GetDomainName(mailboxName);
            string deliveryConfig = string.Format(AccountDeliveryFile, domain, account);

            return(ReadAmsConfigurationFile(deliveryConfig));
        }
Exemplo n.º 4
0
        public static bool SetAccountDelivery(Tree config, string mailboxName)
        {
            string account        = AmsMailbox.GetAccountName(mailboxName);
            string domain         = AmsMailbox.GetDomainName(mailboxName);
            string deliveryConfig = string.Format(AccountDeliveryFile, domain, account);

            return(SaveAmsConfigurationFile(config, deliveryConfig));
        }
Exemplo n.º 5
0
        public static bool SetMailingListConfig(Tree config, string maillistName)
        {
            string domain     = AmsMailbox.GetDomainName(maillistName);
            string account    = AmsMailbox.GetAccountName(maillistName);
            string listConfig = Path.Combine(AMSLocation, string.Format(MailListConfigFile, domain, account));

            return(SaveAmsConfigurationFile(config, listConfig));
        }
Exemplo n.º 6
0
        public bool Save(Tree config)
        {
            if (!config.ChildNodes.Contains(nodeConfig))
            {
                nodeConfig["file"] = string.Format(AMSHelper.MailListConfigFile, AmsMailbox.GetDomainName(maillistName), AmsMailbox.GetAccountName(maillistName));
                config.ChildNodes.Add(nodeConfig);
            }

            return(AMSHelper.SetMailListsConfig(config) &&
                   AMSHelper.SetMailingListConfig(listConfig, maillistName));
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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());
        }
Exemplo n.º 10
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());
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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.");
            }
        }
Exemplo n.º 13
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.");
            }
        }
Exemplo n.º 14
0
        public bool Load(TreeNode configNode)
        {
            string account = AmsMailbox.GetAccountName(maillistName);
            string domain  = AmsMailbox.GetDomainName(maillistName);

            string amsUser   = configNode["user"];
            string amsDomain = configNode["domain"];

            if (string.Compare(amsUser, account, true) == 0 &&
                string.Compare(amsDomain, domain, true) == 0)
            {
                nodeConfig = configNode;
                return(true);
            }

            return(false);
        }
Exemplo n.º 15
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.");
            }
        }
Exemplo n.º 16
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.");
            }
        }
Exemplo n.º 17
0
        public static bool RemoveAccount(string mailboxName)
        {
            bool   succeed    = false;
            string account    = AmsMailbox.GetAccountName(mailboxName);
            string domain     = AmsMailbox.GetDomainName(mailboxName);
            string accountDir = Path.Combine(AMSLocation, string.Format(AccountFolder, domain, account));

            try
            {
                Directory.Delete(accountDir, true);
                succeed = true;
            }
            catch (Exception ex)
            {
                Log.WriteError(ex);
            }

            return(succeed);
        }
Exemplo n.º 18
0
        public static bool RemoveMailList(string maillistName)
        {
            bool   succeed        = false;
            string account        = AmsMailbox.GetAccountName(maillistName);
            string domain         = AmsMailbox.GetDomainName(maillistName);
            string maillistConfig = Path.Combine(AMSLocation, string.Format(MailListConfigFile, domain, account));

            try
            {
                File.Delete(maillistConfig);
                succeed = true;
            }
            catch (Exception ex)
            {
                Log.WriteError(ex.Message, ex);
            }

            return(succeed);
        }
Exemplo n.º 19
0
        public static AmsMailbox[] GetMailboxes(Tree config, string domainName)
        {
            List <AmsMailbox> list = new List <AmsMailbox>();

            foreach (TreeNode node in config.ChildNodes)
            {
                string account   = node["user"];
                string amsDomain = node["domain"];
                if (string.Compare(amsDomain, domainName, true) == 0)
                {
                    AmsMailbox mb = new AmsMailbox(string.Concat(account, "@", amsDomain));
                    mb.Load(node);
                    mb.LoadAccountConfig();
                    list.Add(mb);
                }
            }

            return(list.ToArray());
        }
Exemplo n.º 20
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.");
            }
        }
Exemplo n.º 21
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.");
            }
        }
Exemplo n.º 22
0
        public bool Load(Tree config)
        {
            string account = AmsMailbox.GetAccountName(maillistName);
            string domain  = AmsMailbox.GetDomainName(maillistName);

            foreach (TreeNode node in config.ChildNodes)
            {
                string amsUser   = node["user"];
                string amsDomain = node["domain"];

                if (string.Compare(amsUser, account, true) == 0 &&
                    string.Compare(amsDomain, domain, true) == 0)
                {
                    nodeConfig = node;
                    return(true);
                }
            }

            return(false);
        }