示例#1
0
        private void ParseMailAddresses()
        {
            String value = this.Value;
            Int32  index = 0;

            //Split and parse
            for (int i = 0; i < value.Length; i++)
            {
                if (value[i] == ',' || value[i] == ';')
                {
                    if (index < i)
                    {
                        var m = MailAddress.TryCreate(value.Substring(index, i - index));
                        if (m != null)
                        {
                            this.MailAddresses.Add(m);
                        }
                    }
                    index = i + 1;
                }
            }
            //Add last part of value
            if (index < value.Length)
            {
                var m = MailAddress.TryCreate(value.Substring(index, value.Length - index));
                if (m != null)
                {
                    this.MailAddresses.Add(m);
                }
            }
        }
示例#2
0
        /// メールアドレス一覧の文字列からMailAddressの一覧を取得します。
        /// <summary>
        /// Get mailaddress list from mail address list text.
        /// メールアドレス一覧の文字列からMailAddressの一覧を取得します。
        /// </summary>
        /// <param name="mailAddressListText"></param>
        /// <param name="separators"></param>
        /// <returns></returns>
        public static List <MailAddress> CreateMailAddressList(String mailAddressListText, params Char[] separators)
        {
            List <MailAddress> l           = new List <MailAddress>();
            MailAddress        m           = null;
            Boolean            isSeparator = false;
            Int32 index = 0;

            for (int i = 0; i < mailAddressListText.Length; i++)
            {
                isSeparator = false;
                if (i == mailAddressListText.Length - 1)
                {
                    String s = mailAddressListText.Substring(index, mailAddressListText.Length - index);
                    m = MailAddress.TryCreate(s.Trim());
                    if (m != null)
                    {
                        l.Add(m);
                    }
                    break;
                }
                else
                {
                    for (int cIndex = 0; cIndex < separators.Length; cIndex++)
                    {
                        if (mailAddressListText[i] == separators[cIndex])
                        {
                            isSeparator = true;
                            break;
                        }
                    }
                }
                if (isSeparator == true)
                {
                    String s = mailAddressListText.Substring(index, i - index);
                    m = MailAddress.TryCreate(s.Trim());
                    if (m != null)
                    {
                        l.Add(m);
                    }
                    index = i + 1;
                }
            }
            return(l);
        }