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 {
25 // These enums must either use the same name as the IMAP command
26 // or must provide the correct string as the parameter.
27
28 // Commands valid in any state:
29
30 CAPABILITY(0),
31 NOOP(0),
32 LOGOUT(0),
33
34 // Commands valid in Not Authenticated state
35 STARTTLS(0),
36 AUTHENTICATE(1),
37 LOGIN(2),
38
39 XOAUTH(1),
40
41 // commands valid in authenticated state
42 SELECT(1),
43 EXAMINE(1),
44 CREATE(1),
45 DELETE(1),
46 RENAME(2),
47 SUBSCRIBE(1),
48 UNSUBSCRIBE(1),
49 LIST(2),
50 LSUB(2),
51 STATUS(2), // P2 = list in ()
52 APPEND(2,4), // mbox [(flags)] [date-time] literal
53
54 // commands valid in selected state (substate of authenticated)
55 CHECK(0),
56 CLOSE(0),
57 EXPUNGE(0),
58 SEARCH(1, Integer.MAX_VALUE),
59 FETCH(2),
60 STORE(3),
61 COPY(2),
62 UID(2, Integer.MAX_VALUE),
63 ;
64
65 private final String imapCommand;
66
67 @SuppressWarnings("unused") // not yet used
68 private final int minParamCount;
69 @SuppressWarnings("unused") // not yet used
70 private final int maxParamCount;
71
72 IMAPCommand(){
73 this(null);
74 }
75
76 IMAPCommand(String name){
77 this(name, 0);
78 }
79
80 IMAPCommand(int paramCount){
81 this(null, paramCount, paramCount);
82 }
83
84 IMAPCommand(int minCount, int maxCount){
85 this(null, minCount, maxCount);
86 }
87
88 IMAPCommand(String name, int paramCount){
89 this(name, paramCount, paramCount);
90 }
91
92 IMAPCommand(String name, int minCount, int maxCount){
93 this.imapCommand = name;
94 this.minParamCount = minCount;
95 this.maxParamCount = maxCount;
96 }
97
98 /**
99 * 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; */