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 */
024
025public final class SMTPReply {
026
027    public static final int SYSTEM_STATUS = 211;
028    public static final int HELP_MESSAGE = 214;
029    public static final int SERVICE_READY = 220;
030    public static final int SERVICE_CLOSING_TRANSMISSION_CHANNEL = 221;
031    public static final int ACTION_OK = 250;
032    public static final int USER_NOT_LOCAL_WILL_FORWARD = 251;
033    public static final int START_MAIL_INPUT = 354;
034    public static final int SERVICE_NOT_AVAILABLE = 421;
035    public static final int ACTION_NOT_TAKEN = 450;
036    public static final int ACTION_ABORTED = 451;
037    public static final int INSUFFICIENT_STORAGE = 452;
038    public static final int UNRECOGNIZED_COMMAND = 500;
039    public static final int SYNTAX_ERROR_IN_ARGUMENTS = 501;
040    public static final int COMMAND_NOT_IMPLEMENTED = 502;
041    public static final int BAD_COMMAND_SEQUENCE = 503;
042    public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504;
043    public static final int MAILBOX_UNAVAILABLE = 550;
044    public static final int USER_NOT_LOCAL = 551;
045    public static final int STORAGE_ALLOCATION_EXCEEDED = 552;
046    public static final int MAILBOX_NAME_NOT_ALLOWED = 553;
047    public static final int TRANSACTION_FAILED = 554;
048
049    /**
050     * Determine 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
051     * negative permanent response on the failure of a command that cannot be reattempted with success.
052     * <p>
053     *
054     * @param reply The reply code to test.
055     * @return True if a reply code is a negative permanent response, false if not.
056     */
057    public static boolean isNegativePermanent(final int reply) {
058        return reply >= 500 && reply < 600;
059    }
060
061    /**
062     * Determine 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
063     * negative transient response on the failure of a command that can be reattempted with success.
064     * <p>
065     *
066     * @param reply The reply code to test.
067     * @return True if a reply code is a negative transient response, false if not.
068     */
069    public static boolean isNegativeTransient(final int reply) {
070        return reply >= 400 && reply < 500;
071    }
072
073    /**
074     * Determine 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
075     * positive completion response on the final successful completion of a command.
076     * <p>
077     *
078     * @param reply The reply code to test.
079     * @return True if a reply code is a positive completion response, false if not.
080     */
081    public static boolean isPositiveCompletion(final int reply) {
082        return reply >= 200 && reply < 300;
083    }
084
085    /**
086     * Determine if a reply code is a positive intermediate response. All codes beginning with a 3 are positive intermediate responses. The SMTP server will
087     * send a positive intermediate response on the successful completion of one part of a multi-part sequence of commands. For example, after a successful DATA
088     * command, a positive intermediate response will be sent to indicate that the server is ready to receive the message data.
089     * <p>
090     *
091     * @param reply The reply code to test.
092     * @return True if a reply code is a positive intermediate response, false if not.
093     */
094    public static boolean isPositiveIntermediate(final int reply) {
095        return reply >= 300 && reply < 400;
096    }
097
098    /**
099     * Determine if a reply code is a positive preliminary response. All codes beginning with a 1 are positive preliminary responses. Postitive preliminary
100     * responses are used to indicate tentative success. No further commands can be issued to the SMTP server after a positive preliminary response until a
101     * follow up response is received from the server.
102     * <p>
103     * <b> Note: </b> <em> No SMTP commands defined in RFC 822 provide this type of reply. </em>
104     * <p>
105     *
106     * @param reply The reply code to test.
107     * @return True if a reply code is a positive preliminary response, false if not.
108     */
109    public static boolean isPositivePreliminary(final int reply) {
110        return reply >= 100 && reply < 200;
111    }
112
113    // Cannot be instantiated
114    private SMTPReply() {
115    }
116
117}