2 // author: Per Arneng <pt99par@student.bth.se>
5 namespace System.Web.Mail {
7 /// this class represents the response from the smtp server
8 internal class SmtpResponse {
10 private string rawResponse;
11 private int statusCode;
12 private string[] parts;
14 /// use the Parse method to create instances
15 protected SmtpResponse() {}
17 /// the smtp status code FIXME: change to Enumeration?
18 public int StatusCode {
19 get { return statusCode; }
20 set { statusCode = value; }
23 /// the response as it was recieved
24 public string RawResponse {
25 get { return rawResponse; }
26 set { rawResponse = value; }
29 /// the response as parts where ; was used as delimiter
30 public string[] Parts {
32 set { parts = value; }
35 /// parses a new response object from a response string
36 public static SmtpResponse Parse( string line ) {
37 SmtpResponse response = new SmtpResponse();
40 throw new ArgumentNullException( "Null is not allowed " +
41 "as a response string.");
44 throw new FormatException( "Response is to short " +
47 if( line[ 3 ] != ' ' )
48 throw new FormatException( "Response format is wrong.");
50 // parse the response code
51 response.StatusCode = Int32.Parse( line.Substring( 0 , 3 ) );
54 response.RawResponse = line;
56 // set the response parts
57 response.Parts = line.Substring( 0 , 3 ).Split( ';' );