    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.net.smtp;
    019
    020/**
    021 * SMTPCommand stores a set of constants for SMTP command codes.  To interpret
    022 * the meaning of the codes, familiarity with RFC 821 is assumed.
    023 * The mnemonic constant names are transcriptions from the code descriptions
    024 * of RFC 821.  For those who think in terms of the actual SMTP commands,
    025 * a set of constants such as {@link #HELO  HELO } are provided
    026 * where the constant name is the same as the SMTP command.
    027 */
    028
    029public final class SMTPCommand
    030{
    031
    032
    033    public static final int HELO = 0;
    034    public static final int MAIL = 1;
    035    public static final int RCPT = 2;
    036    public static final int DATA = 3;
    037    public static final int SEND = 4;
    038    public static final int SOML = 5;
    039    public static final int SAML = 6;
    040    public static final int RSET = 7;
    041    public static final int VRFY = 8;
    042    public static final int EXPN = 9;
    043    public static final int HELP = 10;
    044    public static final int NOOP = 11;
    045    public static final int TURN = 12;
    046    public static final int QUIT = 13;
    047
    048    /**
    049     * The authorization command
    050     * @since 3.0
    051     */
    052    public static final int AUTH = 14 ;
    053
    054    /**
    055     * The extended hello command
    056     * @since 3.0
    057     */
    058    public static final int EHLO = 15 ;
    059
    060    private static final int NEXT = EHLO + 1; // update as necessary when adding new entries
    061
    062    public static final int HELLO = HELO;
    063    public static final int LOGIN = HELO;
    064    public static final int MAIL_FROM = MAIL;
    065    public static final int RECIPIENT = RCPT;
    066    public static final int SEND_MESSAGE_DATA = DATA;
    067    public static final int SEND_FROM = SEND;
    068    public static final int SEND_OR_MAIL_FROM = SOML;
    069    public static final int SEND_AND_MAIL_FROM = SAML;
    070    public static final int RESET = RSET;
    071    public static final int VERIFY = VRFY;
    072    public static final int EXPAND = EXPN;
    073    // public static final int HELP = HELP;
    074    // public static final int NOOP = NOOP;
    075    // public static final int TURN = TURN;
    076    // public static final int QUIT = QUIT;
    077    public static final int LOGOUT = QUIT;
    078
    079    // Cannot be instantiated
    080    private SMTPCommand()
    081    {}
    082
    083    private static final String[] commands = {
    084                                          "HELO", "MAIL FROM:", "RCPT TO:", "DATA", "SEND FROM:", "SOML FROM:",
    085                                          "SAML FROM:", "RSET", "VRFY", "EXPN", "HELP", "NOOP", "TURN", "QUIT",
    086                                          "AUTH", "EHLO"
    087                                      };
    088
    089
    090    static {
    091        if (commands.length != NEXT) {
    092            throw new RuntimeException("Error in array definition");
    093        }
    094    }
    095
    096    /**
    097     * Retrieve the SMTP protocol command string corresponding to a specified
    098     * command code.
    099     * <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 String getCommand(final int command)
    105    {
    106        return commands[command];
    107    }
    108
    109}