MailAddressCollection.cs 1.5 KB

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