SmtpResponse.cs 1.5 KB

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