View Javadoc
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  
18  package org.apache.commons.net.imap;
19  
20  /**
21   * IMAPCommand stores IMAP command codes.
22   */
23  public enum IMAPCommand {
24      // These enums must either use the same name as the IMAP command
25      // or must provide the correct string as the parameter.
26  
27      // Commands valid in any state:
28      /**
29       * Valid in any state.
30       */
31      CAPABILITY(0),
32  
33      /**
34       * Valid in any state.
35       */
36      NOOP(0),
37  
38      /**
39       * Valid in any state.
40       */
41      LOGOUT(0),
42  
43      // Commands valid in Not Authenticated state
44      /**
45       * Valid in Not Authenticated state
46       */
47      STARTTLS(0),
48  
49      /**
50       * Valid in Not Authenticated state
51       */
52      AUTHENTICATE(1),
53  
54      /**
55       * Valid in Not Authenticated state
56       */
57      LOGIN(2),
58  
59      XOAUTH(1),
60  
61      // commands valid in authenticated state
62      /**
63       * Valid in authenticated state.
64       */
65      SELECT(1),
66  
67      /**
68       * Valid in authenticated state.
69       */
70      EXAMINE(1),
71  
72      /**
73       * Valid in authenticated state.
74       */
75      CREATE(1),
76  
77      /**
78       * Valid in authenticated state.
79       */
80      DELETE(1),
81  
82      /**
83       * Valid in authenticated state.
84       */
85      RENAME(2),
86      /**
87       * Valid in authenticated state.
88       */
89      SUBSCRIBE(1),
90      /**
91       * Valid in authenticated state.
92       */
93      UNSUBSCRIBE(1),
94      /**
95       * Valid in authenticated state.
96       */
97      LIST(2),
98      /**
99       * Valid in authenticated state.
100      */
101     LSUB(2),
102     /**
103      * Valid in authenticated state.
104      */
105     STATUS(2), // P2 = list in ()
106 
107     /**
108      * Valid in authenticated state.
109      */
110     APPEND(2, 4), // mbox [(flags)] [date-time] literal
111 
112     // commands valid in selected state (substate of authenticated)
113     /**
114      * Valid in selected state (substate of authenticated).
115      */
116     CHECK(0),
117 
118     /**
119      * Valid in selected state (substate of authenticated).
120      */
121     CLOSE(0),
122 
123     /**
124      * Valid in selected state (substate of authenticated).
125      */
126     EXPUNGE(0),
127 
128     /**
129      * Valid in selected state (substate of authenticated).
130      */
131     SEARCH(1, Integer.MAX_VALUE),
132 
133     /**
134      * Valid in selected state (substate of authenticated).
135      */
136     FETCH(2),
137 
138     /**
139      * Valid in selected state (substate of authenticated).
140      */
141     STORE(3),
142 
143     /**
144      * Valid in selected state (substate of authenticated).
145      */
146     COPY(2),
147 
148     /**
149      * Valid in selected state (substate of authenticated).
150      */
151     UID(2, Integer.MAX_VALUE);
152 
153     /**
154      * Get the IMAP protocol string command corresponding to a command code.
155      *
156      * @param command the {@link IMAPCommand} whose command string is required. Must not be null.
157      * @return The IMAP protocol string command corresponding to a command code.
158      */
159     public static final String getCommand(final IMAPCommand command) {
160         return command.getIMAPCommand();
161     }
162 
163     private final String imapCommand;
164 
165     @SuppressWarnings("unused") // not yet used
166     private final int minParamCount;
167 
168     @SuppressWarnings("unused") // not yet used
169     private final int maxParamCount;
170 
171     IMAPCommand() {
172         this(null);
173     }
174 
175     IMAPCommand(final int paramCount) {
176         this(null, paramCount, paramCount);
177     }
178 
179     IMAPCommand(final int minCount, final int maxCount) {
180         this(null, minCount, maxCount);
181     }
182 
183     IMAPCommand(final String name) {
184         this(name, 0);
185     }
186 
187     IMAPCommand(final String name, final int paramCount) {
188         this(name, paramCount, paramCount);
189     }
190 
191     IMAPCommand(final String name, final int minCount, final int maxCount) {
192         this.imapCommand = name;
193         this.minParamCount = minCount;
194         this.maxParamCount = maxCount;
195     }
196 
197     /**
198      * Gets the IMAP protocol string command for this command
199      *
200      * @return The IMAP protocol string command corresponding to this command
201      */
202     public String getIMAPCommand() {
203         return imapCommand != null ? imapCommand : name();
204     }
205 
206 }
207 
208