Esempio n. 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: 'Sender: [email protected]'.</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_Mailbox Parse(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

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

            MIME_Reader r = new MIME_Reader(name_value[1]);

            string word = r.QuotedReadToDelimiter(new[] { ',', '<', ':' });

            // Invalid value.
            if (word == null)
            {
                throw new ParseException("Invalid header field value '" + value + "'.");
            }
            // name-addr
            else if (r.Peek(true) == '<')
            {
                Mail_h_Mailbox h = new Mail_h_Mailbox(name_value[0],
                                                      new Mail_t_Mailbox(
                                                          word != null
                                                              ? MIME_Encoding_EncodedWord.DecodeS(
                                                              TextUtils.UnQuoteString(word))
                                                              : null,
                                                          r.ReadParenthesized()));
                h.m_ParseValue = value;

                return(h);
            }
            // addr-spec
            else
            {
                Mail_h_Mailbox h = new Mail_h_Mailbox(name_value[0], new Mail_t_Mailbox(null, word));
                h.m_ParseValue = value;

                return(h);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Parses header field from the specified value.
        /// </summary>
        /// <param name="value">Header field value. Header field name must be included. For example: 'Sender: [email protected]'.</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_Mailbox Parse(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

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

            MIME_Reader r = new MIME_Reader(name_value[1]);

            string word = r.QuotedReadToDelimiter(new[] {',', '<', ':'});
            // Invalid value.
            if (word == null)
            {
                throw new ParseException("Invalid header field value '" + value + "'.");
            }
                // name-addr
            else if (r.Peek(true) == '<')
            {
                Mail_h_Mailbox h = new Mail_h_Mailbox(name_value[0],
                                                      new Mail_t_Mailbox(
                                                          word != null
                                                              ? MIME_Encoding_EncodedWord.DecodeS(
                                                                    TextUtils.UnQuoteString(word))
                                                              : null,
                                                          r.ReadParenthesized()));
                h.m_ParseValue = value;

                return h;
            }
                // addr-spec
            else
            {
                Mail_h_Mailbox h = new Mail_h_Mailbox(name_value[0], new Mail_t_Mailbox(null, word));
                h.m_ParseValue = value;

                return h;
            }
        }