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