SmtpResponse.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // System.Web.Mail.SmtpResponse.cs
  3. //
  4. // Author(s):
  5. // Per Arneng <[email protected]>
  6. //
  7. //
  8. using System;
  9. namespace System.Web.Mail {
  10. /// this class represents the response from the smtp server
  11. internal class SmtpResponse {
  12. private string rawResponse;
  13. private int statusCode;
  14. private string[] parts;
  15. /// use the Parse method to create instances
  16. protected SmtpResponse() {}
  17. /// the smtp status code FIXME: change to Enumeration?
  18. public int StatusCode {
  19. get { return statusCode; }
  20. set { statusCode = value; }
  21. }
  22. /// the response as it was recieved
  23. public string RawResponse {
  24. get { return rawResponse; }
  25. set { rawResponse = value; }
  26. }
  27. /// the response as parts where ; was used as delimiter
  28. public string[] Parts {
  29. get { return parts; }
  30. set { parts = value; }
  31. }
  32. /// parses a new response object from a response string
  33. public static SmtpResponse Parse( string line ) {
  34. SmtpResponse response = new SmtpResponse();
  35. if( line.Length < 4 )
  36. throw new SmtpException( "Response is to short " +
  37. line.Length + ".");
  38. if( ( line[ 3 ] != ' ' ) && ( line[ 3 ] != '-' ) )
  39. throw new SmtpException( "Response format is wrong.(" +
  40. line + ")" );
  41. // parse the response code
  42. response.StatusCode = Int32.Parse( line.Substring( 0 , 3 ) );
  43. // set the rawsponse
  44. response.RawResponse = line;
  45. // set the response parts
  46. response.Parts = line.Substring( 0 , 3 ).Split( ';' );
  47. return response;
  48. }
  49. }
  50. }