SMTPReply.java

  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. package org.apache.commons.net.smtp;

  18. /**
  19.  * 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
  20.  * names are transcriptions from the code descriptions of RFC 821.
  21.  */
  22. public final class SMTPReply {

  23.     /** SMTP reply code {@value}. */
  24.     public static final int SYSTEM_STATUS = 211;

  25.     /** SMTP reply code {@value}. */
  26.     public static final int HELP_MESSAGE = 214;

  27.     /** SMTP reply code {@value}. */
  28.     public static final int SERVICE_READY = 220;

  29.     /** SMTP reply code {@value}. */
  30.     public static final int SERVICE_CLOSING_TRANSMISSION_CHANNEL = 221;

  31.     /** SMTP reply code {@value}. */
  32.     public static final int ACTION_OK = 250;

  33.     /** SMTP reply code {@value}. */
  34.     public static final int USER_NOT_LOCAL_WILL_FORWARD = 251;

  35.     /** SMTP reply code {@value}. */
  36.     public static final int START_MAIL_INPUT = 354;

  37.     /** SMTP reply code {@value}. */
  38.     public static final int SERVICE_NOT_AVAILABLE = 421;

  39.     /** SMTP reply code {@value}. */
  40.     public static final int ACTION_NOT_TAKEN = 450;

  41.     /** SMTP reply code {@value}. */
  42.     public static final int ACTION_ABORTED = 451;

  43.     /** SMTP reply code {@value}. */
  44.     public static final int INSUFFICIENT_STORAGE = 452;

  45.     /** SMTP reply code {@value}. */
  46.     public static final int UNRECOGNIZED_COMMAND = 500;

  47.     /** SMTP reply code {@value}. */
  48.     public static final int SYNTAX_ERROR_IN_ARGUMENTS = 501;

  49.     /** SMTP reply code {@value}. */
  50.     public static final int COMMAND_NOT_IMPLEMENTED = 502;

  51.     /** SMTP reply code {@value}. */
  52.     public static final int BAD_COMMAND_SEQUENCE = 503;

  53.     /** SMTP reply code {@value}. */
  54.     public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504;

  55.     /** SMTP reply code {@value}. */
  56.     public static final int MAILBOX_UNAVAILABLE = 550;

  57.     /** SMTP reply code {@value}. */
  58.     public static final int USER_NOT_LOCAL = 551;

  59.     /** SMTP reply code {@value}. */

  60.     /** SMTP reply code {@value}. */
  61.     public static final int STORAGE_ALLOCATION_EXCEEDED = 552;

  62.     /** SMTP reply code {@value}. */
  63.     public static final int MAILBOX_NAME_NOT_ALLOWED = 553;

  64.     /** SMTP reply code {@value}. */
  65.     public static final int TRANSACTION_FAILED = 554;

  66.     /**
  67.      * 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
  68.      * negative permanent response on the failure of a command that cannot be reattempted with success.
  69.      *
  70.      * @param reply The reply code to test.
  71.      * @return True if a reply code is a negative permanent response, false if not.
  72.      */
  73.     public static boolean isNegativePermanent(final int reply) {
  74.         return reply >= 500 && reply < 600;
  75.     }

  76.     /**
  77.      * 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
  78.      * negative transient response on the failure of a command that can be reattempted with success.
  79.      *
  80.      * @param reply The reply code to test.
  81.      * @return True if a reply code is a negative transient response, false if not.
  82.      */
  83.     public static boolean isNegativeTransient(final int reply) {
  84.         return reply >= 400 && reply < 500;
  85.     }

  86.     /**
  87.      * 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
  88.      * positive completion response on the final successful completion of a command.
  89.      *
  90.      * @param reply The reply code to test.
  91.      * @return True if a reply code is a positive completion response, false if not.
  92.      */
  93.     public static boolean isPositiveCompletion(final int reply) {
  94.         return reply >= 200 && reply < 300;
  95.     }

  96.     /**
  97.      * Tests if a reply code is a positive intermediate response. All codes beginning with a 3 are positive intermediate responses. The SMTP server will
  98.      * send a positive intermediate response on the successful completion of one part of a multipart sequence of commands. For example, after a successful DATA
  99.      * command, a positive intermediate response will be sent to indicate that the server is ready to receive the message data.
  100.      *
  101.      * @param reply The reply code to test.
  102.      * @return True if a reply code is a positive intermediate response, false if not.
  103.      */
  104.     public static boolean isPositiveIntermediate(final int reply) {
  105.         return reply >= 300 && reply < 400;
  106.     }

  107.     /**
  108.      * Tests if a reply code is a positive preliminary response. All codes beginning with a 1 are positive preliminary responses. Positive preliminary
  109.      * responses are used to indicate tentative success. No further commands can be issued to the SMTP server after a positive preliminary response until a
  110.      * follow-up response is received from the server.
  111.      * <p>
  112.      * <b>Note:</b> <em> No SMTP commands defined in RFC 822 provide this type of reply. </em>
  113.      * </p>
  114.      *
  115.      * @param reply The reply code to test.
  116.      * @return True if a reply code is a positive preliminary response, false if not.
  117.      */
  118.     public static boolean isPositivePreliminary(final int reply) {
  119.         return reply >= 100 && reply < 200;
  120.     }

  121.     /** Cannot be instantiated. */
  122.     private SMTPReply() {
  123.     }

  124. }