public static MailAddress Parse( string str ) { if (str == null || str.Trim () == "") return null; MailAddress addr = new MailAddress(); string address = null; string nameString = null; string[] parts = str.Split( new char[] { ' ' } ); // find the address: [email protected] // and put to gether all the parts // before the address as nameString foreach( string part in parts ) { if( part.IndexOf( '@' ) > 0 ) { address = part; break; } nameString = nameString + part + " "; } if( address == null ) throw new FormatException( "Invalid e-mail address: '" + str + "'."); address = address.Trim( new char[] { '<' , '>' , '(' , ')' } ); addr.Address = address; if( nameString != null ) { addr.Name = nameString.Trim( new char[] { ' ' , '"' } ); addr.Name = ( addr.Name.Length == 0 ? null : addr.Name ); } return addr; }
public void Add( MailAddress addr ) { data.Add( addr ); }