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 /**
28 * Valid in any state.
29 */
30 CAPABILITY(0),
31
32 /**
33 * Valid in any state.
34 */
35 NOOP(0),
36
37 /**
38 * Valid in any state.
39 */
40 LOGOUT(0),
41
42 /**
43 * Valid in Not Authenticated state.
44 */
45 STARTTLS(0),
46
47 /**
48 * Valid in Not Authenticated state.
49 */
50 AUTHENTICATE(1),
51
52 /**
53 * Valid in Not Authenticated state.
54 */
55 LOGIN(2),
56
57 /**
58 * Authenticate an IMAP connection using OAuth.
59 */
60 XOAUTH(1),
61
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 /**
88 * Valid in authenticated state.
89 */
90 SUBSCRIBE(1),
91
92 /**
93 * Valid in authenticated state.
94 */
95 UNSUBSCRIBE(1),
96
97 /**
98 * Valid in authenticated state.
99 */
100 LIST(2),
101
102 /**
103 * Valid in authenticated state.
104 */
105 LSUB(2),
106
107 /**
108 * Valid in authenticated state.
109 */
110 STATUS(2), // P2 = list in ()
111
112 /**
113 * Valid in authenticated state.
114 */
115 APPEND(2, 4), // mbox [(flags)] [date-time] literal
116
117 /**
118 * Valid in selected state (substate of authenticated).
119 */
120 CHECK(0),
121
122 /**
123 * Valid in selected state (substate of authenticated).
124 */
125 CLOSE(0),
126
127 /**
128 * Valid in selected state (substate of authenticated).
129 */
130 EXPUNGE(0),
131
132 /**
133 * Valid in selected state (substate of authenticated).
134 */
135 SEARCH(1, Integer.MAX_VALUE),
136
137 /**
138 * Valid in selected state (substate of authenticated).
139 */
140 FETCH(2),
141
142 /**
143 * Valid in selected state (substate of authenticated).
144 */
145 STORE(3),
146
147 /**
148 * Valid in selected state (substate of authenticated).
149 */
150 COPY(2),
151
152 /**
153 * Valid in selected state (substate of authenticated).
154 */
155 UID(2, Integer.MAX_VALUE);
156
157 /**
158 * Gets the IMAP protocol string command corresponding to a command code.
159 *
160 * @param command the {@link IMAPCommand} whose command string is required. Must not be null.
161 * @return The IMAP protocol string command corresponding to a command code.
162 */
163 public static String getCommand(final IMAPCommand command) {
164 return command.getIMAPCommand();
165 }
166
167 private final String imapCommand;
168
169 @SuppressWarnings("unused") // not yet used
170 private final int minParamCount;
171
172 @SuppressWarnings("unused") // not yet used
173 private final int maxParamCount;
174
175 IMAPCommand() {
176 this(null);
177 }
178
179 IMAPCommand(final int paramCount) {
180 this(null, paramCount, paramCount);
181 }
182
183 IMAPCommand(final int minCount, final int maxCount) {
184 this(null, minCount, maxCount);
185 }
186
187 IMAPCommand(final String name) {
188 this(name, 0);
189 }
190
191 IMAPCommand(final String name, final int paramCount) {
192 this(name, paramCount, paramCount);
193 }
194
195 IMAPCommand(final String name, final int minCount, final int maxCount) {
196 this.imapCommand = name;
197 this.minParamCount = minCount;
198 this.maxParamCount = maxCount;
199 }
200
201 /**
202 * Gets the IMAP protocol string command for this command
203 *
204 * @return The IMAP protocol string command corresponding to this command
205 */
206 public String getIMAPCommand() {
207 return imapCommand != null ? imapCommand : name();
208 }
209
210 }
211