MailAddressCollection.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Text;
  3. using System.Collections;
  4. namespace System.Web.Mail {
  5. internal class MailAddressCollection : IEnumerable {
  6. protected ArrayList data = new ArrayList();
  7. public MailAddress this[ int index ] {
  8. get { return this.Get( index ); }
  9. }
  10. public int Count { get { return data.Count; } }
  11. public void Add( MailAddress addr ) { data.Add( addr ); }
  12. public MailAddress Get( int index ) { return (MailAddress)data[ index ]; }
  13. public IEnumerator GetEnumerator() {
  14. return data.GetEnumerator();
  15. }
  16. public override string ToString() {
  17. StringBuilder builder = new StringBuilder();
  18. for( int i = 0; i <data.Count ; i++ ) {
  19. MailAddress addr = this.Get( i );
  20. builder.Append( addr );
  21. if( i != ( data.Count - 1 ) ) builder.Append( ", " );
  22. }
  23. return builder.ToString();
  24. }
  25. public static MailAddressCollection Parse( string str ) {
  26. if( str == null ) throw new ArgumentNullException("Null is not allowed as an address string");
  27. MailAddressCollection list = new MailAddressCollection();
  28. string[] parts = str.Split( new char[] { ',' , ';' } );
  29. foreach( string part in parts ) {
  30. list.Add( MailAddress.Parse( part ) );
  31. }
  32. return list;
  33. }
  34. }
  35. }