Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/xpn/xwiki/test/smtp/SmtpActionType.java


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