POP3Command.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.pop3;

  18. /**
  19.  * POP3Command stores POP3 command code constants.
  20.  */

  21. public final class POP3Command {
  22.     /** Send user name. */
  23.     public static final int USER = 0;
  24.     /** Send password. */
  25.     public static final int PASS = 1;
  26.     /** Quit session. */
  27.     public static final int QUIT = 2;
  28.     /** Gets status. */
  29.     public static final int STAT = 3;
  30.     /** List message(s). */
  31.     public static final int LIST = 4;
  32.     /** Retrieve message(s). */
  33.     public static final int RETR = 5;
  34.     /** Delete message(s). */
  35.     public static final int DELE = 6;
  36.     /** No operation. Used as a session keepalive. */
  37.     public static final int NOOP = 7;
  38.     /** Reset session. */
  39.     public static final int RSET = 8;
  40.     /** Authorization. */
  41.     public static final int APOP = 9;
  42.     /** Retrieve top number lines from message. */
  43.     public static final int TOP = 10;
  44.     /** List unique message identifier(s). */
  45.     public static final int UIDL = 11;
  46.     /**
  47.      * The capabilities command.
  48.      *
  49.      * @since 3.0
  50.      */
  51.     public static final int CAPA = 12;
  52.     /**
  53.      * Authentication
  54.      *
  55.      * @since 3.0
  56.      */
  57.     public static final int AUTH = 13;

  58.     private static final int NEXT = AUTH + 1; // update as necessary when adding new entries

  59.     static final String[] commands = { "USER", "PASS", "QUIT", "STAT", "LIST", "RETR", "DELE", "NOOP", "RSET", "APOP", "TOP", "UIDL", "CAPA", "AUTH", };

  60.     static {
  61.         if (commands.length != NEXT) {
  62.             throw new IllegalStateException("Error in array definition");
  63.         }
  64.     }

  65.     /**
  66.      * Gets the POP3 protocol string command corresponding to a command code.
  67.      *
  68.      * @param command the command code
  69.      *
  70.      * @return The POP3 protocol string command corresponding to a command code.
  71.      */
  72.     public static String getCommand(final int command) {
  73.         return commands[command];
  74.     }

  75.     /** Cannot be instantiated. */
  76.     private POP3Command() {
  77.     }
  78. }