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    
018    package org.apache.commons.net.imap;
019    
020    /**
021     * IMAPCommand stores IMAP command codes.
022     */
023    public enum IMAPCommand
024    {
025        // These enums must either use the same name as the IMAP command
026        // or must provide the correct string as the parameter.
027        
028        // Commands valid in any state:
029        
030        CAPABILITY(0),
031        NOOP(0),
032        LOGOUT(0),
033        
034        // Commands valid in Not Authenticated state
035        STARTTLS(0),
036        AUTHENTICATE(1),
037        LOGIN(2),
038        
039        XOAUTH(1),
040        
041        // commands valid in authenticated state
042        SELECT(1),
043        EXAMINE(1),
044        CREATE(1),
045        DELETE(1),
046        RENAME(2),
047        SUBSCRIBE(1),
048        UNSUBSCRIBE(1),
049        LIST(2),
050        LSUB(2),
051        STATUS(2), // P2 = list in ()
052        APPEND(2,4), // mbox [(flags)] [date-time] literal
053        
054        // commands valid in selected state (substate of authenticated)
055        CHECK(0),
056        CLOSE(0),
057        EXPUNGE(0),
058        SEARCH(1, Integer.MAX_VALUE),
059        FETCH(2),
060        STORE(3),
061        COPY(2),
062        UID(2, Integer.MAX_VALUE),
063        ;
064        
065        private final String imapCommand;
066        
067        @SuppressWarnings("unused") // not yet used
068        private final int minParamCount;
069        @SuppressWarnings("unused") // not yet used
070        private final int maxParamCount;
071    
072        IMAPCommand(){
073            this(null);
074        }
075        
076        IMAPCommand(String name){
077            this(name, 0);
078        }
079        
080        IMAPCommand(int paramCount){
081            this(null, paramCount, paramCount);
082       }
083        
084        IMAPCommand(int minCount, int maxCount){
085            this(null, minCount, maxCount);
086       }
087        
088        IMAPCommand(String name, int paramCount){
089            this(name, paramCount, paramCount);
090        }
091        
092        IMAPCommand(String name, int minCount, int maxCount){
093            this.imapCommand = name;
094            this.minParamCount = minCount;
095            this.maxParamCount = maxCount;
096        }
097    
098        /**
099         * Get the IMAP protocol string command corresponding to a command code.
100         *
101         * @param command the IMAPCommand whose command string is required.
102         * @return The IMAP protocol string command corresponding to a command code.
103         */
104        public static final String getCommand(IMAPCommand command) {
105            return command.getIMAPCommand();
106        }
107    
108        /**
109         * Get the IMAP protocol string command for this command
110         *
111         * @return The IMAP protocol string command corresponding to this command
112         */
113        public String getIMAPCommand() {
114            return imapCommand != null ? imapCommand : name();
115        }
116    
117    }
118    
119    /* kate: indent-width 4; replace-tabs on; */