public class IMAPConnection extends java.lang.Object implements IMAPConstants
To use this connection, you must implement an
IMAPCallback
either directly or by subclassing the
IMAPAdapter
class. This callback will be notified of the various
IMAP events that occur during the processing of the command, since a
single command may result in multiple events possibly unrelated to the
intent of the caller (alerts, new message updates, etc).
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT
The default IMAP port.
|
static int |
DEFAULT_SSL_PORT
The default IMAP-SSL port.
|
static java.util.logging.Level |
IMAP_TRACE
The network trace level.
|
ACL, ALERT, APPEND, APPENDUID, AUTHENTICATE, BAD, BADCHARSET, BODY, 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, UIDNOTSTICKY, 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 |
append(java.lang.String mailbox,
java.util.List<java.lang.String> flags,
java.util.Date date,
byte[] content,
IMAPCallback callback)
Append a message to the specified mailbox.
|
boolean |
authenticate(java.lang.String mechanism,
java.lang.String username,
java.lang.String password,
IMAPCallback callback)
Authenticates the connection using the specified SASL mechanism,
username, and password.
|
boolean |
capability(IMAPCallback callback)
Returns a list of the capabilities of the IMAP server.
|
boolean |
check(IMAPCallback callback)
Request a checkpoint of the currently selected mailbox.
|
boolean |
close(IMAPCallback callback)
Permanently remove all messages that have the \Deleted flags set,
and close the mailbox.
|
boolean |
copy(MessageSet messages,
java.lang.String mailbox,
IMAPCallback callback)
Copies the specified messages to the end of the destination mailbox.
|
boolean |
create(java.lang.String mailbox,
IMAPCallback callback)
Creates a mailbox with the specified name.
|
boolean |
delete(java.lang.String mailbox,
IMAPCallback callback)
Deletes the mailbox with the specified name.
|
boolean |
deleteacl(java.lang.String mailbox,
java.lang.String principal,
IMAPCallback callback)
Removes any access rights for the given authentication principal on the
specified mailbox.
|
boolean |
examine(java.lang.String mailbox,
IMAPCallback callback)
Selects the specified mailbox.
|
boolean |
expunge(IMAPCallback callback)
Permanently removes all messages that have the \Delete flag set.
|
boolean |
fetch(MessageSet messages,
java.util.List<java.lang.String> fetchCommands,
IMAPCallback callback)
Retrieves data associated with the specified message in the mailbox.
|
boolean |
getacl(java.lang.String mailbox,
IMAPCallback callback)
Returns the access control list for the specified mailbox.
|
java.util.logging.Logger |
getLogger()
Returns the logger used by this connection for debug output.
|
boolean |
getquota(java.lang.String quotaRoot,
IMAPCallback callback)
Returns the specified quota root's resource usage and limits.
|
boolean |
getquotaroot(java.lang.String mailbox,
IMAPCallback callback)
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 |
list(java.lang.String reference,
java.lang.String mailbox,
IMAPCallback callback)
Returns a subset of names from the complete set of names available to
the client.
|
boolean |
listrights(java.lang.String mailbox,
java.lang.String principal,
IMAPCallback callback)
Returns the rights for the given principal for the specified mailbox.
|
boolean |
login(java.lang.String username,
java.lang.String password,
IMAPCallback callback)
Login to the connection using the username and password method.
|
void |
logout(IMAPCallback callback)
Logout this connection.
|
boolean |
lsub(java.lang.String reference,
java.lang.String mailbox,
IMAPCallback callback)
Returns a subset of subscribed names.
|
boolean |
myrights(java.lang.String mailbox,
IMAPCallback callback)
Returns the rights for the current principal for the specified mailbox.
|
boolean |
namespace(IMAPCallback callback)
Returns the namespaces available on the server.
|
protected java.lang.String |
newTag()
Returns a new tag for a command.
|
void |
noop(IMAPCallback callback)
Ping the server.
|
boolean |
rename(java.lang.String source,
java.lang.String target,
IMAPCallback callback)
Renames the source mailbox to the specified name.
|
boolean |
search(java.lang.String charset,
java.util.List<java.lang.String> criteria,
IMAPCallback callback)
Searches the currently selected mailbox for messages matching the
specified criteria.
|
boolean |
select(java.lang.String mailbox,
IMAPCallback callback)
Selects the specified mailbox.
|
boolean |
setacl(java.lang.String mailbox,
java.lang.String principal,
int rights,
IMAPCallback callback)
Changes the access rights on the specified mailbox such that the
authentication principal is granted the specified permissions.
|
void |
setLiteralFactory(LiteralFactory factory,
int threshold)
Sets a literal factory for the connection.
|
boolean |
setquota(java.lang.String quotaRoot,
java.util.Map<java.lang.String,java.lang.Integer> resources,
IMAPCallback callback)
Sets the quota for the specified quota root.
|
boolean |
starttls(IMAPCallback callback)
Attempts to start TLS on the specified connection.
|
boolean |
starttls(IMAPCallback callback,
javax.net.ssl.TrustManager tm)
Attempts to start TLS on the specified connection.
|
boolean |
status(java.lang.String mailbox,
java.util.List<java.lang.String> statusNames,
IMAPCallback callback)
Requests the status of the specified mailbox.
|
boolean |
store(MessageSet messages,
java.lang.String flagCommand,
java.util.List<java.lang.String> flags,
IMAPCallback callback)
Alters data associated with the specified messages in the mailbox.
|
boolean |
subscribe(java.lang.String mailbox,
IMAPCallback callback)
Adds the specified mailbox to the set of subscribed mailboxes as
returned by the LSUB command.
|
boolean |
uidExpunge(long start,
long end,
IMAPCallback callback)
Expunges the specified range of messages.
|
boolean |
uidExpunge(UIDSet uids,
IMAPCallback callback)
Permanently removes all messages in the specified UID-set that have
the \Delete flag set.
|
boolean |
uidFetch(UIDSet uids,
java.util.List<java.lang.String> fetchCommands,
IMAPCallback callback)
Retrieves data associated with the specified message in the mailbox.
|
boolean |
uidStore(UIDSet uids,
java.lang.String flagCommand,
java.util.List<java.lang.String> flags,
IMAPCallback callback)
Alters data associated with the specified messages in the mailbox.
|
boolean |
unsubscribe(java.lang.String mailbox,
IMAPCallback callback)
Removes the specified mailbox from the set of subscribed mailboxes as
returned by the LSUB command.
|
public static final java.util.logging.Level IMAP_TRACE
public static final int DEFAULT_PORT
public static final int DEFAULT_SSL_PORT
public IMAPConnection(java.lang.String host)
host
- the name of the host to connect topublic IMAPConnection(java.lang.String host, int port)
host
- the name of the host to connect toport
- the port to connect to, or -1 for the defaultpublic IMAPConnection(java.lang.String host, int port, int connectionTimeout, int timeout)
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 timeoutpublic IMAPConnection(java.lang.String host, int port, javax.net.ssl.TrustManager tm)
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 defaultpublic IMAPConnection(java.lang.String host, int port, int connectionTimeout, int timeout, boolean secure, javax.net.ssl.TrustManager tm)
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 defaultpublic void setLiteralFactory(LiteralFactory factory, int threshold)
connect()
factory
- the factorythreshold
- the threshold over which literals are considered largeLiteralFactory}
public java.util.logging.Logger getLogger()
protected java.lang.String newTag()
public boolean capability(IMAPCallback callback) throws java.io.IOException
java.io.IOException
public void noop(IMAPCallback callback) throws java.io.IOException
java.io.IOException
protected javax.net.ssl.SSLSocketFactory getSSLSocketFactory(javax.net.ssl.TrustManager tm) throws java.security.GeneralSecurityException
tm
- an optional trust manager to usejava.security.GeneralSecurityException
public boolean starttls(IMAPCallback callback) throws java.io.IOException
java.io.IOException
public boolean starttls(IMAPCallback callback, javax.net.ssl.TrustManager tm) throws java.io.IOException
tm
- the custom trust manager to usejava.io.IOException
public boolean login(java.lang.String username, java.lang.String password, IMAPCallback callback) throws java.io.IOException
username
- the authentication principalpassword
- the authentication credentialsjava.io.IOException
public boolean authenticate(java.lang.String mechanism, java.lang.String username, java.lang.String password, IMAPCallback callback) throws java.io.IOException
mechanism
- a SASL authentication mechanism, e.g. LOGIN, PLAIN,
CRAM-MD5, GSSAPIusername
- the authentication principalpassword
- the authentication credentialsjava.io.IOException
public void logout(IMAPCallback callback) throws java.io.IOException
java.io.IOException
public boolean select(java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox namecallback
- the callback to be notified of the state of the
selected mailboxjava.io.IOException
public boolean examine(java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox namecallback
- the callback to be notified of the state of the
selected mailboxjava.io.IOException
public boolean create(java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox namejava.io.IOException
public boolean delete(java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox namejava.io.IOException
public boolean rename(java.lang.String source, java.lang.String target, IMAPCallback callback) throws java.io.IOException
source
- the source mailbox nametarget
- the target mailbox namejava.io.IOException
public boolean subscribe(java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox namejava.io.IOException
public boolean unsubscribe(java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox namejava.io.IOException
public boolean list(java.lang.String reference, java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
reference
- the context relative to which mailbox names are
definedmailbox
- a mailbox name, possibly including IMAP wildcardsjava.io.IOException
public boolean lsub(java.lang.String reference, java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
reference
- the context relative to which mailbox names are
definedmailbox
- a mailbox name, possibly including IMAP wildcardsjava.io.IOException
list(java.lang.String, java.lang.String, gnu.inet.imap.IMAPCallback)
public boolean status(java.lang.String mailbox, java.util.List<java.lang.String> statusNames, IMAPCallback callback) throws java.io.IOException
java.io.IOException
public boolean append(java.lang.String mailbox, java.util.List<java.lang.String> flags, java.util.Date date, byte[] content, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox nameflags
- optional list of flags to specify for the messagedate
- optional date of the messagecontent
- the RFC822 message (including headers)java.io.IOException
public boolean check(IMAPCallback callback) throws java.io.IOException
java.io.IOException
public boolean close(IMAPCallback callback) throws java.io.IOException
java.io.IOException
public boolean expunge(IMAPCallback callback) throws java.io.IOException
java.io.IOException
public boolean uidExpunge(UIDSet uids, IMAPCallback callback) throws java.io.IOException
uids
- the non-null set of UIDsjava.io.IOException
public boolean search(java.lang.String charset, java.util.List<java.lang.String> criteria, IMAPCallback callback) throws java.io.IOException
charset
- optional charsetcriteria
- the list of criteriajava.io.IOException
public boolean fetch(MessageSet messages, java.util.List<java.lang.String> fetchCommands, IMAPCallback callback) throws java.io.IOException
message
- the message number, or -1 for all messagesfetchCommands
- the fetch commands, e.g. FLAGSjava.io.IOException
public boolean uidFetch(UIDSet uids, java.util.List<java.lang.String> fetchCommands, IMAPCallback callback) throws java.io.IOException
uids
- the message UIDs, or null for all messagesfetchCommands
- the fetch commands, e.g. FLAGSjava.io.IOException
public boolean store(MessageSet messages, java.lang.String flagCommand, java.util.List<java.lang.String> flags, IMAPCallback callback) throws java.io.IOException
messages
- the message set, or null for all messagesflagCommand
- FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags
- message flags to setjava.io.IOException
public boolean uidStore(UIDSet uids, java.lang.String flagCommand, java.util.List<java.lang.String> flags, IMAPCallback callback) throws java.io.IOException
uids
- the message UIDs, or null for all messagesflagCommand
- FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags
- message flags to setjava.io.IOException
public boolean copy(MessageSet messages, java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
messages
- the message-setmailbox
- the destination mailboxjava.io.IOException
public boolean namespace(IMAPCallback callback) throws java.io.IOException
java.io.IOException
2342
public boolean setacl(java.lang.String mailbox, java.lang.String principal, int rights, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox nameprincipal
- the authentication identifierrights
- the rights to assignjava.io.IOException
4314
public boolean deleteacl(java.lang.String mailbox, java.lang.String principal, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox nameprincipal
- the authentication identifierjava.io.IOException
4314
public boolean getacl(java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox namejava.io.IOException
4314
public boolean listrights(java.lang.String mailbox, java.lang.String principal, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox nameprincipal
- the authentication identityjava.io.IOException
4314
public boolean myrights(java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox namejava.io.IOException
4314
public boolean setquota(java.lang.String quotaRoot, java.util.Map<java.lang.String,java.lang.Integer> resources, IMAPCallback callback) throws java.io.IOException
quotaRoot
- the quota rootresources
- the list of resources and associated limits to setjava.io.IOException
public boolean getquota(java.lang.String quotaRoot, IMAPCallback callback) throws java.io.IOException
quotaRoot
- the quota rootjava.io.IOException
public boolean getquotaroot(java.lang.String mailbox, IMAPCallback callback) throws java.io.IOException
mailbox
- the mailbox namejava.io.IOException
public boolean uidExpunge(long start, long end, IMAPCallback callback) throws java.io.IOException
start
- the UID of the first message to expungeend
- the UID of the last message to expungejava.io.IOException