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        // commands valid in authenticated state
040        SELECT(1),
041        EXAMINE(1),
042        CREATE(1),
043        DELETE(1),
044        RENAME(2),
045        SUBSCRIBE(1),
046        UNSUBSCRIBE(1),
047        LIST(2),
048        LSUB(2),
049        STATUS(2), // P2 = list in ()
050        APPEND(2,4), // mbox [(flags)] [date-time] literal
051        
052        // commands valid in selected state (substate of authenticated)
053        CHECK(0),
054        CLOSE(0),
055        EXPUNGE(0),
056        SEARCH(1, Integer.MAX_VALUE),
057        FETCH(2),
058        STORE(3),
059        COPY(2),
060        UID(2, Integer.MAX_VALUE),
061        ;
062        
063        private final String imapCommand;
064        
065        @SuppressWarnings("unused") // not yet used
066        private final int minParamCount;
067        @SuppressWarnings("unused") // not yet used
068        private final int maxParamCount;
069    
070        IMAPCommand(){
071            this(null);
072        }
073        
074        IMAPCommand(String name){
075            this(name, 0);
076        }
077        
078        IMAPCommand(int paramCount){
079            this(null, paramCount, paramCount);
080       }
081        
082        IMAPCommand(int minCount, int maxCount){
083            this(null, minCount, maxCount);
084       }
085        
086        IMAPCommand(String name, int paramCount){
087            this(name, paramCount, paramCount);
088        }
089        
090        IMAPCommand(String name, int minCount, int maxCount){
091            this.imapCommand = name;
092            this.minParamCount = minCount;
093            this.maxParamCount = maxCount;
094        }
095    
096        /**
097         * Get the IMAP protocol string command corresponding to a command code.
098         *
099         * @param command the IMAPCommand whose command string is required.
100         * @return The IMAP protocol string command corresponding to a command code.
101         */
102        public static final String getCommand(IMAPCommand command) {
103            return command.getIMAPCommand();
104        }
105    
106        /**
107         * Get the IMAP protocol string command for this command
108         *
109         * @return The IMAP protocol string command corresponding to this command
110         */
111        public String getIMAPCommand() {
112            return imapCommand != null ? imapCommand : name();
113        }
114    
115    }
116    
117    /* kate: indent-width 4; replace-tabs on; */