SMTPCommand.java

  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. package org.apache.commons.net.smtp;

  18. /**
  19.  * 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
  20.  * 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
  21.  * {@link #HELO HELO } are provided where the constant name is the same as the SMTP command.
  22.  */
  23. public final class SMTPCommand {

  24.     /** SMTP command {@value}. */
  25.     public static final int HELO = 0;

  26.     /** SMTP command {@value}. */
  27.     public static final int MAIL = 1;

  28.     /** SMTP command {@value}. */
  29.     public static final int RCPT = 2;

  30.     /** SMTP command {@value}. */
  31.     public static final int DATA = 3;

  32.     /** SMTP command {@value}. */
  33.     public static final int SEND = 4;

  34.     /** SMTP command {@value}. */
  35.     public static final int SOML = 5;

  36.     /** SMTP command {@value}. */
  37.     public static final int SAML = 6;

  38.     /** SMTP command {@value}. */
  39.     public static final int RSET = 7;

  40.     /** SMTP command {@value}. */
  41.     public static final int VRFY = 8;

  42.     /** SMTP command {@value}. */
  43.     public static final int EXPN = 9;

  44.     /** SMTP command {@value}. */
  45.     public static final int HELP = 10;

  46.     /** SMTP command {@value}. */
  47.     public static final int NOOP = 11;

  48.     /** SMTP command {@value}. */
  49.     public static final int TURN = 12;

  50.     /** SMTP command {@value}. */
  51.     public static final int QUIT = 13;

  52.     /**
  53.      * The authorization command
  54.      *
  55.      * @since 3.0
  56.      */
  57.     public static final int AUTH = 14;

  58.     /**
  59.      * The extended hello command
  60.      *
  61.      * @since 3.0
  62.      */
  63.     public static final int EHLO = 15;

  64.     private static final int NEXT = EHLO + 1; // update as necessary when adding new entries

  65.     /** Alias for {@value}. */
  66.     public static final int HELLO = HELO;

  67.     /** Alias for {@value}. */
  68.     public static final int LOGIN = HELO;

  69.     /** Alias for {@value}. */
  70.     public static final int MAIL_FROM = MAIL;

  71.     /** Alias for {@value}. */
  72.     public static final int RECIPIENT = RCPT;

  73.     /** Alias for {@value}. */
  74.     public static final int SEND_MESSAGE_DATA = DATA;

  75.     /** Alias for {@value}. */
  76.     public static final int SEND_FROM = SEND;

  77.     /** Alias for {@value}. */
  78.     public static final int SEND_OR_MAIL_FROM = SOML;

  79.     /** Alias for {@value}. */
  80.     public static final int SEND_AND_MAIL_FROM = SAML;

  81.     /** Alias for {@value}. */
  82.     public static final int RESET = RSET;

  83.     /** Alias for {@value}. */
  84.     public static final int VERIFY = VRFY;

  85.     /** Alias for {@value}. */
  86.     public static final int EXPAND = EXPN;

  87.     /** Alias for {@value}. */
  88.     public static final int LOGOUT = QUIT;

  89.     private static final String[] commands = { "HELO", "MAIL FROM:", "RCPT TO:", "DATA", "SEND FROM:", "SOML FROM:", "SAML FROM:", "RSET", "VRFY", "EXPN",
  90.             "HELP", "NOOP", "TURN", "QUIT", "AUTH", "EHLO" };

  91.     static {
  92.         if (commands.length != NEXT) {
  93.             throw new IllegalStateException("Error in array definition");
  94.         }
  95.     }

  96.     /**
  97.      * Gets the SMTP protocol command string corresponding to a specified command code.
  98.      *
  99.      * @param command The command code.
  100.      * @return The SMTP protocol command string corresponding to a specified command code.
  101.      */
  102.     public static String getCommand(final int command) {
  103.         return commands[command];
  104.     }

  105.     /** Cannot be instantiated. */
  106.     private SMTPCommand() {
  107.     }

  108. }