1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.commons.net.smtp;
19
20 /***
21 * SMTPReply stores a set of constants for SMTP reply codes. To interpret
22 * the meaning of the codes, familiarity with RFC 821 is assumed.
23 * The mnemonic constant names are transcriptions from the code descriptions
24 * of RFC 821. For those who think in terms of the actual reply code values,
25 * a set of CODE_NUM constants are provided where NUM is the numerical value
26 * of the code.
27 * <p>
28 * <p>
29 * @author Daniel F. Savarese
30 ***/
31
32 public final class SMTPReply
33 {
34
35 public static final int CODE_211 = 211;
36 public static final int CODE_214 = 214;
37 public static final int CODE_215 = 215;
38 public static final int CODE_220 = 220;
39 public static final int CODE_221 = 221;
40 public static final int CODE_250 = 250;
41 public static final int CODE_251 = 251;
42 public static final int CODE_354 = 354;
43 public static final int CODE_421 = 421;
44 public static final int CODE_450 = 450;
45 public static final int CODE_451 = 451;
46 public static final int CODE_452 = 452;
47 public static final int CODE_500 = 500;
48 public static final int CODE_501 = 501;
49 public static final int CODE_502 = 502;
50 public static final int CODE_503 = 503;
51 public static final int CODE_504 = 504;
52 public static final int CODE_550 = 550;
53 public static final int CODE_551 = 551;
54 public static final int CODE_552 = 552;
55 public static final int CODE_553 = 553;
56 public static final int CODE_554 = 554;
57
58 public static final int SYSTEM_STATUS = CODE_211;
59 public static final int HELP_MESSAGE = CODE_214;
60 public static final int SERVICE_READY = CODE_220;
61 public static final int SERVICE_CLOSING_TRANSMISSION_CHANNEL = CODE_221;
62 public static final int ACTION_OK = CODE_250;
63 public static final int USER_NOT_LOCAL_WILL_FORWARD = CODE_251;
64 public static final int START_MAIL_INPUT = CODE_354;
65 public static final int SERVICE_NOT_AVAILABLE = CODE_421;
66 public static final int ACTION_NOT_TAKEN = CODE_450;
67 public static final int ACTION_ABORTED = CODE_451;
68 public static final int INSUFFICIENT_STORAGE = CODE_452;
69 public static final int UNRECOGNIZED_COMMAND = CODE_500;
70 public static final int SYNTAX_ERROR_IN_ARGUMENTS = CODE_501;
71 public static final int COMMAND_NOT_IMPLEMENTED = CODE_502;
72 public static final int BAD_COMMAND_SEQUENCE = CODE_503;
73 public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = CODE_504;
74 public static final int MAILBOX_UNAVAILABLE = CODE_550;
75 public static final int USER_NOT_LOCAL = CODE_551;
76 public static final int STORAGE_ALLOCATION_EXCEEDED = CODE_552;
77 public static final int MAILBOX_NAME_NOT_ALLOWED = CODE_553;
78 public static final int TRANSACTION_FAILED = CODE_554;
79
80 // Cannot be instantiated
81 private SMTPReply()
82 {}
83
84 /***
85 * Determine if a reply code is a positive preliminary response. All
86 * codes beginning with a 1 are positive preliminary responses.
87 * Postitive preliminary responses are used to indicate tentative success.
88 * No further commands can be issued to the SMTP server after a positive
89 * preliminary response until a follow up response is received from the
90 * server.
91 * <p>
92 * <b> Note: </b> <em> No SMTP commands defined in RFC 822 provide this
93 * type of reply. </em>
94 * <p>
95 * @param reply The reply code to test.
96 * @return True if a reply code is a postive preliminary response, false
97 * if not.
98 ***/
99 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 }