001: /*
002: * Dumbster - a dummy SMTP server
003: * Copyright 2004 Jason Paul Kitchen
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package com.dumbster.smtp;
018:
019: /**
020: * Represents an SMTP action or command.
021: */
022: public class SmtpActionType {
023: /** Internal value for the action type. */
024: private byte value;
025:
026: /** Internal representation of the CONNECT action. */
027: private static final byte CONNECT_BYTE = (byte) 1;
028: /** Internal representation of the EHLO action. */
029: private static final byte EHLO_BYTE = (byte) 2;
030: /** Internal representation of the MAIL FROM action. */
031: private static final byte MAIL_BYTE = (byte) 3;
032: /** Internal representation of the RCPT action. */
033: private static final byte RCPT_BYTE = (byte) 4;
034: /** Internal representation of the DATA action. */
035: private static final byte DATA_BYTE = (byte) 5;
036: /** Internal representation of the DATA END (.) action. */
037: private static final byte DATA_END_BYTE = (byte) 6;
038: /** Internal representation of the QUIT action. */
039: private static final byte QUIT_BYTE = (byte) 7;
040: /** Internal representation of an unrecognized action: body text gets this action type. */
041: private static final byte UNREC_BYTE = (byte) 8;
042: /** Internal representation of the blank line action: separates headers and body text. */
043: private static final byte BLANK_LINE_BYTE = (byte) 9;
044:
045: /** Internal representation of the stateless RSET action. */
046: private static final byte RSET_BYTE = (byte) -1;
047: /** Internal representation of the stateless VRFY action. */
048: private static final byte VRFY_BYTE = (byte) -2;
049: /** Internal representation of the stateless EXPN action. */
050: private static final byte EXPN_BYTE = (byte) -3;
051: /** Internal representation of the stateless HELP action. */
052: private static final byte HELP_BYTE = (byte) -4;
053: /** Internal representation of the stateless NOOP action. */
054: private static final byte NOOP_BYTE = (byte) -5;
055:
056: /** CONNECT action. */
057: public static final SmtpActionType CONNECT = new SmtpActionType(
058: CONNECT_BYTE);
059: /** EHLO action. */
060: public static final SmtpActionType EHLO = new SmtpActionType(
061: EHLO_BYTE);
062: /** MAIL action. */
063: public static final SmtpActionType MAIL = new SmtpActionType(
064: MAIL_BYTE);
065: /** RCPT action. */
066: public static final SmtpActionType RCPT = new SmtpActionType(
067: RCPT_BYTE);
068: /** DATA action. */
069: public static final SmtpActionType DATA = new SmtpActionType(
070: DATA_BYTE);
071: /** "." action. */
072: public static final SmtpActionType DATA_END = new SmtpActionType(
073: DATA_END_BYTE);
074: /** Body text action. */
075: public static final SmtpActionType UNRECOG = new SmtpActionType(
076: UNREC_BYTE);
077: /** QUIT action. */
078: public static final SmtpActionType QUIT = new SmtpActionType(
079: QUIT_BYTE);
080: /** Header/body separator action. */
081: public static final SmtpActionType BLANK_LINE = new SmtpActionType(
082: BLANK_LINE_BYTE);
083:
084: /** Stateless RSET action. */
085: public static final SmtpActionType RSET = new SmtpActionType(
086: RSET_BYTE);
087: /** Stateless VRFY action. */
088: public static final SmtpActionType VRFY = new SmtpActionType(
089: VRFY_BYTE);
090: /** Stateless EXPN action. */
091: public static final SmtpActionType EXPN = new SmtpActionType(
092: EXPN_BYTE);
093: /** Stateless HELP action. */
094: public static final SmtpActionType HELP = new SmtpActionType(
095: HELP_BYTE);
096: /** Stateless NOOP action. */
097: public static final SmtpActionType NOOP = new SmtpActionType(
098: NOOP_BYTE);
099:
100: /**
101: * Create a new SMTP action type. Private to ensure no invalid values.
102: * @param value one of the _BYTE values
103: */
104: private SmtpActionType(byte value) {
105: this .value = value;
106: }
107:
108: /**
109: * Indicates whether the action is stateless or not.
110: * @return true iff the action is stateless
111: */
112: public boolean isStateless() {
113: return value < 0;
114: }
115:
116: /**
117: * String representation of this SMTP action type.
118: * @return a String
119: */
120: public String toString() {
121: switch (value) {
122: case CONNECT_BYTE:
123: return "Connect";
124: case EHLO_BYTE:
125: return "EHLO";
126: case MAIL_BYTE:
127: return "MAIL";
128: case RCPT_BYTE:
129: return "RCPT";
130: case DATA_BYTE:
131: return "DATA";
132: case DATA_END_BYTE:
133: return ".";
134: case QUIT_BYTE:
135: return "QUIT";
136: case RSET_BYTE:
137: return "RSET";
138: case VRFY_BYTE:
139: return "VRFY";
140: case EXPN_BYTE:
141: return "EXPN";
142: case HELP_BYTE:
143: return "HELP";
144: case NOOP_BYTE:
145: return "NOOP";
146: case UNREC_BYTE:
147: return "Unrecognized command / data";
148: case BLANK_LINE_BYTE:
149: return "Blank line";
150: default:
151: return "Unknown";
152: }
153: }
154: }
|