1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.net.smtp;
  17. /***
  18. * SMTPReply stores a set of constants for SMTP reply codes. To interpret
  19. * the meaning of the codes, familiarity with RFC 821 is assumed.
  20. * The mnemonic constant names are transcriptions from the code descriptions
  21. * of RFC 821. For those who think in terms of the actual reply code values,
  22. * a set of CODE_NUM constants are provided where NUM is the numerical value
  23. * of the code.
  24. * <p>
  25. * <p>
  26. * @author Daniel F. Savarese
  27. ***/
  28. public final class SMTPReply
  29. {
  30. public static final int CODE_211 = 211;
  31. public static final int CODE_214 = 214;
  32. public static final int CODE_215 = 215;
  33. public static final int CODE_220 = 220;
  34. public static final int CODE_221 = 221;
  35. public static final int CODE_250 = 250;
  36. public static final int CODE_251 = 251;
  37. public static final int CODE_354 = 354;
  38. public static final int CODE_421 = 421;
  39. public static final int CODE_450 = 450;
  40. public static final int CODE_451 = 451;
  41. public static final int CODE_452 = 452;
  42. public static final int CODE_500 = 500;
  43. public static final int CODE_501 = 501;
  44. public static final int CODE_502 = 502;
  45. public static final int CODE_503 = 503;
  46. public static final int CODE_504 = 504;
  47. public static final int CODE_550 = 550;
  48. public static final int CODE_551 = 551;
  49. public static final int CODE_552 = 552;
  50. public static final int CODE_553 = 553;
  51. public static final int CODE_554 = 554;
  52. public static final int SYSTEM_STATUS = CODE_211;
  53. public static final int HELP_MESSAGE = CODE_214;
  54. public static final int SERVICE_READY = CODE_220;
  55. public static final int SERVICE_CLOSING_TRANSMISSION_CHANNEL = CODE_221;
  56. public static final int ACTION_OK = CODE_250;
  57. public static final int USER_NOT_LOCAL_WILL_FORWARD = CODE_251;
  58. public static final int START_MAIL_INPUT = CODE_354;
  59. public static final int SERVICE_NOT_AVAILABLE = CODE_421;
  60. public static final int ACTION_NOT_TAKEN = CODE_450;
  61. public static final int ACTION_ABORTED = CODE_451;
  62. public static final int INSUFFICIENT_STORAGE = CODE_452;
  63. public static final int UNRECOGNIZED_COMMAND = CODE_500;
  64. public static final int SYNTAX_ERROR_IN_ARGUMENTS = CODE_501;
  65. public static final int COMMAND_NOT_IMPLEMENTED = CODE_502;
  66. public static final int BAD_COMMAND_SEQUENCE = CODE_503;
  67. public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = CODE_504;
  68. public static final int MAILBOX_UNAVAILABLE = CODE_550;
  69. public static final int USER_NOT_LOCAL = CODE_551;
  70. public static final int STORAGE_ALLOCATION_EXCEEDED = CODE_552;
  71. public static final int MAILBOX_NAME_NOT_ALLOWED = CODE_553;
  72. public static final int TRANSACTION_FAILED = CODE_554;
  73. // Cannot be instantiated
  74. private SMTPReply()
  75. {}
  76. /***
  77. * Determine if a reply code is a positive preliminary response. All
  78. * codes beginning with a 1 are positive preliminary responses.
  79. * Postitive preliminary responses are used to indicate tentative success.
  80. * No further commands can be issued to the SMTP server after a positive
  81. * preliminary response until a follow up response is received from the
  82. * server.
  83. * <p>
  84. * <b> Note: </b> <em> No SMTP commands defined in RFC 822 provide this
  85. * type of reply. </em>
  86. * <p>
  87. * @param reply The reply code to test.
  88. * @return True if a reply code is a postive preliminary response, false
  89. * if not.
  90. ***/
  91. public static boolean isPositivePreliminary(int reply)
  92. {
  93. return (reply >= 100 && reply < 200);
  94. }
  95. /***
  96. * Determine if a reply code is a positive completion response. All
  97. * codes beginning with a 2 are positive completion responses.
  98. * The SMTP server will send a positive completion response on the final
  99. * successful completion of a command.
  100. * <p>
  101. * @param reply The reply code to test.
  102. * @return True if a reply code is a postive completion response, false
  103. * if not.
  104. ***/
  105. public static boolean isPositiveCompletion(int reply)
  106. {
  107. return (reply >= 200 && reply < 300);
  108. }
  109. /***
  110. * Determine if a reply code is a positive intermediate response. All
  111. * codes beginning with a 3 are positive intermediate responses.
  112. * The SMTP server will send a positive intermediate response on the
  113. * successful completion of one part of a multi-part sequence of
  114. * commands. For example, after a successful DATA command, a positive
  115. * intermediate response will be sent to indicate that the server is
  116. * ready to receive the message data.
  117. * <p>
  118. * @param reply The reply code to test.
  119. * @return True if a reply code is a postive intermediate response, false
  120. * if not.
  121. ***/
  122. public static boolean isPositiveIntermediate(int reply)
  123. {
  124. return (reply >= 300 && reply < 400);
  125. }
  126. /***
  127. * Determine if a reply code is a negative transient response. All
  128. * codes beginning with a 4 are negative transient responses.
  129. * The SMTP server will send a negative transient response on the
  130. * failure of a command that can be reattempted with success.
  131. * <p>
  132. * @param reply The reply code to test.
  133. * @return True if a reply code is a negative transient response, false
  134. * if not.
  135. ***/
  136. public static boolean isNegativeTransient(int reply)
  137. {
  138. return (reply >= 400 && reply < 500);
  139. }
  140. /***
  141. * Determine if a reply code is a negative permanent response. All
  142. * codes beginning with a 5 are negative permanent responses.
  143. * The SMTP server will send a negative permanent response on the
  144. * failure of a command that cannot be reattempted with success.
  145. * <p>
  146. * @param reply The reply code to test.
  147. * @return True if a reply code is a negative permanent response, false
  148. * if not.
  149. ***/
  150. public static boolean isNegativePermanent(int reply)
  151. {
  152. return (reply >= 500 && reply < 600);
  153. }
  154. }