示例#1
0
        /// <summary>
        /// Parses header field from the specified value.
        /// </summary>
        /// <param name="value">Header field value. Header field name must be included. For example: 'Content-Type: text/plain'.</param>
        /// <returns>Returns parsed header field.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception>
        /// <exception cref="ParseException">Is raised when header field parsing errors.</exception>
        public static Mail_h_MailboxList Parse(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            string[] name_value = value.Split(new char[] { ':' }, 2);
            if (name_value.Length != 2)
            {
                throw new ParseException("Invalid header field value '" + value + "'.");
            }

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

            Mail_h_MailboxList retVal = new Mail_h_MailboxList(name_value[0], Mail_t_MailboxList.Parse(name_value[1].Trim()));

            retVal.m_ParseValue = value;
            retVal.m_pAddresses.AcceptChanges();

            return(retVal);
        }
示例#2
0
        /// <summary>
        /// Parses <b>mailbox</b> from specified string value.
        /// </summary>
        /// <param name="value">The <b>mailbox</b> string value.</param>
        /// <returns>Returns parse mailbox.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception>
        /// <exception cref="ParseException">Is raised when <b>value</b> is not valid <b>mailbox</b> value.</exception>
        public static Mail_t_Mailbox Parse(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            MIME_Reader        r      = new MIME_Reader(value);
            Mail_t_MailboxList retVal = new Mail_t_MailboxList();

            while (true)
            {
                string word = r.QuotedReadToDelimiter(new char[] { ',', '<' });
                // We processed all data.
                if (string.IsNullOrEmpty(word) && r.Available == 0)
                {
                    throw new ParseException("Not valid 'mailbox' value '" + value + "'.");
                }
                // name-addr
                else if (r.Peek(true) == '<')
                {
                    return(new Mail_t_Mailbox(word != null ? MIME_Encoding_EncodedWord.DecodeS(TextUtils.UnQuoteString(word.Trim())) : null, r.ReadParenthesized()));
                }
                // addr-spec
                else
                {
                    return(new Mail_t_Mailbox(null, word));
                }
            }

            throw new ParseException("Not valid 'mailbox' value '" + value + "'.");
        }
        /// <summary>
        /// Parses <b>mailbox-list</b> from specified string value.
        /// </summary>
        /// <param name="value">The <b>mailbox-list</b> string value.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception>
        /// <exception cref="ParseException">Is raised when <b>value</b> is not valid <b>mailbox-list</b> value.</exception>
        public static Mail_t_MailboxList Parse(string value)
        {
            if(value == null){
                throw new ArgumentNullException("value");
            }

            MIME_Reader        r      = new MIME_Reader(value);
            Mail_t_MailboxList retVal = new Mail_t_MailboxList();
            while(true){
                string word = r.QuotedReadToDelimiter(new char[]{',','<'});
                // We processed all data.
                if(string.IsNullOrEmpty(word) && r.Available == 0){
                    break;
                }
                // name-addr
                else if(r.Peek(true) == '<'){
                    retVal.Add(new Mail_t_Mailbox(word != null ? MIME_Encoding_EncodedWord.DecodeS(TextUtils.UnQuoteString(word.Trim())) : null,r.ReadParenthesized()));                    
                }
                // addr-spec
                else{
                    retVal.Add(new Mail_t_Mailbox(null,word));
                }

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

            return retVal;
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="filedName">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_MailboxList(string filedName,Mail_t_MailboxList values)
        {
            if(filedName == null){
                throw new ArgumentNullException("filedName");
            }
            if(filedName == string.Empty){
                throw new ArgumentException("Argument 'filedName' value must be specified.");
            }
            if(values == null){
                throw new ArgumentNullException("values");
            }

            m_Name       = filedName;
            m_pAddresses = values;
        }
示例#5
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="filedName">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_MailboxList(string filedName, Mail_t_MailboxList values)
        {
            if (filedName == null)
            {
                throw new ArgumentNullException("filedName");
            }
            if (filedName == string.Empty)
            {
                throw new ArgumentException("Argument 'filedName' value must be specified.");
            }
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            m_Name       = filedName;
            m_pAddresses = values;
        }