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 * https://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 018package org.apache.commons.net.imap; 019 020/** 021 * IMAPCommand stores IMAP command codes. 022 */ 023public enum IMAPCommand { 024 // These enums must either use the same name as the IMAP command 025 // or must provide the correct string as the parameter. 026 027 /** 028 * Valid in any state. 029 */ 030 CAPABILITY(0), 031 032 /** 033 * Valid in any state. 034 */ 035 NOOP(0), 036 037 /** 038 * Valid in any state. 039 */ 040 LOGOUT(0), 041 042 /** 043 * Valid in Not Authenticated state. 044 */ 045 STARTTLS(0), 046 047 /** 048 * Valid in Not Authenticated state. 049 */ 050 AUTHENTICATE(1), 051 052 /** 053 * Valid in Not Authenticated state. 054 */ 055 LOGIN(2), 056 057 /** 058 * Authenticate an IMAP connection using OAuth. 059 */ 060 XOAUTH(1), 061 062 /** 063 * Valid in authenticated state. 064 */ 065 SELECT(1), 066 067 /** 068 * Valid in authenticated state. 069 */ 070 EXAMINE(1), 071 072 /** 073 * Valid in authenticated state. 074 */ 075 CREATE(1), 076 077 /** 078 * Valid in authenticated state. 079 */ 080 DELETE(1), 081 082 /** 083 * Valid in authenticated state. 084 */ 085 RENAME(2), 086 087 /** 088 * Valid in authenticated state. 089 */ 090 SUBSCRIBE(1), 091 092 /** 093 * Valid in authenticated state. 094 */ 095 UNSUBSCRIBE(1), 096 097 /** 098 * Valid in authenticated state. 099 */ 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