    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.net.imap;
    019
    020/**
    021 * IMAPCommand stores IMAP command codes.
    022 */
    023public enum IMAPCommand {
    024    // These enums must either use the same name as the IMAP command
    025    // or must provide the correct string as the parameter.
    026
    027    // Commands valid in any state:
    028
    029    CAPABILITY(0), NOOP(0), LOGOUT(0),
    030
    031    // Commands valid in Not Authenticated state
    032    STARTTLS(0), AUTHENTICATE(1), LOGIN(2),
    033
    034    XOAUTH(1),
    035
    036    // commands valid in authenticated state
    037    SELECT(1), EXAMINE(1), CREATE(1), DELETE(1), RENAME(2), SUBSCRIBE(1), UNSUBSCRIBE(1), LIST(2), LSUB(2), STATUS(2), // P2 = list in ()
    038    APPEND(2, 4), // mbox [(flags)] [date-time] literal
    039
    040    // commands valid in selected state (substate of authenticated)
    041    CHECK(0), CLOSE(0), EXPUNGE(0), SEARCH(1, Integer.MAX_VALUE), FETCH(2), STORE(3), COPY(2), UID(2, Integer.MAX_VALUE),;
    042
    043    /**
    044     * Get the IMAP protocol string command corresponding to a command code.
    045     *
    046     * @param command the IMAPCommand whose command string is required.
    047     * @return The IMAP protocol string command corresponding to a command code.
    048     */
    049    public static final String getCommand(final IMAPCommand command) {
    050        return command.getIMAPCommand();
    051    }
    052
    053    private final String imapCommand;
    054    @SuppressWarnings("unused") // not yet used
    055    private final int minParamCount;
    056
    057    @SuppressWarnings("unused") // not yet used
    058    private final int maxParamCount;
    059
    060    IMAPCommand() {
    061        this(null);
    062    }
    063
    064    IMAPCommand(final int paramCount) {
    065        this(null, paramCount, paramCount);
    066    }
    067
    068    IMAPCommand(final int minCount, final int maxCount) {
    069        this(null, minCount, maxCount);
    070    }
    071
    072    IMAPCommand(final String name) {
    073        this(name, 0);
    074    }
    075
    076    IMAPCommand(final String name, final int paramCount) {
    077        this(name, paramCount, paramCount);
    078    }
    079
    080    IMAPCommand(final String name, final int minCount, final int maxCount) {
    081        this.imapCommand = name;
    082        this.minParamCount = minCount;
    083        this.maxParamCount = maxCount;
    084    }
    085
    086    /**
    087     * Get the IMAP protocol string command for this command
    088     *
    089     * @return The IMAP protocol string command corresponding to this command
    090     */
    091    public String getIMAPCommand() {
    092        return imapCommand != null ? imapCommand : name();
    093    }
    094
    095}
    096
    097/* kate: indent-width 4; replace-tabs on; */