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 * http://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.smtp; 019 020/** 021 * SMTPCommand stores a set of constants for SMTP command codes. To interpret the meaning of the codes, familiarity with RFC 821 is assumed. The mnemonic 022 * constant names are transcriptions from the code descriptions of RFC 821. For those who think in terms of the actual SMTP commands, a set of constants such as 023 * {@link #HELO HELO } are provided where the constant name is the same as the SMTP command. 024 */ 025public final class SMTPCommand { 026 027 /** SMTP command {@value}. */ 028 public static final int HELO = 0; 029 030 /** SMTP command {@value}. */ 031 public static final int MAIL = 1; 032 033 /** SMTP command {@value}. */ 034 public static final int RCPT = 2; 035 036 /** SMTP command {@value}. */ 037 public static final int DATA = 3; 038 039 /** SMTP command {@value}. */ 040 public static final int SEND = 4; 041 042 /** SMTP command {@value}. */ 043 public static final int SOML = 5; 044 045 /** SMTP command {@value}. */ 046 public static final int SAML = 6; 047 048 /** SMTP command {@value}. */ 049 public static final int RSET = 7; 050 051 /** SMTP command {@value}. */ 052 public static final int VRFY = 8; 053 054 /** SMTP command {@value}. */ 055 public static final int EXPN = 9; 056 057 /** SMTP command {@value}. */ 058 public static final int HELP = 10; 059 060 /** SMTP command {@value}. */ 061 public static final int NOOP = 11; 062 063 /** SMTP command {@value}. */ 064 public static final int TURN = 12; 065 066 /** SMTP command {@value}. */ 067 public static final int QUIT = 13; 068 069 /** 070 * The authorization command 071 * 072 * @since 3.0 073 */ 074 public static final int AUTH = 14; 075 076 /** 077 * The extended hello command 078 * 079 * @since 3.0 080 */ 081 public static final int EHLO = 15; 082 083 private static final int NEXT = EHLO + 1; // update as necessary when adding new entries 084 085 /** Alias for {@value}. */ 086 public static final int HELLO = HELO; 087 088 /** Alias for {@value}. */ 089 public static final int LOGIN = HELO; 090 091 /** Alias for {@value}. */ 092 public static final int MAIL_FROM = MAIL; 093 094 /** Alias for {@value}. */ 095 public static final int RECIPIENT = RCPT; 096 097 /** Alias for {@value}. */ 098 public static final int SEND_MESSAGE_DATA = DATA; 099 100 /** Alias for {@value}. */ 101 public static final int SEND_FROM = SEND; 102 103 /** Alias for {@value}. */ 104 public static final int SEND_OR_MAIL_FROM = SOML; 105 106 /** Alias for {@value}. */ 107 public static final int SEND_AND_MAIL_FROM = SAML; 108 109 /** Alias for {@value}. */ 110 public static final int RESET = RSET; 111 112 /** Alias for {@value}. */ 113 public static final int VERIFY = VRFY; 114 115 /** Alias for {@value}. */ 116 public static final int EXPAND = EXPN; 117 118 /** Alias for {@value}. */ 119 public static final int LOGOUT = QUIT; 120 121 private static final String[] commands = { "HELO", "MAIL FROM:", "RCPT TO:", "DATA", "SEND FROM:", "SOML FROM:", "SAML FROM:", "RSET", "VRFY", "EXPN", 122 "HELP", "NOOP", "TURN", "QUIT", "AUTH", "EHLO" }; 123 124 static { 125 if (commands.length != NEXT) { 126 throw new IllegalStateException("Error in array definition"); 127 } 128 } 129 130 /** 131 * Gets the SMTP protocol command string corresponding to a specified command code. 132 * 133 * @param command The command code. 134 * @return The SMTP protocol command string corresponding to a specified command code. 135 */ 136 public static String getCommand(final int command) { 137 return commands[command]; 138 } 139 140 /** Cannot be instantiated. */ 141 private SMTPCommand() { 142 } 143 144}