public class IMAPConnection extends java.lang.Object implements IMAPConstants
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List |
asyncResponses
List of responses received asynchronously.
|
protected static int |
DEFAULT_PORT
The default IMAP port.
|
protected static int |
DEFAULT_SSL_PORT
The default IMAP-SSL port.
|
static java.util.logging.Level |
IMAP_TRACE
The network trace level.
|
protected IMAPResponseTokenizer |
in
The tokenizer used to read IMAP responses from.
|
static java.util.logging.Logger |
logger
The logger used for IMAP protocol traces.
|
protected CRLFOutputStream |
out
The output stream.
|
protected java.net.Socket |
socket
The socket used for communication with the server.
|
protected static java.lang.String |
TAG_PREFIX
Prefix for tags.
|
protected static java.lang.String |
US_ASCII
The encoding used to create strings for IMAP commands.
|
ACL, ALERT, APPEND, APPENDUID, AUTHENTICATE, BAD, BODY, BODY_PEEK, BODYSTRUCTURE, BYE, CAPABILITY, CHECK, CLOSE, COPY, COPYUID, CRAM_MD5, CREATE, DELETE, DELETEACL, ENVELOPE, EXAMINE, EXISTS, EXPUNGE, FETCH, FETCH_FLAGS, FLAG_ANSWERED, FLAG_DELETED, FLAG_DRAFT, FLAG_FLAGGED, FLAG_RECENT, FLAG_SEEN, FLAGS, GETACL, GETQUOTA, GETQUOTAROOT, GSSAPI, HEADER, HEADER_FIELDS, HEADER_FIELDS_NOT, INTERNALDATE, KERBEROS_V4, LIST, LIST_MARKED, LIST_NOINFERIORS, LIST_NOSELECT, LIST_UNMARKED, LISTRIGHTS, LOGIN, LOGINDISABLED, LOGOUT, LSUB, MESSAGES, MYRIGHTS, NAMESPACE, NEWNAME, NIL, NO, NOOP, OK, PARSE, PERMANENTFLAGS, PREAUTH, QUOTA, QUOTAROOT, READ_ONLY, READ_WRITE, RECENT, RENAME, RFC822, RFC822_HEADER, RFC822_SIZE, RFC822_TEXT, RIGHTS_ADMIN, RIGHTS_CREATE, RIGHTS_DELETE, RIGHTS_INSERT, RIGHTS_LOOKUP, RIGHTS_POST, RIGHTS_READ, RIGHTS_SEEN, RIGHTS_WRITE, SEARCH, SEARCH_ALL, SEARCH_ANSWERED, SEARCH_BCC, SEARCH_BEFORE, SEARCH_BODY, SEARCH_CC, SEARCH_DELETED, SEARCH_DRAFT, SEARCH_FLAGGED, SEARCH_FROM, SEARCH_HEADER, SEARCH_KEYWORD, SEARCH_LARGER, SEARCH_NEW, SEARCH_NOT, SEARCH_OLD, SEARCH_ON, SEARCH_OR, SEARCH_RECENT, SEARCH_SEEN, SEARCH_SENTBEFORE, SEARCH_SENTON, SEARCH_SENTSINCE, SEARCH_SINCE, SEARCH_SMALLER, SEARCH_SUBJECT, SEARCH_TEXT, SEARCH_TO, SEARCH_UID, SEARCH_UNANSWERED, SEARCH_UNDELETED, SEARCH_UNDRAFT, SEARCH_UNFLAGGED, SEARCH_UNKEYWORD, SEARCH_UNSEEN, SELECT, SETACL, SETQUOTA, SKEY, STARTTLS, STATUS, STORAGE, STORE, SUBSCRIBE, TRYCREATE, UID, UID_EXPUNGE, UIDNEXT, UIDVALIDITY, UNSEEN, UNSUBSCRIBE| Constructor and Description |
|---|
IMAPConnection(java.lang.String host)
Creates a new connection to the default IMAP port.
|
IMAPConnection(java.lang.String host,
int port)
Creates a new connection.
|
IMAPConnection(java.lang.String host,
int port,
int connectionTimeout,
int timeout)
Creates a new connection.
|
IMAPConnection(java.lang.String host,
int port,
int connectionTimeout,
int timeout,
boolean secure,
javax.net.ssl.TrustManager tm)
Creates a new connection.
|
IMAPConnection(java.lang.String host,
int port,
javax.net.ssl.TrustManager tm)
Creates a new secure connection using the specified trust manager.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
alertsPending()
Indicates if there are alerts pending for the user-agent.
|
boolean |
append(java.lang.String mailbox,
java.lang.String[] flags,
byte[] content)
Append a message to the specified mailbox.
|
boolean |
append(java.lang.String mailbox,
java.lang.String[] flags,
byte[] content,
UIDPlusHandler uidplus)
Append a message to the specified mailbox.
|
boolean |
authenticate(java.lang.String mechanism,
java.lang.String username,
java.lang.String password)
Authenticates the connection using the specified SASL mechanism,
username, and password.
|
java.util.List |
capability()
Returns a list of the capabilities of the IMAP server.
|
void |
check()
Request a checkpoint of the currently selected mailbox.
|
boolean |
close()
Permanently remove all messages that have the \Deleted flags set,
and close the mailbox.
|
boolean |
copy(int[] messages,
java.lang.String mailbox)
Copies the specified messages to the end of the destination mailbox.
|
boolean |
copy(int[] messages,
java.lang.String mailbox,
UIDPlusHandler uidplus)
Copies the specified messages to the end of the destination mailbox.
|
boolean |
create(java.lang.String mailbox)
Creates a mailbox with the specified name.
|
boolean |
delete(java.lang.String mailbox)
Deletes the mailbox with the specified name.
|
boolean |
deleteacl(java.lang.String mailbox,
java.lang.String principal)
Removes any access rights for the given authentication principal on the
specified mailbox.
|
MailboxStatus |
examine(java.lang.String mailbox)
Selects the specified mailbox.
|
int[] |
expunge()
Permanently removes all messages that have the \Delete flag set.
|
MessageStatus[] |
fetch(int[] messages,
java.lang.String[] fetchCommands)
Retrieves data associated with messages in the mailbox.
|
MessageStatus[] |
fetch(int start,
int end,
java.lang.String[] fetchCommands)
Retrieves data associated with the specified range of messages in
the mailbox.
|
MessageStatus |
fetch(int message,
java.lang.String[] fetchCommands)
Retrieves data associated with the specified message in the mailbox.
|
java.util.Map |
getacl(java.lang.String mailbox)
Returns the access control list for the specified mailbox.
|
java.lang.String[] |
getAlerts()
Returns the pending alerts for the user-agent as an array.
|
Quota |
getquota(java.lang.String quotaRoot)
Returns the specified quota root's resource usage and limits.
|
Quota[] |
getquotaroot(java.lang.String mailbox)
Returns the quotas for the given mailbox.
|
protected javax.net.ssl.SSLSocketFactory |
getSSLSocketFactory(javax.net.ssl.TrustManager tm)
Returns a configured SSLSocketFactory to use in creating new SSL
sockets.
|
boolean |
invokeSimpleCommand(java.lang.String command)
Sends the specified IMAP command.
|
ListEntry[] |
list(java.lang.String reference,
java.lang.String mailbox)
Returns a subset of names from the compete set of names available to
the client.
|
protected ListEntry[] |
listImpl(java.lang.String command,
java.lang.String reference,
java.lang.String mailbox) |
int |
listrights(java.lang.String mailbox,
java.lang.String principal)
Returns the rights for the given principal for the specified mailbox.
|
boolean |
login(java.lang.String username,
java.lang.String password)
Login to the connection using the username and password method.
|
void |
logout()
Logout this connection.
|
ListEntry[] |
lsub(java.lang.String reference,
java.lang.String mailbox)
Returns a subset of subscribed names.
|
int |
myrights(java.lang.String mailbox)
Returns the rights for the current principal for the specified mailbox.
|
Namespaces |
namespace()
Returns the namespaces available on the server.
|
protected java.lang.String |
newTag()
Returns a new tag for a command.
|
MailboxStatus |
noop()
Ping the server.
|
protected IMAPResponse |
readResponse()
Reads an IMAP response from the server.
|
boolean |
rename(java.lang.String source,
java.lang.String target)
Renames the source mailbox to the specified name.
|
int[] |
search(java.lang.String charset,
java.lang.String[] criteria)
Searches the currently selected mailbox for messages matching the
specified criteria.
|
MailboxStatus |
select(java.lang.String mailbox)
Selects the specified mailbox.
|
protected MailboxStatus |
selectImpl(java.lang.String mailbox,
java.lang.String command) |
protected void |
sendCommand(java.lang.String tag,
java.lang.String command)
Sends the specified IMAP tagged command to the server.
|
boolean |
setacl(java.lang.String mailbox,
java.lang.String principal,
int rights)
Changes the access rights on the specified mailbox such that the
authentication principal is granted the specified permissions.
|
void |
setAnsiDebug(boolean flag)
Sets whether debugging output should use ANSI colour escape sequences.
|
Quota |
setquota(java.lang.String quotaRoot,
Quota.Resource[] resources)
Sets the quota for the specified quota root.
|
boolean |
starttls()
Attempts to start TLS on the specified connection.
|
boolean |
starttls(javax.net.ssl.TrustManager tm)
Attempts to start TLS on the specified connection.
|
MailboxStatus |
status(java.lang.String mailbox,
java.lang.String[] statusNames)
Requests the status of the specified mailbox.
|
MessageStatus[] |
store(int[] messages,
java.lang.String flagCommand,
java.lang.String[] flags)
Alters data associated with messages in the mailbox.
|
MessageStatus[] |
store(int start,
int end,
java.lang.String flagCommand,
java.lang.String[] flags)
Alters data associated with the specified range of messages in the
mailbox.
|
MessageStatus |
store(int message,
java.lang.String flagCommand,
java.lang.String[] flags)
Alters data associated with the specified message in the mailbox.
|
boolean |
subscribe(java.lang.String mailbox)
Adds the specified mailbox to the set of subscribed mailboxes as
returned by the LSUB command.
|
int[] |
uidExpunge(long start,
long end)
Expunges the specified range of messages.
|
MessageStatus[] |
uidFetch(long[] uids,
java.lang.String[] fetchCommands)
Retrieves data associated with messages in the mailbox.
|
MessageStatus[] |
uidFetch(long start,
long end,
java.lang.String[] fetchCommands)
Retrieves data associated with the specified range of messages in
the mailbox.
|
MessageStatus |
uidFetch(long uid,
java.lang.String[] fetchCommands)
Retrieves data associated with the specified message in the mailbox.
|
MessageStatus[] |
uidStore(long[] uids,
java.lang.String flagCommand,
java.lang.String[] flags)
Alters data associated with messages in the mailbox.
|
MessageStatus[] |
uidStore(long start,
long end,
java.lang.String flagCommand,
java.lang.String[] flags)
Alters data associated with the specified range of messages in the
mailbox.
|
MessageStatus |
uidStore(long uid,
java.lang.String flagCommand,
java.lang.String[] flags)
Alters data associated with the specified message in the mailbox.
|
boolean |
unsubscribe(java.lang.String mailbox)
Removes the specified mailbox from the set of subscribed mailboxes as
returned by the LSUB command.
|
protected boolean |
updateMailboxStatus(MailboxStatus ms,
java.lang.String id,
IMAPResponse response) |
public static final java.util.logging.Level IMAP_TRACE
protected static final java.lang.String TAG_PREFIX
protected static final java.lang.String US_ASCII
protected static final int DEFAULT_PORT
protected static final int DEFAULT_SSL_PORT
public static final java.util.logging.Logger logger
protected java.net.Socket socket
protected IMAPResponseTokenizer in
protected CRLFOutputStream out
protected java.util.List asyncResponses
public IMAPConnection(java.lang.String host)
throws java.net.UnknownHostException,
java.io.IOException
host - the name of the host to connect tojava.net.UnknownHostExceptionjava.io.IOExceptionpublic IMAPConnection(java.lang.String host,
int port)
throws java.net.UnknownHostException,
java.io.IOException
host - the name of the host to connect toport - the port to connect to, or -1 for the defaultjava.net.UnknownHostExceptionjava.io.IOExceptionpublic IMAPConnection(java.lang.String host,
int port,
int connectionTimeout,
int timeout)
throws java.net.UnknownHostException,
java.io.IOException
host - the name of the host to connect toport - the port to connect to, or -1 for the defaultconnectionTimeout - the socket connection timeouttimeout - the socket timeoutjava.net.UnknownHostExceptionjava.io.IOExceptionpublic IMAPConnection(java.lang.String host,
int port,
javax.net.ssl.TrustManager tm)
throws java.net.UnknownHostException,
java.io.IOException
host - the name of the host to connect toport - the port to connect to, or -1 for the defaulttm - a trust manager used to check SSL certificates, or null to
use the defaultjava.net.UnknownHostExceptionjava.io.IOExceptionpublic IMAPConnection(java.lang.String host,
int port,
int connectionTimeout,
int timeout,
boolean secure,
javax.net.ssl.TrustManager tm)
throws java.net.UnknownHostException,
java.io.IOException
host - the name of the host to connect toport - the port to connect to, or -1 for the defaultconnectionTimeout - the socket connection timeouttimeout - the socket timeoutsecure - if an IMAP-SSL connection should be madetm - a trust manager used to check SSL certificates, or null to
use the defaultjava.net.UnknownHostExceptionjava.io.IOExceptionpublic void setAnsiDebug(boolean flag)
protected java.lang.String newTag()
protected void sendCommand(java.lang.String tag,
java.lang.String command)
throws java.io.IOException
java.io.IOExceptionpublic boolean invokeSimpleCommand(java.lang.String command)
throws java.io.IOException
command - the commandjava.io.IOException - if BAD was received or an I/O error occurredprotected IMAPResponse readResponse() throws java.io.IOException
java.io.IOExceptionpublic boolean alertsPending()
public java.lang.String[] getAlerts()
public java.util.List capability()
throws java.io.IOException
java.io.IOExceptionpublic MailboxStatus noop() throws java.io.IOException
java.io.IOExceptionprotected javax.net.ssl.SSLSocketFactory getSSLSocketFactory(javax.net.ssl.TrustManager tm)
throws java.security.GeneralSecurityException
tm - an optional trust manager to usejava.security.GeneralSecurityExceptionpublic boolean starttls()
throws java.io.IOException
java.io.IOExceptionpublic boolean starttls(javax.net.ssl.TrustManager tm)
throws java.io.IOException
tm - the custom trust manager to usejava.io.IOExceptionpublic boolean login(java.lang.String username,
java.lang.String password)
throws java.io.IOException
username - the authentication principalpassword - the authentication credentialsjava.io.IOExceptionpublic boolean authenticate(java.lang.String mechanism,
java.lang.String username,
java.lang.String password)
throws java.io.IOException
mechanism - a SASL authentication mechanism, e.g. LOGIN, PLAIN,
CRAM-MD5, GSSAPIusername - the authentication principalpassword - the authentication credentialsjava.io.IOExceptionpublic void logout()
throws java.io.IOException
java.io.IOExceptionpublic MailboxStatus select(java.lang.String mailbox) throws java.io.IOException
mailbox - the mailbox namejava.io.IOExceptionpublic MailboxStatus examine(java.lang.String mailbox) throws java.io.IOException
mailbox - the mailbox namejava.io.IOExceptionprotected MailboxStatus selectImpl(java.lang.String mailbox, java.lang.String command) throws java.io.IOException
java.io.IOExceptionprotected boolean updateMailboxStatus(MailboxStatus ms, java.lang.String id, IMAPResponse response) throws java.io.IOException
java.io.IOExceptionpublic boolean create(java.lang.String mailbox)
throws java.io.IOException
mailbox - the mailbox namejava.io.IOExceptionpublic boolean delete(java.lang.String mailbox)
throws java.io.IOException
mailbox - the mailbox namejava.io.IOExceptionpublic boolean rename(java.lang.String source,
java.lang.String target)
throws java.io.IOException
source - the source mailbox nametarget - the target mailbox namejava.io.IOExceptionpublic boolean subscribe(java.lang.String mailbox)
throws java.io.IOException
mailbox - the mailbox namejava.io.IOExceptionpublic boolean unsubscribe(java.lang.String mailbox)
throws java.io.IOException
mailbox - the mailbox namejava.io.IOExceptionpublic ListEntry[] list(java.lang.String reference, java.lang.String mailbox) throws java.io.IOException
reference - the context relative to which mailbox names are
definedmailbox - a mailbox name, possibly including IMAP wildcardsjava.io.IOExceptionpublic ListEntry[] lsub(java.lang.String reference, java.lang.String mailbox) throws java.io.IOException
java.io.IOExceptionlist(java.lang.String, java.lang.String)protected ListEntry[] listImpl(java.lang.String command, java.lang.String reference, java.lang.String mailbox) throws java.io.IOException
java.io.IOExceptionpublic MailboxStatus status(java.lang.String mailbox, java.lang.String[] statusNames) throws java.io.IOException
java.io.IOExceptionpublic boolean append(java.lang.String mailbox,
java.lang.String[] flags,
byte[] content)
throws java.io.IOException
mailbox - the mailbox nameflags - optional list of flags to specify for the messagecontent - the message body(including headers)java.io.IOExceptionpublic boolean append(java.lang.String mailbox,
java.lang.String[] flags,
byte[] content,
UIDPlusHandler uidplus)
throws java.io.IOException
mailbox - the mailbox nameflags - optional list of flags to specify for the messagecontent - the message body(including headers)uidplus - handler for any APPENDUID information in the responsejava.io.IOExceptionpublic void check()
throws java.io.IOException
java.io.IOExceptionpublic boolean close()
throws java.io.IOException
java.io.IOExceptionpublic int[] expunge()
throws java.io.IOException
java.io.IOExceptionpublic int[] search(java.lang.String charset,
java.lang.String[] criteria)
throws java.io.IOException
java.io.IOExceptionpublic MessageStatus fetch(int message, java.lang.String[] fetchCommands) throws java.io.IOException
message - the message numberfetchCommands - the fetch commands, e.g. FLAGSjava.io.IOExceptionpublic MessageStatus[] fetch(int start, int end, java.lang.String[] fetchCommands) throws java.io.IOException
start - the message number of the first messageend - the message number of the last messagefetchCommands - the fetch commands, e.g. FLAGSjava.io.IOExceptionpublic MessageStatus[] fetch(int[] messages, java.lang.String[] fetchCommands) throws java.io.IOException
messages - the message numbersfetchCommands - the fetch commands, e.g. FLAGSjava.io.IOExceptionpublic MessageStatus uidFetch(long uid, java.lang.String[] fetchCommands) throws java.io.IOException
uid - the message UIDfetchCommands - the fetch commands, e.g. FLAGSjava.io.IOExceptionpublic MessageStatus[] uidFetch(long start, long end, java.lang.String[] fetchCommands) throws java.io.IOException
start - the message number of the first messageend - the message number of the last messagefetchCommands - the fetch commands, e.g. FLAGSjava.io.IOExceptionpublic MessageStatus[] uidFetch(long[] uids, java.lang.String[] fetchCommands) throws java.io.IOException
uids - the message UIDsfetchCommands - the fetch commands, e.g. FLAGSjava.io.IOExceptionpublic MessageStatus store(int message, java.lang.String flagCommand, java.lang.String[] flags) throws java.io.IOException
message - the message numberflagCommand - FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags - message flags to setjava.io.IOExceptionpublic MessageStatus[] store(int start, int end, java.lang.String flagCommand, java.lang.String[] flags) throws java.io.IOException
start - the message number of the first messageend - the message number of the last messageflagCommand - FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags - message flags to setjava.io.IOExceptionpublic MessageStatus[] store(int[] messages, java.lang.String flagCommand, java.lang.String[] flags) throws java.io.IOException
messages - the message numbersflagCommand - FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags - message flags to setjava.io.IOExceptionpublic MessageStatus uidStore(long uid, java.lang.String flagCommand, java.lang.String[] flags) throws java.io.IOException
uid - the message UIDflagCommand - FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags - message flags to setjava.io.IOExceptionpublic MessageStatus[] uidStore(long start, long end, java.lang.String flagCommand, java.lang.String[] flags) throws java.io.IOException
start - the UID of the first messageend - the UID of the last messageflagCommand - FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags - message flags to setjava.io.IOExceptionpublic MessageStatus[] uidStore(long[] uids, java.lang.String flagCommand, java.lang.String[] flags) throws java.io.IOException
uids - the message UIDsflagCommand - FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags - message flags to setjava.io.IOExceptionpublic boolean copy(int[] messages,
java.lang.String mailbox)
throws java.io.IOException
messages - the message numbersmailbox - the destination mailboxjava.io.IOExceptionpublic boolean copy(int[] messages,
java.lang.String mailbox,
UIDPlusHandler uidplus)
throws java.io.IOException
messages - the message numbersmailbox - the destination mailboxuidplus - UIDPLUS callback for COPYUID informationjava.io.IOExceptionpublic Namespaces namespace() throws java.io.IOException
java.io.IOExceptionpublic boolean setacl(java.lang.String mailbox,
java.lang.String principal,
int rights)
throws java.io.IOException
mailbox - the mailbox nameprincipal - the authentication identifierrights - the rights to assignjava.io.IOExceptionpublic boolean deleteacl(java.lang.String mailbox,
java.lang.String principal)
throws java.io.IOException
mailbox - the mailbox nameprincipal - the authentication identifierjava.io.IOExceptionpublic java.util.Map getacl(java.lang.String mailbox)
throws java.io.IOException
mailbox - the mailbox namejava.io.IOExceptionpublic int listrights(java.lang.String mailbox,
java.lang.String principal)
throws java.io.IOException
mailbox - the mailbox nameprincipal - the authentication identityjava.io.IOExceptionpublic int myrights(java.lang.String mailbox)
throws java.io.IOException
mailbox - the mailbox namejava.io.IOExceptionpublic Quota setquota(java.lang.String quotaRoot, Quota.Resource[] resources) throws java.io.IOException
quotaRoot - the quota rootresources - the list of resources and associated limits to setnull if the operation failedjava.io.IOExceptionpublic Quota getquota(java.lang.String quotaRoot) throws java.io.IOException
quotaRoot - the quota rootjava.io.IOExceptionpublic Quota[] getquotaroot(java.lang.String mailbox) throws java.io.IOException
mailbox - the mailbox namejava.io.IOExceptionpublic int[] uidExpunge(long start,
long end)
throws java.io.IOException
start - the UID of the first message to expungeend - the UID of the last message to expungejava.io.IOException© Copyright 2003 The Free Software Foundation, all rights reserved