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 * https://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 the meaning of the codes, familiarity with RFC 821 is assumed. The mnemonic constant
22 * names are transcriptions from the code descriptions of RFC 821.
23 */
24 public final class SMTPReply {
25
26 /** SMTP reply code {@value}. */
27 public static final int SYSTEM_STATUS = 211;
28
29 /** SMTP reply code {@value}. */
30 public static final int HELP_MESSAGE = 214;
31
32 /** SMTP reply code {@value}. */
33 public static final int SERVICE_READY = 220;
34
35 /** SMTP reply code {@value}. */
36 public static final int SERVICE_CLOSING_TRANSMISSION_CHANNEL = 221;
37
38 /** SMTP reply code {@value}. */
39 public static final int ACTION_OK = 250;
40
41 /** SMTP reply code {@value}. */
42 public static final int USER_NOT_LOCAL_WILL_FORWARD = 251;
43
44 /** SMTP reply code {@value}. */
45 public static final int START_MAIL_INPUT = 354;
46
47 /** SMTP reply code {@value}. */
48 public static final int SERVICE_NOT_AVAILABLE = 421;
49
50 /** SMTP reply code {@value}. */
51 public static final int ACTION_NOT_TAKEN = 450;
52
53 /** SMTP reply code {@value}. */
54 public static final int ACTION_ABORTED = 451;
55
56 /** SMTP reply code {@value}. */
57 public static final int INSUFFICIENT_STORAGE = 452;
58
59 /** SMTP reply code {@value}. */
60 public static final int UNRECOGNIZED_COMMAND = 500;
61
62 /** SMTP reply code {@value}. */
63 public static final int SYNTAX_ERROR_IN_ARGUMENTS = 501;
64
65 /** SMTP reply code {@value}. */
66 public static final int COMMAND_NOT_IMPLEMENTED = 502;
67
68 /** SMTP reply code {@value}. */
69 public static final int BAD_COMMAND_SEQUENCE = 503;
70
71 /** SMTP reply code {@value}. */
72 public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504;
73
74 /** SMTP reply code {@value}. */
75 public static final int MAILBOX_UNAVAILABLE = 550;
76
77 /** SMTP reply code {@value}. */
78 public static final int USER_NOT_LOCAL = 551;
79
80 /** SMTP reply code {@value}. */
81
82 /** SMTP reply code {@value}. */
83 public static final int STORAGE_ALLOCATION_EXCEEDED = 552;
84
85 /** SMTP reply code {@value}. */
86 public static final int MAILBOX_NAME_NOT_ALLOWED = 553;
87
88 /** SMTP reply code {@value}. */
89 public static final int TRANSACTION_FAILED = 554;
90
91 /**
92 * 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
93 * negative permanent response on the failure of a command that cannot be reattempted with success.
94 *
95 * @param reply The reply code to test.
96 * @return True if a reply code is a negative permanent response, false if not.
97 */
98 public static boolean isNegativePermanent(final int reply) {
99 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 * <strong>Note:</strong> <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 }