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 * https://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 /**
60 * Authenticate an IMAP connection using OAuth.
61 */
62 XOAUTH(1),
63
64 // commands valid in authenticated state
65 /**
66 * Valid in authenticated state.
67 */
68 SELECT(1),
69
70 /**
71 * Valid in authenticated state.
72 */
73 EXAMINE(1),
74
75 /**
76 * Valid in authenticated state.
77 */
78 CREATE(1),
79
80 /**
81 * Valid in authenticated state.
82 */
83 DELETE(1),
84
85 /**
86 * Valid in authenticated state.
87 */
88 RENAME(2),
89 /**
90 * Valid in authenticated state.
91 */
92 SUBSCRIBE(1),
93 /**
94 * Valid in authenticated state.
95 */
96 UNSUBSCRIBE(1),
97 /**
98 * Valid in authenticated state.
99 */
100 LIST(2),
101 /**
102 * Valid in authenticated state.
103 */
104 LSUB(2),
105 /**
106 * Valid in authenticated state.
107 */
108 STATUS(2), // P2 = list in ()
109
110 /**
111 * Valid in authenticated state.
112 */
113 APPEND(2, 4), // mbox [(flags)] [date-time] literal
114
115 // commands valid in selected state (substate of authenticated)
116 /**
117 * Valid in selected state (substate of authenticated).
118 */
119 CHECK(0),
120
121 /**
122 * Valid in selected state (substate of authenticated).
123 */
124 CLOSE(0),
125
126 /**
127 * Valid in selected state (substate of authenticated).
128 */
129 EXPUNGE(0),
130
131 /**
132 * Valid in selected state (substate of authenticated).
133 */
134 SEARCH(1, Integer.MAX_VALUE),
135
136 /**
137 * Valid in selected state (substate of authenticated).
138 */
139 FETCH(2),
140
141 /**
142 * Valid in selected state (substate of authenticated).
143 */
144 STORE(3),
145
146 /**
147 * Valid in selected state (substate of authenticated).
148 */
149 COPY(2),
150
151 /**
152 * Valid in selected state (substate of authenticated).
153 */
154 UID(2, Integer.MAX_VALUE);
155
156 /**
157 * Gets the IMAP protocol string command corresponding to a command code.
158 *
159 * @param command the {@link IMAPCommand} whose command string is required. Must not be null.
160 * @return The IMAP protocol string command corresponding to a command code.
161 */
162 public static String getCommand(final IMAPCommand command) {
163 return command.getIMAPCommand();
164 }
165
166 private final String imapCommand;
167
168 @SuppressWarnings("unused") // not yet used
169 private final int minParamCount;
170
171 @SuppressWarnings("unused") // not yet used
172 private final int maxParamCount;
173
174 IMAPCommand() {
175 this(null);
176 }
177
178 IMAPCommand(final int paramCount) {
179 this(null, paramCount, paramCount);
180 }
181
182 IMAPCommand(final int minCount, final int maxCount) {
183 this(null, minCount, maxCount);
184 }
185
186 IMAPCommand(final String name) {
187 this(name, 0);
188 }
189
190 IMAPCommand(final String name, final int paramCount) {
191 this(name, paramCount, paramCount);
192 }
193
194 IMAPCommand(final String name, final int minCount, final int maxCount) {
195 this.imapCommand = name;
196 this.minParamCount = minCount;
197 this.maxParamCount = maxCount;
198 }
199
200 /**
201 * Gets the IMAP protocol string command for this command
202 *
203 * @return The IMAP protocol string command corresponding to this command
204 */
205 public String getIMAPCommand() {
206 return imapCommand != null ? imapCommand : name();
207 }
208
209 }
210