SMTP Internal classes added to make SmtpMail.Send work
[mono.git] / mcs / class / System.Web / System.Web.Mail / SmtpResponse.cs
1 // SmtpResponse.cs
2 // author: Per Arneng <pt99par@student.bth.se>
3 using System;
4
5 namespace System.Web.Mail {
6
7     /// this class represents the response from the smtp server
8     internal class SmtpResponse {
9         
10         private string rawResponse;
11         private int statusCode;
12         private string[] parts;
13
14         /// use the Parse method to create instances
15         protected SmtpResponse() {}
16
17         /// the smtp status code FIXME: change to Enumeration?
18         public int StatusCode {
19             get { return statusCode; }
20             set { statusCode = value; }
21         }
22         
23         /// the response as it was recieved
24         public string RawResponse {
25             get { return rawResponse; }
26             set { rawResponse = value; }
27         }
28
29         /// the response as parts where ; was used as delimiter
30         public string[] Parts {
31             get { return parts; }
32             set { parts = value; }
33         }
34
35         /// parses a new response object from a response string
36         public static SmtpResponse Parse( string line ) {
37             SmtpResponse response = new SmtpResponse();
38             
39             if( line == null )
40                 throw new ArgumentNullException( "Null is not allowed " + 
41                                                  "as a response string.");
42
43             if( line.Length < 4 ) 
44                 throw new FormatException( "Response is to short " + 
45                                            line.Length + ".");
46             
47             if( line[ 3 ] != ' ' )
48                 throw new FormatException( "Response format is wrong.");
49             
50             // parse the response code
51             response.StatusCode = Int32.Parse( line.Substring( 0 , 3 ) );
52             
53             // set the rawsponse
54             response.RawResponse = line;
55
56             // set the response parts
57             response.Parts = line.Substring( 0 , 3 ).Split( ';' );
58
59             return response;
60         }
61     }
62
63 }