LumiSoft.Net.Mime.AddressList.Parse C# (CSharp) Method

Parse() public method

Parses address-list from string.
public Parse ( string addressList ) : void
addressList string Address list string.
return void
        public void Parse(string addressList)
        {
            addressList = addressList.Trim();

            StringReader reader = new StringReader(addressList);
            while(reader.SourceString.Length > 0){
                // See if mailbox or group. If ',' is before ':', then mailbox
                // Example: [email protected],	group:[email protected];
                int commaIndex = TextUtils.QuotedIndexOf(reader.SourceString,',');
                int colonIndex = TextUtils.QuotedIndexOf(reader.SourceString,':');

                // Mailbox
                if(colonIndex == -1 || (commaIndex < colonIndex && commaIndex != -1)){
                    // Read to ',' or to end if last element
                    m_pAddresses.Add(MailboxAddress.Parse(reader.QuotedReadToDelimiter(',')));
                }
                    // Group
                else{
                    // Read to ';', this is end of group
                    m_pAddresses.Add(GroupAddress.Parse(reader.QuotedReadToDelimiter(';')));

                    // If there are next items, remove first comma because it's part of group address
                    if(reader.SourceString.Length > 0){
                        reader.QuotedReadToDelimiter(',');
                    }
                }
            }

            OnCollectionChanged();
        }

Usage Example

        private void m_pOk_Click(object sender, EventArgs e)
        {
            AddressList from = new AddressList();
            from.Parse(m_pFrom.Text);
            AddressList to = new AddressList();
            to.Parse(m_pTo.Text);
            Mime m = Mime.CreateSimple(from,to,m_pSubject.Text,m_pBodyText.Text,null);
            m_Message = m.ToStringData();

            this.DialogResult = DialogResult.OK;
        }
All Usage Examples Of LumiSoft.Net.Mime.AddressList::Parse