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 * Represents an SMTP action or command.
24 */
25 public class SmtpActionType {
26
27 /*** Internal value for the action type. */
28 private byte value;
29
30 /*** Internal representation of the CONNECT action. */
31 private static final byte CONNECT_BYTE = 1;
32
33 /*** Internal representation of the EHLO action. */
34 private static final byte EHLO_BYTE = 2;
35
36 /*** Internal representation of the MAIL FROM action. */
37 private static final byte MAIL_BYTE = 3;
38
39 /*** Internal representation of the RCPT action. */
40 private static final byte RCPT_BYTE = 4;
41
42 /*** Internal representation of the DATA action. */
43 private static final byte DATA_BYTE = 5;
44
45 /*** Internal representation of the DATA END (.) action. */
46 private static final byte DATA_END_BYTE = 6;
47
48 /*** Internal representation of the QUIT action. */
49 private static final byte QUIT_BYTE = 7;
50
51 /*** Internal representation of an unrecognized action: body text gets this action type. */
52 private static final byte UNREC_BYTE = 8;
53
54 /*** Internal representation of the blank line action: separates headers and body text. */
55 private static final byte BLANK_LINE_BYTE = 9;
56
57 /*** Internal representation of the stateless RSET action. */
58 private static final byte RSET_BYTE = -1;
59
60 /*** Internal representation of the stateless VRFY action. */
61 private static final byte VRFY_BYTE = -2;
62
63 /*** Internal representation of the stateless EXPN action. */
64 private static final byte EXPN_BYTE = -3;
65
66 /*** Internal representation of the stateless HELP action. */
67 private static final byte HELP_BYTE = -4;
68
69 /*** Internal representation of the stateless NOOP action. */
70 private static final byte NOOP_BYTE = -5;
71
72 /*** CONNECT action. */
73 public static final SmtpActionType CONNECT = new SmtpActionType(CONNECT_BYTE);
74
75 /*** EHLO action. */
76 public static final SmtpActionType EHLO = new SmtpActionType(EHLO_BYTE);
77
78 /*** MAIL action. */
79 public static final SmtpActionType MAIL = new SmtpActionType(MAIL_BYTE);
80
81 /*** RCPT action. */
82 public static final SmtpActionType RCPT = new SmtpActionType(RCPT_BYTE);
83
84 /*** DATA action. */
85 public static final SmtpActionType DATA = new SmtpActionType(DATA_BYTE);
86
87 /*** "." action. */
88 public static final SmtpActionType DATA_END = new SmtpActionType(DATA_END_BYTE);
89
90 /*** Body text action. */
91 public static final SmtpActionType UNRECOG = new SmtpActionType(UNREC_BYTE);
92
93 /*** QUIT action. */
94 public static final SmtpActionType QUIT = new SmtpActionType(QUIT_BYTE);
95
96 /*** Header/body separator action. */
97 public static final SmtpActionType BLANK_LINE = new SmtpActionType(BLANK_LINE_BYTE);
98
99 /*** Stateless RSET action. */
100 public static final SmtpActionType RSET = new SmtpActionType(RSET_BYTE);
101
102 /*** Stateless VRFY action. */
103 public static final SmtpActionType VRFY = new SmtpActionType(VRFY_BYTE);
104
105 /*** Stateless EXPN action. */
106 public static final SmtpActionType EXPN = new SmtpActionType(EXPN_BYTE);
107
108 /*** Stateless HELP action. */
109 public static final SmtpActionType HELP = new SmtpActionType(HELP_BYTE);
110
111 /*** Stateless NOOP action. */
112 public static final SmtpActionType NOOP = new SmtpActionType(NOOP_BYTE);
113
114 /***
115 * Create a new SMTP action type. Private to ensure no invalid values.
116 * @param value one of the _BYTE values
117 */
118 private SmtpActionType(byte value) {
119 this.value = value;
120 }
121
122 /***
123 * Indicates whether the action is stateless or not.
124 * @return true iff the action is stateless
125 */
126 public boolean isStateless() {
127 return value < 0;
128 }
129
130 /***
131 * String representation of this SMTP action type.
132 * @return a String
133 */
134 public String toString() {
135 switch (value) {
136 case CONNECT_BYTE:
137 return "Connect";
138 case EHLO_BYTE:
139 return "EHLO";
140 case MAIL_BYTE:
141 return "MAIL";
142 case RCPT_BYTE:
143 return "RCPT";
144 case DATA_BYTE:
145 return "DATA";
146 case DATA_END_BYTE:
147 return ".";
148 case QUIT_BYTE:
149 return "QUIT";
150 case RSET_BYTE:
151 return "RSET";
152 case VRFY_BYTE:
153 return "VRFY";
154 case EXPN_BYTE:
155 return "EXPN";
156 case HELP_BYTE:
157 return "HELP";
158 case NOOP_BYTE:
159 return "NOOP";
160 case UNREC_BYTE:
161 return "Unrecognized command / data";
162 case BLANK_LINE_BYTE:
163 return "Blank line";
164 default:
165 return "Unknown";
166 }
167 }
168 }