    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 * SMTPReply stores a set of constants for SMTP reply codes. To interpret the meaning of the codes, familiarity with RFC 821 is assumed. The mnemonic constant
    022 * names are transcriptions from the code descriptions of RFC 821.
    023 */
    024public final class SMTPReply {
    025
    026    /** SMTP reply code {@value}. */
    027    public static final int SYSTEM_STATUS = 211;
    028
    029    /** SMTP reply code {@value}. */
    030    public static final int HELP_MESSAGE = 214;
    031
    032    /** SMTP reply code {@value}. */
    033    public static final int SERVICE_READY = 220;
    034
    035    /** SMTP reply code {@value}. */
    036    public static final int SERVICE_CLOSING_TRANSMISSION_CHANNEL = 221;
    037
    038    /** SMTP reply code {@value}. */
    039    public static final int ACTION_OK = 250;
    040
    041    /** SMTP reply code {@value}. */
    042    public static final int USER_NOT_LOCAL_WILL_FORWARD = 251;
    043
    044    /** SMTP reply code {@value}. */
    045    public static final int START_MAIL_INPUT = 354;
    046
    047    /** SMTP reply code {@value}. */
    048    public static final int SERVICE_NOT_AVAILABLE = 421;
    049
    050    /** SMTP reply code {@value}. */
    051    public static final int ACTION_NOT_TAKEN = 450;
    052
    053    /** SMTP reply code {@value}. */
    054    public static final int ACTION_ABORTED = 451;
    055
    056    /** SMTP reply code {@value}. */
    057    public static final int INSUFFICIENT_STORAGE = 452;
    058
    059    /** SMTP reply code {@value}. */
    060    public static final int UNRECOGNIZED_COMMAND = 500;
    061
    062    /** SMTP reply code {@value}. */
    063    public static final int SYNTAX_ERROR_IN_ARGUMENTS = 501;
    064
    065    /** SMTP reply code {@value}. */
    066    public static final int COMMAND_NOT_IMPLEMENTED = 502;
    067
    068    /** SMTP reply code {@value}. */
    069    public static final int BAD_COMMAND_SEQUENCE = 503;
    070
    071    /** SMTP reply code {@value}. */
    072    public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504;
    073
    074    /** SMTP reply code {@value}. */
    075    public static final int MAILBOX_UNAVAILABLE = 550;
    076
    077    /** SMTP reply code {@value}. */
    078    public static final int USER_NOT_LOCAL = 551;
    079
    080    /** SMTP reply code {@value}. */
    081
    082    /** SMTP reply code {@value}. */
    083    public static final int STORAGE_ALLOCATION_EXCEEDED = 552;
    084
    085    /** SMTP reply code {@value}. */
    086    public static final int MAILBOX_NAME_NOT_ALLOWED = 553;
    087
    088    /** SMTP reply code {@value}. */
    089    public static final int TRANSACTION_FAILED = 554;
    090
    091    /**
    092     * Tests if a reply code is a negative permanent response. All codes beginning with a 5 are negative permanent responses. The SMTP server will send a
    093     * negative permanent response on the failure of a command that cannot be reattempted with success.
    094     *
    095     * @param reply The reply code to test.
    096     * @return True if a reply code is a negative permanent response, false if not.
    097     */
    098    public static boolean isNegativePermanent(final int reply) {
    099        return reply >= 500 && reply < 600;
    100    }
    101
    102    /**
    103     * Tests if a reply code is a negative transient response. All codes beginning with a 4 are negative transient responses. The SMTP server will send a
    104     * negative transient response on the failure of a command that can be reattempted with success.
    105     *
    106     * @param reply The reply code to test.
    107     * @return True if a reply code is a negative transient response, false if not.
    108     */
    109    public static boolean isNegativeTransient(final int reply) {
    110        return reply >= 400 && reply < 500;
    111    }
    112
    113    /**
    114     * Tests if a reply code is a positive completion response. All codes beginning with a 2 are positive completion responses. The SMTP server will send a
    115     * positive completion response on the final successful completion of a command.
    116     *
    117     * @param reply The reply code to test.
    118     * @return True if a reply code is a positive completion response, false if not.
    119     */
    120    public static boolean isPositiveCompletion(final int reply) {
    121        return reply >= 200 && reply < 300;
    122    }
    123
    124    /**
    125     * Tests if a reply code is a positive intermediate response. All codes beginning with a 3 are positive intermediate responses. The SMTP server will
    126     * send a positive intermediate response on the successful completion of one part of a multipart sequence of commands. For example, after a successful DATA
    127     * command, a positive intermediate response will be sent to indicate that the server is ready to receive the message data.
    128     *
    129     * @param reply The reply code to test.
    130     * @return True if a reply code is a positive intermediate response, false if not.
    131     */
    132    public static boolean isPositiveIntermediate(final int reply) {
    133        return reply >= 300 && reply < 400;
    134    }
    135
    136    /**
    137     * Tests if a reply code is a positive preliminary response. All codes beginning with a 1 are positive preliminary responses. Positive preliminary
    138     * responses are used to indicate tentative success. No further commands can be issued to the SMTP server after a positive preliminary response until a
    139     * follow-up response is received from the server.
    140     * <p>
    141     * <b>Note:</b> <em> No SMTP commands defined in RFC 822 provide this type of reply. </em>
    142     * </p>
    143     *
    144     * @param reply The reply code to test.
    145     * @return True if a reply code is a positive preliminary response, false if not.
    146     */
    147    public static boolean isPositivePreliminary(final int reply) {
    148        return reply >= 100 && reply < 200;
    149    }
    150
    151    /** Cannot be instantiated. */
    152    private SMTPReply() {
    153    }
    154
    155}