2 // System.Web.Mail.MailAddressCollection.cs
5 // Per Arneng <pt99par@student.bth.se>
10 using System.Collections;
12 namespace System.Web.Mail {
14 // represents a collection of MailAddress objects
15 internal class MailAddressCollection : IEnumerable {
17 protected ArrayList data = new ArrayList();
19 public MailAddress this[ int index ] {
20 get { return this.Get( index ); }
23 public int Count { get { return data.Count; } }
25 public void Add( MailAddress addr ) { data.Add( addr ); }
26 public MailAddress Get( int index ) { return (MailAddress)data[ index ]; }
28 public IEnumerator GetEnumerator() {
29 return data.GetEnumerator();
33 public override string ToString() {
35 StringBuilder builder = new StringBuilder();
36 for( int i = 0; i <data.Count ; i++ ) {
37 MailAddress addr = this.Get( i );
39 builder.Append( addr );
41 if( i != ( data.Count - 1 ) ) builder.Append( ",\r\n " );
44 return builder.ToString();
47 public static MailAddressCollection Parse( string str ) {
49 if( str == null ) throw new ArgumentNullException("Null is not allowed as an address string");
51 MailAddressCollection list = new MailAddressCollection();
53 string[] parts = str.Split( new char[] { ',' , ';' } );
55 foreach( string part in parts ) {
56 MailAddress add = MailAddress.Parse (part);