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

Parse() public static method

Parses Rfc 2822 3.4 group address from group address string. Syntax: display-name':'[mailbox *(',' mailbox)]';'
public static Parse ( string group ) : GroupAddress
group string Group address string.
return GroupAddress
        public static GroupAddress Parse(string group)
        {
            GroupAddress g = new GroupAddress();

            // Syntax: display-name':'[mailbox *(',' mailbox)]';'
            string[] parts = TextUtils.SplitQuotedString(group,':');
            if(parts.Length > -1){
                g.DisplayName = TextUtils.RemoveQuotes(parts[0]);
            }
            if(parts.Length > 1){
                g.GroupMembers.Parse(parts[1]);
            }

            return g;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Parses address-list from string.
        /// </summary>
        /// <param name="addressList">Address list string.</param>
        /// <returns></returns>
        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))
                {
                    // FIX: why quotes missing
                    //System.Windows.Forms.MessageBox.Show(reader.SourceString + "#" + reader.OriginalString);

                    // Read to ',' or to end if last element
                    MailboxAddress address = MailboxAddress.Parse(reader.QuotedReadToDelimiter(','));
                    m_pAddresses.Add(address);
                    address.Owner = this;
                }
                // Group
                else
                {
                    // Read to ';', this is end of group
                    GroupAddress address = GroupAddress.Parse(reader.QuotedReadToDelimiter(';'));
                    m_pAddresses.Add(address);
                    address.Owner = this;

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

            OnCollectionChanged();
        }