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
22   * the meaning of the codes, familiarity with RFC 821 is assumed.
23   * The mnemonic constant names are transcriptions from the code descriptions
24   * of RFC 821.  For those who think in terms of the actual SMTP commands,
25   * a set of constants such as {@link #HELO  HELO } are provided
26   * where the constant name is the same as the SMTP command.
27   */
28  
29  public final class SMTPCommand
30  {
31  
32  
33      public static final int HELO = 0;
34      public static final int MAIL = 1;
35      public static final int RCPT = 2;
36      public static final int DATA = 3;
37      public static final int SEND = 4;
38      public static final int SOML = 5;
39      public static final int SAML = 6;
40      public static final int RSET = 7;
41      public static final int VRFY = 8;
42      public static final int EXPN = 9;
43      public static final int HELP = 10;
44      public static final int NOOP = 11;
45      public static final int TURN = 12;
46      public static final int QUIT = 13;
47  
48      /**
49       * The authorization command
50       * @since 3.0
51       */
52      public static final int AUTH = 14 ;
53  
54      /**
55       * The extended hello command
56       * @since 3.0
57       */
58      public static final int EHLO = 15 ;
59  
60      private static final int _NEXT_ = EHLO + 1; // update as necessary when adding new entries
61  
62      public static final int HELLO = HELO;
63      public static final int LOGIN = HELO;
64      public static final int MAIL_FROM = MAIL;
65      public static final int RECIPIENT = RCPT;
66      public static final int SEND_MESSAGE_DATA = DATA;
67      public static final int SEND_FROM = SEND;
68      public static final int SEND_OR_MAIL_FROM = SOML;
69      public static final int SEND_AND_MAIL_FROM = SAML;
70      public static final int RESET = RSET;
71      public static final int VERIFY = VRFY;
72      public static final int EXPAND = EXPN;
73      // public static final int HELP = HELP;
74      // public static final int NOOP = NOOP;
75      // public static final int TURN = TURN;
76      // public static final int QUIT = QUIT;
77      public static final int LOGOUT = QUIT;
78  
79      // Cannot be instantiated
80      private SMTPCommand()
81      {}
82  
83      private static final String[] _commands = {
84                                            "HELO", "MAIL FROM:", "RCPT TO:", "DATA", "SEND FROM:", "SOML FROM:",
85                                            "SAML FROM:", "RSET", "VRFY", "EXPN", "HELP", "NOOP", "TURN", "QUIT",
86                                            "AUTH", "EHLO"
87                                        };
88  
89  
90      static {
91          if (_commands.length != _NEXT_) {
92              throw new RuntimeException("Error in array definition");
93          }
94      }
95  
96      /***
97       * Retrieve the SMTP protocol command string corresponding to a specified
98       * command code.
99       * <p>
100      * @param command The command code.
101      * @return The SMTP protcol command string corresponding to a specified
102      *         command code.
103      ***/
104     public static final String getCommand(int command)
105     {
106         return _commands[command];
107     }
108 
109 }