IMAPCommand.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.imap;

  18. /**
  19.  * IMAPCommand stores IMAP command codes.
  20.  */
  21. public enum IMAPCommand {
  22.     // These enums must either use the same name as the IMAP command
  23.     // or must provide the correct string as the parameter.

  24.     // Commands valid in any state:
  25.     /**
  26.      * Valid in any state.
  27.      */
  28.     CAPABILITY(0),

  29.     /**
  30.      * Valid in any state.
  31.      */
  32.     NOOP(0),

  33.     /**
  34.      * Valid in any state.
  35.      */
  36.     LOGOUT(0),

  37.     // Commands valid in Not Authenticated state
  38.     /**
  39.      * Valid in Not Authenticated state
  40.      */
  41.     STARTTLS(0),

  42.     /**
  43.      * Valid in Not Authenticated state
  44.      */
  45.     AUTHENTICATE(1),

  46.     /**
  47.      * Valid in Not Authenticated state
  48.      */
  49.     LOGIN(2),

  50.     XOAUTH(1),

  51.     // commands valid in authenticated state
  52.     /**
  53.      * Valid in authenticated state.
  54.      */
  55.     SELECT(1),

  56.     /**
  57.      * Valid in authenticated state.
  58.      */
  59.     EXAMINE(1),

  60.     /**
  61.      * Valid in authenticated state.
  62.      */
  63.     CREATE(1),

  64.     /**
  65.      * Valid in authenticated state.
  66.      */
  67.     DELETE(1),

  68.     /**
  69.      * Valid in authenticated state.
  70.      */
  71.     RENAME(2),
  72.     /**
  73.      * Valid in authenticated state.
  74.      */
  75.     SUBSCRIBE(1),
  76.     /**
  77.      * Valid in authenticated state.
  78.      */
  79.     UNSUBSCRIBE(1),
  80.     /**
  81.      * Valid in authenticated state.
  82.      */
  83.     LIST(2),
  84.     /**
  85.      * Valid in authenticated state.
  86.      */
  87.     LSUB(2),
  88.     /**
  89.      * Valid in authenticated state.
  90.      */
  91.     STATUS(2), // P2 = list in ()

  92.     /**
  93.      * Valid in authenticated state.
  94.      */
  95.     APPEND(2, 4), // mbox [(flags)] [date-time] literal

  96.     // commands valid in selected state (substate of authenticated)
  97.     /**
  98.      * Valid in selected state (substate of authenticated).
  99.      */
  100.     CHECK(0),

  101.     /**
  102.      * Valid in selected state (substate of authenticated).
  103.      */
  104.     CLOSE(0),

  105.     /**
  106.      * Valid in selected state (substate of authenticated).
  107.      */
  108.     EXPUNGE(0),

  109.     /**
  110.      * Valid in selected state (substate of authenticated).
  111.      */
  112.     SEARCH(1, Integer.MAX_VALUE),

  113.     /**
  114.      * Valid in selected state (substate of authenticated).
  115.      */
  116.     FETCH(2),

  117.     /**
  118.      * Valid in selected state (substate of authenticated).
  119.      */
  120.     STORE(3),

  121.     /**
  122.      * Valid in selected state (substate of authenticated).
  123.      */
  124.     COPY(2),

  125.     /**
  126.      * Valid in selected state (substate of authenticated).
  127.      */
  128.     UID(2, Integer.MAX_VALUE);

  129.     /**
  130.      * Gets the IMAP protocol string command corresponding to a command code.
  131.      *
  132.      * @param command the {@link IMAPCommand} whose command string is required. Must not be null.
  133.      * @return The IMAP protocol string command corresponding to a command code.
  134.      */
  135.     public static final String getCommand(final IMAPCommand command) {
  136.         return command.getIMAPCommand();
  137.     }

  138.     private final String imapCommand;

  139.     @SuppressWarnings("unused") // not yet used
  140.     private final int minParamCount;

  141.     @SuppressWarnings("unused") // not yet used
  142.     private final int maxParamCount;

  143.     IMAPCommand() {
  144.         this(null);
  145.     }

  146.     IMAPCommand(final int paramCount) {
  147.         this(null, paramCount, paramCount);
  148.     }

  149.     IMAPCommand(final int minCount, final int maxCount) {
  150.         this(null, minCount, maxCount);
  151.     }

  152.     IMAPCommand(final String name) {
  153.         this(name, 0);
  154.     }

  155.     IMAPCommand(final String name, final int paramCount) {
  156.         this(name, paramCount, paramCount);
  157.     }

  158.     IMAPCommand(final String name, final int minCount, final int maxCount) {
  159.         this.imapCommand = name;
  160.         this.minParamCount = minCount;
  161.         this.maxParamCount = maxCount;
  162.     }

  163.     /**
  164.      * Gets the IMAP protocol string command for this command
  165.      *
  166.      * @return The IMAP protocol string command corresponding to this command
  167.      */
  168.     public String getIMAPCommand() {
  169.         return imapCommand != null ? imapCommand : name();
  170.     }

  171. }