View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      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  
18  package org.apache.commons.net.smtp;
19  
20  /**
21   * SMTPCommand stores a set of constants for SMTP command codes. To interpret the meaning of the codes, familiarity with RFC 821 is assumed. The mnemonic
22   * constant names are transcriptions from the code descriptions of RFC 821. For those who think in terms of the actual SMTP commands, a set of constants such as
23   * {@link #HELO HELO } are provided where the constant name is the same as the SMTP command.
24   */
25  public final class SMTPCommand {
26  
27      /** SMTP command {@value}. */
28      public static final int HELO = 0;
29  
30      /** SMTP command {@value}. */
31      public static final int MAIL = 1;
32  
33      /** SMTP command {@value}. */
34      public static final int RCPT = 2;
35  
36      /** SMTP command {@value}. */
37      public static final int DATA = 3;
38  
39      /** SMTP command {@value}. */
40      public static final int SEND = 4;
41  
42      /** SMTP command {@value}. */
43      public static final int SOML = 5;
44  
45      /** SMTP command {@value}. */
46      public static final int SAML = 6;
47  
48      /** SMTP command {@value}. */
49      public static final int RSET = 7;
50  
51      /** SMTP command {@value}. */
52      public static final int VRFY = 8;
53  
54      /** SMTP command {@value}. */
55      public static final int EXPN = 9;
56  
57      /** SMTP command {@value}. */
58      public static final int HELP = 10;
59  
60      /** SMTP command {@value}. */
61      public static final int NOOP = 11;
62  
63      /** SMTP command {@value}. */
64      public static final int TURN = 12;
65  
66      /** SMTP command {@value}. */
67      public static final int QUIT = 13;
68  
69      /**
70       * The authorization command
71       *
72       * @since 3.0
73       */
74      public static final int AUTH = 14;
75  
76      /**
77       * The extended hello command
78       *
79       * @since 3.0
80       */
81      public static final int EHLO = 15;
82  
83      private static final int NEXT = EHLO + 1; // update as necessary when adding new entries
84  
85      /** Alias for {@value}. */
86      public static final int HELLO = HELO;
87  
88      /** Alias for {@value}. */
89      public static final int LOGIN = HELO;
90  
91      /** Alias for {@value}. */
92      public static final int MAIL_FROM = MAIL;
93  
94      /** Alias for {@value}. */
95      public static final int RECIPIENT = RCPT;
96  
97      /** Alias for {@value}. */
98      public static final int SEND_MESSAGE_DATA = DATA;
99  
100     /** Alias for {@value}. */
101     public static final int SEND_FROM = SEND;
102 
103     /** Alias for {@value}. */
104     public static final int SEND_OR_MAIL_FROM = SOML;
105 
106     /** Alias for {@value}. */
107     public static final int SEND_AND_MAIL_FROM = SAML;
108 
109     /** Alias for {@value}. */
110     public static final int RESET = RSET;
111 
112     /** Alias for {@value}. */
113     public static final int VERIFY = VRFY;
114 
115     /** Alias for {@value}. */
116     public static final int EXPAND = EXPN;
117 
118     /** Alias for {@value}. */
119     public static final int LOGOUT = QUIT;
120 
121     private static final String[] commands = { "HELO", "MAIL FROM:", "RCPT TO:", "DATA", "SEND FROM:", "SOML FROM:", "SAML FROM:", "RSET", "VRFY", "EXPN",
122             "HELP", "NOOP", "TURN", "QUIT", "AUTH", "EHLO" };
123 
124     static {
125         if (commands.length != NEXT) {
126             throw new IllegalStateException("Error in array definition");
127         }
128     }
129 
130     /**
131      * Gets the SMTP protocol command string corresponding to a specified command code.
132      *
133      * @param command The command code.
134      * @return The SMTP protocol command string corresponding to a specified command code.
135      */
136     public static String getCommand(final int command) {
137         return commands[command];
138     }
139 
140     /** Cannot be instantiated. */
141     private SMTPCommand() {
142     }
143 
144 }