Package org.apache.commons.net.imap
Class IMAPClient
- java.lang.Object
-
- org.apache.commons.net.SocketClient
-
- org.apache.commons.net.imap.IMAP
-
- org.apache.commons.net.imap.IMAPClient
-
- Direct Known Subclasses:
IMAPSClient
public class IMAPClient extends IMAP
The IMAPClient class provides the basic functionalities found in an IMAP client.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIMAPClient.FETCH_ITEM_NAMESThe message data item names for the FETCH command defined in RFC 3501.static classIMAPClient.SEARCH_CRITERIAThe search criteria defined in RFC 3501.static classIMAPClient.STATUS_DATA_ITEMSThe status data items defined in RFC 3501.-
Nested classes/interfaces inherited from class org.apache.commons.net.imap.IMAP
IMAP.IMAPChunkListener, IMAP.IMAPState
-
-
Field Summary
-
Fields inherited from class org.apache.commons.net.imap.IMAP
__DEFAULT_ENCODING, __writer, _reader, DEFAULT_PORT, TRUE_CHUNK_LISTENER
-
Fields inherited from class org.apache.commons.net.SocketClient
_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL
-
-
Constructor Summary
Constructors Constructor Description IMAPClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanappend(java.lang.String mailboxName)Deprecated.(3.4) Does not work; the message body is not optional.booleanappend(java.lang.String mailboxName, java.lang.String flags, java.lang.String datetime)Deprecated.(3.4) Does not work; the message body is not optional.booleanappend(java.lang.String mailboxName, java.lang.String flags, java.lang.String datetime, java.lang.String message)Send an APPEND command to the server.booleancapability()Send a CAPABILITY command to the server.booleancheck()Send a CHECK command to the server.booleanclose()Send a CLOSE command to the server.booleancopy(java.lang.String sequenceSet, java.lang.String mailboxName)Send a COPY command to the server.booleancreate(java.lang.String mailboxName)Send a CREATE command to the server.booleandelete(java.lang.String mailboxName)Send a DELETE command to the server.booleanexamine(java.lang.String mailboxName)Send an EXAMINE command to the server.booleanexpunge()Send an EXPUNGE command to the server.booleanfetch(java.lang.String sequenceSet, java.lang.String itemNames)Send a FETCH command to the server.booleanlist(java.lang.String refName, java.lang.String mailboxName)Send a LIST command to the server.booleanlogin(java.lang.String username, java.lang.String password)Login to the IMAP server with the given username and password.booleanlogout()Send a LOGOUT command to the server.booleanlsub(java.lang.String refName, java.lang.String mailboxName)Send an LSUB command to the server.booleannoop()Send a NOOP command to the server.booleanrename(java.lang.String oldMailboxName, java.lang.String newMailboxName)Send a RENAME command to the server.booleansearch(java.lang.String criteria)Send a SEARCH command to the server.booleansearch(java.lang.String charset, java.lang.String criteria)Send a SEARCH command to the server.booleanselect(java.lang.String mailboxName)Send a SELECT command to the server.booleanstatus(java.lang.String mailboxName, java.lang.String[] itemNames)Send a STATUS command to the server.booleanstore(java.lang.String sequenceSet, java.lang.String itemNames, java.lang.String itemValues)Send a STORE command to the server.booleansubscribe(java.lang.String mailboxName)Send a SUBSCRIBE command to the server.booleanuid(java.lang.String command, java.lang.String commandArgs)Send a UID command to the server.booleanunsubscribe(java.lang.String mailboxName)Send a UNSUBSCRIBE command to the server.-
Methods inherited from class org.apache.commons.net.imap.IMAP
_connectAction_, disconnect, doCommand, doCommand, fireReplyReceived, generateCommandID, getReplyString, getReplyStrings, getState, sendCommand, sendCommand, sendCommand, sendCommand, sendData, setChunkListener, setState
-
Methods inherited from class org.apache.commons.net.SocketClient
addProtocolCommandListener, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, getCharset, getCharsetName, getCommandSupport, getConnectTimeout, getDefaultPort, getDefaultTimeout, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemotePort, getSendBufferSize, getServerSocketFactory, getSoLinger, getSoTimeout, getTcpNoDelay, isAvailable, isConnected, removeProtocolCommandListener, setCharset, setConnectTimeout, setDefaultPort, setDefaultTimeout, setKeepAlive, setProxy, setReceiveBufferSize, setSendBufferSize, setServerSocketFactory, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
-
-
-
-
Method Detail
-
capability
public boolean capability() throws java.io.IOExceptionSend a CAPABILITY command to the server.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs
-
noop
public boolean noop() throws java.io.IOExceptionSend a NOOP command to the server. This is useful for keeping a connection alive since most IMAP servers will timeout after 10 minutes of inactivity.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
logout
public boolean logout() throws java.io.IOExceptionSend a LOGOUT command to the server. To fully disconnect from the server you must call disconnect(). A logout attempt is valid in any state. If the client is in the not authenticated or authenticated state, it enters the logout on a successful logout.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
login
public boolean login(java.lang.String username, java.lang.String password) throws java.io.IOExceptionLogin to the IMAP server with the given username and password. You must first connect to the server withconnectbefore attempting to login. A login attempt is only valid if the client is in the NOT_AUTH_STATE. After logging in, the client enters the AUTH_STATE.- Parameters:
username- The account name being logged in to.password- The plain text password of the account.- Returns:
- True if the login attempt was successful, false if not.
- Throws:
java.io.IOException- If a network I/O error occurs in the process of logging in.
-
select
public boolean select(java.lang.String mailboxName) throws java.io.IOExceptionSend a SELECT command to the server.- Parameters:
mailboxName- The mailbox name to select.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
examine
public boolean examine(java.lang.String mailboxName) throws java.io.IOExceptionSend an EXAMINE command to the server.- Parameters:
mailboxName- The mailbox name to examine.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
create
public boolean create(java.lang.String mailboxName) throws java.io.IOExceptionSend a CREATE command to the server.- Parameters:
mailboxName- The mailbox name to create.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
delete
public boolean delete(java.lang.String mailboxName) throws java.io.IOExceptionSend a DELETE command to the server.- Parameters:
mailboxName- The mailbox name to delete.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
rename
public boolean rename(java.lang.String oldMailboxName, java.lang.String newMailboxName) throws java.io.IOExceptionSend a RENAME command to the server.- Parameters:
oldMailboxName- The existing mailbox name to rename.newMailboxName- The new mailbox name.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
subscribe
public boolean subscribe(java.lang.String mailboxName) throws java.io.IOExceptionSend a SUBSCRIBE command to the server.- Parameters:
mailboxName- The mailbox name to subscribe to.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
unsubscribe
public boolean unsubscribe(java.lang.String mailboxName) throws java.io.IOExceptionSend a UNSUBSCRIBE command to the server.- Parameters:
mailboxName- The mailbox name to unsubscribe from.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
list
public boolean list(java.lang.String refName, java.lang.String mailboxName) throws java.io.IOExceptionSend a LIST command to the server.- Parameters:
refName- The reference name.mailboxName- The mailbox name.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
lsub
public boolean lsub(java.lang.String refName, java.lang.String mailboxName) throws java.io.IOExceptionSend an LSUB command to the server.- Parameters:
refName- The reference name.mailboxName- The mailbox name.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
status
public boolean status(java.lang.String mailboxName, java.lang.String[] itemNames) throws java.io.IOExceptionSend a STATUS command to the server.- Parameters:
mailboxName- The reference name.itemNames- The status data item names.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
append
public boolean append(java.lang.String mailboxName, java.lang.String flags, java.lang.String datetime, java.lang.String message) throws java.io.IOExceptionSend an APPEND command to the server.- Parameters:
mailboxName- The mailbox name.flags- The flag parenthesized list (optional).datetime- The date/time string (optional).message- The message to append.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.- Since:
- 3.4
-
append
@Deprecated public boolean append(java.lang.String mailboxName, java.lang.String flags, java.lang.String datetime) throws java.io.IOExceptionDeprecated.(3.4) Does not work; the message body is not optional. Useappend(String, String, String, String)instead.Send an APPEND command to the server.- Parameters:
mailboxName- The mailbox name.flags- The flag parenthesized list (optional).datetime- The date/time string (optional).- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
append
@Deprecated public boolean append(java.lang.String mailboxName) throws java.io.IOExceptionDeprecated.(3.4) Does not work; the message body is not optional. Useappend(String, String, String, String)instead.Send an APPEND command to the server.- Parameters:
mailboxName- The mailbox name.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
check
public boolean check() throws java.io.IOExceptionSend a CHECK command to the server.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
close
public boolean close() throws java.io.IOExceptionSend a CLOSE command to the server.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
expunge
public boolean expunge() throws java.io.IOExceptionSend an EXPUNGE command to the server.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
search
public boolean search(java.lang.String charset, java.lang.String criteria) throws java.io.IOExceptionSend a SEARCH command to the server.- Parameters:
charset- The charset (optional).criteria- The search criteria.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
search
public boolean search(java.lang.String criteria) throws java.io.IOExceptionSend a SEARCH command to the server.- Parameters:
criteria- The search criteria.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
fetch
public boolean fetch(java.lang.String sequenceSet, java.lang.String itemNames) throws java.io.IOExceptionSend a FETCH command to the server.- Parameters:
sequenceSet- The sequence set to fetch (e.g. 1:4,6,11,100:*)itemNames- The item names for the FETCH command. (e.g. BODY.PEEK[HEADER.FIELDS (SUBJECT)]) If multiple item names are requested, these must be enclosed in parentheses, e.g. "(UID FLAGS BODY.PEEK[])"- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.- See Also:
IMAP.getReplyString(),IMAP.getReplyStrings()
-
store
public boolean store(java.lang.String sequenceSet, java.lang.String itemNames, java.lang.String itemValues) throws java.io.IOExceptionSend a STORE command to the server.- Parameters:
sequenceSet- The sequence set to update (e.g. 2:5)itemNames- The item name for the STORE command (i.e. [+|-]FLAGS[.SILENT])itemValues- The item values for the STORE command. (e.g. (\Deleted) )- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
copy
public boolean copy(java.lang.String sequenceSet, java.lang.String mailboxName) throws java.io.IOExceptionSend a COPY command to the server.- Parameters:
sequenceSet- The sequence set to fetch.mailboxName- The mailbox name.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
uid
public boolean uid(java.lang.String command, java.lang.String commandArgs) throws java.io.IOExceptionSend a UID command to the server.- Parameters:
command- The command for UID.commandArgs- The arguments for the command.- Returns:
trueif the command was successful,falseif not.- Throws:
java.io.IOException- If a network I/O error occurs.
-
-