01: /*
02: * Dumbster - a dummy SMTP server
03: * Copyright 2004 Jason Paul Kitchen
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package com.dumbster.smtp;
18:
19: /**
20: * SMTP server state.
21: */
22: public class SmtpState {
23: /** Internal representation of the state. */
24: private byte value;
25:
26: /** Internal representation of the CONNECT state. */
27: private static final byte CONNECT_BYTE = (byte) 1;
28: /** Internal representation of the GREET state. */
29: private static final byte GREET_BYTE = (byte) 2;
30: /** Internal representation of the MAIL state. */
31: private static final byte MAIL_BYTE = (byte) 3;
32: /** Internal representation of the RCPT state. */
33: private static final byte RCPT_BYTE = (byte) 4;
34: /** Internal representation of the DATA_HEADER state. */
35: private static final byte DATA_HEADER_BYTE = (byte) 5;
36: /** Internal representation of the DATA_BODY state. */
37: private static final byte DATA_BODY_BYTE = (byte) 6;
38: /** Internal representation of the QUIT state. */
39: private static final byte QUIT_BYTE = (byte) 7;
40:
41: /** CONNECT state: waiting for a client connection. */
42: public static final SmtpState CONNECT = new SmtpState(CONNECT_BYTE);
43: /** GREET state: wating for a ELHO message. */
44: public static final SmtpState GREET = new SmtpState(GREET_BYTE);
45: /** MAIL state: waiting for the MAIL FROM: command. */
46: public static final SmtpState MAIL = new SmtpState(MAIL_BYTE);
47: /** RCPT state: waiting for a RCPT <email address> command. */
48: public static final SmtpState RCPT = new SmtpState(RCPT_BYTE);
49: /** Waiting for headers. */
50: public static final SmtpState DATA_HDR = new SmtpState(
51: DATA_HEADER_BYTE);
52: /** Processing body text. */
53: public static final SmtpState DATA_BODY = new SmtpState(
54: DATA_BODY_BYTE);
55: /** End of client transmission. */
56: public static final SmtpState QUIT = new SmtpState(QUIT_BYTE);
57:
58: /**
59: * Create a new SmtpState object. Private to ensure that only valid states can be created.
60: * @param value one of the _BYTE values.
61: */
62: private SmtpState(byte value) {
63: this .value = value;
64: }
65:
66: /**
67: * String representation of this SmtpState.
68: * @return a String
69: */
70: public String toString() {
71: switch (value) {
72: case CONNECT_BYTE:
73: return "CONNECT";
74: case GREET_BYTE:
75: return "GREET";
76: case MAIL_BYTE:
77: return "MAIL";
78: case RCPT_BYTE:
79: return "RCPT";
80: case DATA_HEADER_BYTE:
81: return "DATA_HDR";
82: case DATA_BODY_BYTE:
83: return "DATA_BODY";
84: case QUIT_BYTE:
85: return "QUIT";
86: default:
87: return "Unknown";
88: }
89: }
90: }
|