1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.dumbster.smtp;
21
22 /***
23 * SMTP server state.
24 */
25 public class SmtpState {
26
27 /*** Internal representation of the state. */
28 private byte value;
29
30 /*** Internal representation of the CONNECT state. */
31 private static final byte CONNECT_BYTE = 1;
32
33 /*** Internal representation of the GREET state. */
34 private static final byte GREET_BYTE = 2;
35
36 /*** Internal representation of the MAIL state. */
37 private static final byte MAIL_BYTE = 3;
38
39 /*** Internal representation of the RCPT state. */
40 private static final byte RCPT_BYTE = 4;
41
42 /*** Internal representation of the DATA_HEADER state. */
43 private static final byte DATA_HEADER_BYTE = 5;
44
45 /*** Internal representation of the DATA_BODY state. */
46 private static final byte DATA_BODY_BYTE = 6;
47
48 /*** Internal representation of the QUIT state. */
49 private static final byte QUIT_BYTE = 7;
50
51 /*** CONNECT state: waiting for a client connection. */
52 public static final SmtpState CONNECT = new SmtpState(CONNECT_BYTE);
53
54 /*** GREET state: wating for a ELHO message. */
55 public static final SmtpState GREET = new SmtpState(GREET_BYTE);
56
57 /*** MAIL state: waiting for the MAIL FROM: command. */
58 public static final SmtpState MAIL = new SmtpState(MAIL_BYTE);
59
60 /*** RCPT state: waiting for a RCPT <email address> command. */
61 public static final SmtpState RCPT = new SmtpState(RCPT_BYTE);
62
63 /*** Waiting for headers. */
64 public static final SmtpState DATA_HDR = new SmtpState(DATA_HEADER_BYTE);
65
66 /*** Processing body text. */
67 public static final SmtpState DATA_BODY = new SmtpState(DATA_BODY_BYTE);
68
69 /*** End of client transmission. */
70 public static final SmtpState QUIT = new SmtpState(QUIT_BYTE);
71
72 /***
73 * Create a new SmtpState object. Private to ensure that only valid states can be created.
74 * @param value one of the _BYTE values.
75 */
76 private SmtpState(byte value) {
77 this.value = value;
78 }
79
80 /***
81 * String representation of this SmtpState.
82 * @return a String
83 */
84 public String toString() {
85 switch (value) {
86 case CONNECT_BYTE:
87 return "CONNECT";
88 case GREET_BYTE:
89 return "GREET";
90 case MAIL_BYTE:
91 return "MAIL";
92 case RCPT_BYTE:
93 return "RCPT";
94 case DATA_HEADER_BYTE:
95 return "DATA_HDR";
96 case DATA_BODY_BYTE:
97 return "DATA_BODY";
98 case QUIT_BYTE:
99 return "QUIT";
100 default:
101 return "Unknown";
102 }
103 }
104 }