MailAddressCollection.cs 1.3 KB

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