    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 the meaning of the codes, familiarity with RFC 821 is assumed. The mnemonic
    022 * 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
    023 * {@link #HELO HELO } are provided where the constant name is the same as the SMTP command.
    024 */
    025
    026public final class SMTPCommand {
    027
    028    public static final int HELO = 0;
    029    public static final int MAIL = 1;
    030    public static final int RCPT = 2;
    031    public static final int DATA = 3;
    032    public static final int SEND = 4;
    033    public static final int SOML = 5;
    034    public static final int SAML = 6;
    035    public static final int RSET = 7;
    036    public static final int VRFY = 8;
    037    public static final int EXPN = 9;
    038    public static final int HELP = 10;
    039    public static final int NOOP = 11;
    040    public static final int TURN = 12;
    041    public static final int QUIT = 13;
    042
    043    /**
    044     * The authorization command
    045     *
    046     * @since 3.0
    047     */
    048    public static final int AUTH = 14;
    049
    050    /**
    051     * The extended hello command
    052     *
    053     * @since 3.0
    054     */
    055    public static final int EHLO = 15;
    056
    057    private static final int NEXT = EHLO + 1; // update as necessary when adding new entries
    058
    059    public static final int HELLO = HELO;
    060    public static final int LOGIN = HELO;
    061    public static final int MAIL_FROM = MAIL;
    062    public static final int RECIPIENT = RCPT;
    063    public static final int SEND_MESSAGE_DATA = DATA;
    064    public static final int SEND_FROM = SEND;
    065    public static final int SEND_OR_MAIL_FROM = SOML;
    066    public static final int SEND_AND_MAIL_FROM = SAML;
    067    public static final int RESET = RSET;
    068    public static final int VERIFY = VRFY;
    069    public static final int EXPAND = EXPN;
    070    // public static final int HELP = HELP;
    071    // public static final int NOOP = NOOP;
    072    // public static final int TURN = TURN;
    073    // public static final int QUIT = QUIT;
    074    public static final int LOGOUT = QUIT;
    075
    076    private static final String[] commands = { "HELO", "MAIL FROM:", "RCPT TO:", "DATA", "SEND FROM:", "SOML FROM:", "SAML FROM:", "RSET", "VRFY", "EXPN",
    077            "HELP", "NOOP", "TURN", "QUIT", "AUTH", "EHLO" };
    078
    079    static {
    080        if (commands.length != NEXT) {
    081            throw new RuntimeException("Error in array definition");
    082        }
    083    }
    084
    085    /**
    086     * Retrieve the SMTP protocol command string corresponding to a specified command code.
    087     * <p>
    088     *
    089     * @param command The command code.
    090     * @return The SMTP protcol command string corresponding to a specified command code.
    091     */
    092    public static String getCommand(final int command) {
    093        return commands[command];
    094    }
    095
    096    // Cannot be instantiated
    097    private SMTPCommand() {
    098    }
    099
    100}