1   /*
2    * Dumbster: a dummy SMTP server.
3    * Copyright (C) 2003, Jason Paul Kitchen
4    * lilnottsman@yahoo.com
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 }