/// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="fieldName">Header field name. For example: "To".</param>
        /// <param name="values">Addresses collection.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>filedName</b> or <b>values</b> is null reference.</exception>
        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
        public Mail_h_AddressList(string fieldName, Mail_t_AddressList values)
        {
            if (fieldName == null)
            {
                throw new ArgumentNullException("fieldName");
            }
            if (fieldName == string.Empty)
            {
                throw new ArgumentException("Argument 'fieldName' value must be specified.");
            }
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            m_Name       = fieldName;
            m_pAddresses = values;
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="fieldName">Header field name. For example: "To".</param>
        /// <param name="values">Addresses collection.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>filedName</b> or <b>values</b> is null reference.</exception>
        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
        public Mail_h_AddressList(string fieldName, Mail_t_AddressList values)
        {
            if (fieldName == null)
            {
                throw new ArgumentNullException("fieldName");
            }
            if (fieldName == string.Empty)
            {
                throw new ArgumentException("Argument 'fieldName' value must be specified.");
            }
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            m_Name = fieldName;
            m_pAddresses = values;
        }
        public static Mail_t_AddressList ParseAddressList(string value)
        {
            MIME_Reader r = new MIME_Reader(value);

            /* RFC 5322 3.4.
                address         =   mailbox / group

                mailbox         =   name-addr / addr-spec

                name-addr       =   [display-name] angle-addr

                angle-addr      =   [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr

                group           =   display-name ":" [group-list] ";" [CFWS]

                display-name    =   phrase

                mailbox-list    =   (mailbox *("," mailbox)) / obs-mbox-list

                address-list    =   (address *("," address)) / obs-addr-list

                group-list      =   mailbox-list / CFWS / obs-group-list
            */

            Mail_t_AddressList retVal = new Mail_t_AddressList();

            while (true)
            {
                string word = r.QuotedReadToDelimiter(new[] { ',', '<', ':' });
                // We processed all data.
                if (word == null && r.Available == 0)
                {
                    if (retVal.Count == 0)
                    {
                        if (CheckEmail(value))
                        {
                            retVal.Add(new Mail_t_Mailbox(null, value));
                        }
                    }
                    
                    break;
                }
                // skip old group address format
                else if (r.Peek(true) == ':')
                {
                    // Consume ':'
                    r.Char(true);
                }
                // name-addr
                else if (r.Peek(true) == '<')
                {
                    string address = r.ReadParenthesized();

                    if (CheckEmail(address))
                    {
                        retVal.Add(
                            new Mail_t_Mailbox(
                                word != null
                                    ? MIME_Encoding_EncodedWord.DecodeS(TextUtils.UnQuoteString(word))
                                    : null,
                                address));
                    }
                }
                // addr-spec
                else
                {
                    if (CheckEmail(word))
                    {
                        retVal.Add(new Mail_t_Mailbox(null, word));
                    }
                }

                // We have more addresses.
                if (r.Peek(true) == ',')
                {
                    r.Char(false);
                }
            }

            return retVal;
        }
Example #4
0
        public static Mail_t_AddressList ParseAddressList(string value)
        {
            MIME_Reader r = new MIME_Reader(value);

            /* RFC 5322 3.4.
             *  address         =   mailbox / group
             *
             *  mailbox         =   name-addr / addr-spec
             *
             *  name-addr       =   [display-name] angle-addr
             *
             *  angle-addr      =   [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr
             *
             *  group           =   display-name ":" [group-list] ";" [CFWS]
             *
             *  display-name    =   phrase
             *
             *  mailbox-list    =   (mailbox *("," mailbox)) / obs-mbox-list
             *
             *  address-list    =   (address *("," address)) / obs-addr-list
             *
             *  group-list      =   mailbox-list / CFWS / obs-group-list
             */

            Mail_t_AddressList retVal = new Mail_t_AddressList();

            while (true)
            {
                string word = r.QuotedReadToDelimiter(new[] { ',', '<', ':' });
                // We processed all data.
                if (word == null && r.Available == 0)
                {
                    if (retVal.Count == 0)
                    {
                        if (CheckEmail(value))
                        {
                            retVal.Add(new Mail_t_Mailbox(null, value));
                        }
                    }

                    break;
                }
                // skip old group address format
                else if (r.Peek(true) == ':')
                {
                    // Consume ':'
                    r.Char(true);
                }
                // name-addr
                else if (r.Peek(true) == '<')
                {
                    string address = r.ReadParenthesized();

                    if (CheckEmail(address))
                    {
                        retVal.Add(
                            new Mail_t_Mailbox(
                                word != null
                                    ? MIME_Encoding_EncodedWord.DecodeS(TextUtils.UnQuoteString(word))
                                    : null,
                                address));
                    }
                }
                // addr-spec
                else
                {
                    if (CheckEmail(word))
                    {
                        retVal.Add(new Mail_t_Mailbox(null, word));
                    }
                }

                // We have more addresses.
                if (r.Peek(true) == ',')
                {
                    r.Char(false);
                }
            }

            return(retVal);
        }