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