Exemplo n.º 1
0
        public override MailList[] GetLists(string domainName)
        {
            try
            {
                SM3.svcMailListAdmin svcLists = new SM3.svcMailListAdmin();
                PrepareProxy(svcLists);

                SM3.MailingListResult mResult = svcLists.GetMailingListsByDomain(
                    AdminUsername,
                    AdminPassword,
                    domainName
                    );

                if (!mResult.Result)
                {
                    throw new Exception(mResult.Message);
                }

                List <MailList> mailLists = new List <MailList>();
                foreach (string listName in mResult.listNames)
                {
                    SM3.SettingsRequestResult sResult = svcLists.GetRequestedListSettings(
                        AdminUsername,
                        AdminPassword,
                        domainName,
                        listName,
                        sm3Settings
                        );

                    if (!sResult.Result)
                    {
                        throw new Exception(sResult.Message);
                    }

                    SM3.SubscriberListResult rResult = svcLists.GetSubscriberList(
                        AdminUsername,
                        AdminPassword,
                        domainName,
                        listName
                        );

                    if (!rResult.Result)
                    {
                        throw new Exception(rResult.Message);
                    }

                    MailList list = new MailList();
                    list.Name = string.Concat(listName, "@", domainName);
                    SetMailListSettings(list, sResult.settingValues);
                    SetMailListMembers(list, rResult.Subscribers);
                    mailLists.Add(list);
                }

                return(mailLists.ToArray());
            }
            catch (Exception ex)
            {
                throw new Exception("Couldn't obtain domain mail lists.", ex);
            }
        }
Exemplo n.º 2
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.º 3
0
        public MailList ToMailList()
        {
            MailList list = new MailList();

            list.Name = maillistName;

            if (nodeConfig["enabled"] == "1")
            {
                list.Enabled = true;
            }

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

            if (addresses != null)
            {
                List <string> members = new List <string>();

                foreach (TreeNode node in addresses.ChildNodes)
                {
                    members.Add(node.NodeValue);
                }

                list.Members = members.ToArray();
            }

            return(list);
        }
Exemplo n.º 4
0
        protected void SetMailListMembers(MailList list, string[] subscribers)
        {
            List <string> members = new List <string>();

            foreach (string subscriber in subscribers)
            {
                members.Add(subscriber);
            }

            list.Members = members.ToArray();
        }
Exemplo n.º 5
0
        public override MailList GetList(string listName)
        {
            try
            {
                string domain  = GetDomainName(listName);
                string account = GetAccountName(listName);

                SM3.svcMailListAdmin svcLists = new SM3.svcMailListAdmin();
                PrepareProxy(svcLists);

                SM3.SettingsRequestResult sResult = svcLists.GetRequestedListSettings(
                    AdminUsername,
                    AdminPassword,
                    domain,
                    account,
                    sm3Settings
                    );

                if (!sResult.Result)
                {
                    throw new Exception(sResult.Message);
                }

                SM3.SubscriberListResult mResult = svcLists.GetSubscriberList(
                    AdminUsername,
                    AdminPassword,
                    domain,
                    account
                    );

                if (!mResult.Result)
                {
                    throw new Exception(mResult.Message);
                }

                MailList list = new MailList();
                list.Name = listName;

                SetMailListSettings(list, sResult.settingValues);
                SetMailListMembers(list, mResult.Subscribers);

                return(list);
            }
            catch (Exception ex)
            {
                throw new Exception("Couldn't obtain mail list.", ex);
            }
        }
Exemplo n.º 6
0
        public void CreateList(MailList maillist)
        {
            Tree        config  = AMSHelper.GetMailListsConfig();
            AmsMailList amsList = new AmsMailList(maillist.Name);

            if (amsList.Load(config))
            {
                throw new Exception("Mail list is already exists.");
            }

            amsList.Read(maillist);

            if (!amsList.Save(config))
            {
                throw new Exception("Couldn't create a mail list.");
            }
        }
Exemplo n.º 7
0
        public void UpdateList(MailList maillist)
        {
            Tree        config  = AMSHelper.GetMailListsConfig();
            AmsMailList amsList = new AmsMailList(maillist.Name);

            if (amsList.Load(config))
            {
                amsList.LoadListConfig();
                amsList.Read(maillist);

                if (!amsList.Save(config))
                {
                    throw new Exception("Couldn't update specified mail list.");
                }
            }
            else
            {
                throw new Exception("Couldn't find specified mail list.");
            }
        }
Exemplo n.º 8
0
        protected void SetMailListSettings(MailList list, string[] smSettings)
        {
            foreach (string setting in smSettings)
            {
                string[] bunch = setting.Split(new char[] { '=' });

                switch (bunch[0])
                {
                case "description":
                    list.Description = bunch[1];
                    break;

                case "disabled":
                    list.Enabled = !Convert.ToBoolean(bunch[1]);
                    break;

                case "moderator":
                    list.ModeratorAddress = bunch[1];
                    list.Moderated        = !string.IsNullOrEmpty(bunch[1]);
                    break;

                case "password":
                    list.Password = bunch[1];
                    break;

                case "requirepassword":
                    list.RequirePassword = Convert.ToBoolean(bunch[1]);
                    break;

                case "whocanpost":
                    if (string.Compare(bunch[1], "anyone", true) == 0)
                    {
                        list.PostingMode = PostingMode.AnyoneCanPost;
                    }
                    else if (string.Compare(bunch[1], "moderatoronly", true) == 0)
                    {
                        list.PostingMode = PostingMode.ModeratorCanPost;
                    }
                    else
                    {
                        list.PostingMode = PostingMode.MembersCanPost;
                    }
                    break;

                case "prependsubject":
                    list.EnableSubjectPrefix = Convert.ToBoolean(bunch[1]);
                    break;

                case "maxmessagesize":
                    list.MaxMessageSize = Convert.ToInt32(bunch[1]);
                    break;

                case "maxrecipients":
                    list.MaxRecipientsPerMessage = Convert.ToInt32(bunch[1]);
                    break;

                case "replytolist":
                    if (string.Compare(bunch[1], "true", true) == 0)
                    {
                        list.ReplyToMode = string.Compare(bunch[1], "true", true) == 0 ? ReplyTo.RepliesToList : ReplyTo.RepliesToSender;
                    }
                    break;
                }
            }
        }
Exemplo n.º 9
0
        public override void UpdateList(MailList list)
        {
            try
            {
                string domain  = GetDomainName(list.Name);
                string account = GetAccountName(list.Name);

                SM3.svcMailListAdmin lists = new SM3.svcMailListAdmin();
                PrepareProxy(lists);

                List <string> settings = new List <string>();
                settings.Add(string.Concat("description=", list.Description));
                settings.Add(string.Concat("disabled=", !list.Enabled));
                settings.Add(string.Concat("moderator=", list.ModeratorAddress));
                settings.Add(string.Concat("password="******"requirepassword="******"whocanpost=anyone");
                    break;

                case PostingMode.MembersCanPost:
                    settings.Add("whocanpost=subscribersonly");
                    break;

                case PostingMode.ModeratorCanPost:
                    settings.Add("whocanpost=moderator");
                    break;
                }

                settings.Add(string.Concat("prependsubject=", list.EnableSubjectPrefix));
                settings.Add(string.Concat("maxmessagesize=", list.MaxMessageSize));
                settings.Add(string.Concat("maxrecipients=", list.MaxRecipientsPerMessage));

                switch (list.ReplyToMode)
                {
                case ReplyTo.RepliesToList:
                    settings.Add("replytolist=true");
                    break;

                case ReplyTo.RepliesToSender:
                    settings.Add("replytolist=false");
                    break;
                }

                SM3.GenericResult result = lists.SetRequestedListSettings(AdminUsername, AdminPassword,
                                                                          domain,
                                                                          account,
                                                                          settings.ToArray()
                                                                          );

                if (!result.Result)
                {
                    throw new Exception(result.Message);
                }

                if (list.Members.Length > 0)
                {
                    result = lists.SetSubscriberList(AdminUsername, AdminPassword,
                                                     domain,
                                                     account,
                                                     list.Members
                                                     );

                    if (!result.Result)
                    {
                        throw new Exception(result.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Couldn't update mail list.", ex);
            }
        }