/// <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[] { ':' }, 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 */ MIME_Reader r = new MIME_Reader(MIME_Utils.UnfoldHeader(name_value.Length == 2 ? name_value[1].TrimStart() : "")); Mail_h_MailboxList retVal = new Mail_h_MailboxList(name_value[0], new Mail_t_MailboxList()); while (true) { string word = r.QuotedReadToDelimiter(new[] { ',', '<', ':' }); // We processed all data. if (word == null && r.Available == 0) { break; } // name-addr else if (r.Peek(true) == '<') { retVal.m_pAddresses.Add( new Mail_t_Mailbox( word != null ? MIME_Encoding_EncodedWord.DecodeAll(word) : null, r.ReadParenthesized())); } // addr-spec else { retVal.m_pAddresses.Add(new Mail_t_Mailbox(null, word)); } // We have more addresses. if (r.Peek(true) == ',') { r.Char(false); } } retVal.m_ParseValue = value; retVal.m_pAddresses.AcceptChanges(); return(retVal); }
/// <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[] {':'}, 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 */ MIME_Reader r = new MIME_Reader(MIME_Utils.UnfoldHeader(name_value.Length == 2 ? name_value[1].TrimStart() : "")); Mail_h_MailboxList retVal = new Mail_h_MailboxList(name_value[0], new Mail_t_MailboxList()); while (true) { string word = r.QuotedReadToDelimiter(new[] {',', '<', ':'}); // We processed all data. if (word == null && r.Available == 0) { break; } // name-addr else if (r.Peek(true) == '<') { retVal.m_pAddresses.Add( new Mail_t_Mailbox( word != null ? MIME_Encoding_EncodedWord.DecodeAll(word) : null, r.ReadParenthesized())); } // addr-spec else { retVal.m_pAddresses.Add(new Mail_t_Mailbox(null, word)); } // We have more addresses. if (r.Peek(true) == ',') { r.Char(false); } } retVal.m_ParseValue = value; retVal.m_pAddresses.AcceptChanges(); return retVal; }