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