The protocol class implementing IMAP4rev1.
alertsPending
public boolean alertsPending()
Indicates if there are alerts pending for the user-agent.
append
public boolean append(String mailbox,
String[] flags,
byte[] content)
throws IOException
Append a message to the specified mailbox.
This method returns an OutputStream to which the message should be
written and then closed.
mailbox
- the mailbox nameflags
- optional list of flags to specify for the messagecontent
- the message body(including headers)
- true if successful, false if error in flags/text
append
public boolean append(String mailbox,
String[] flags,
byte[] content,
UIDPlusHandler uidplus)
throws IOException
Append a message to the specified mailbox.
This method returns an OutputStream to which the message should be
written and then closed.
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 response
- true if successful, false if error in flags/text
authenticate
public boolean authenticate(String mechanism,
String username,
String password)
throws IOException
Authenticates the connection using the specified SASL mechanism,
username, and password.
mechanism
- a SASL authentication mechanism, e.g. LOGIN, PLAIN,
CRAM-MD5, GSSAPIusername
- the authentication principalpassword
- the authentication credentials
- true if authentication was successful, false otherwise
capability
public List capability()
throws IOException
Returns a list of the capabilities of the IMAP server.
check
public void check()
throws IOException
Request a checkpoint of the currently selected mailbox.
close
public boolean close()
throws IOException
Permanently remove all messages that have the \Deleted flags set,
and close the mailbox.
- true if successful, false if no mailbox was selected
copy
public boolean copy(int[] messages,
String mailbox)
throws IOException
Copies the specified messages to the end of the destination mailbox.
messages
- the message numbersmailbox
- the destination mailbox
copy
public boolean copy(int[] messages,
String mailbox,
UIDPlusHandler uidplus)
throws IOException
Copies the specified messages to the end of the destination mailbox.
messages
- the message numbersmailbox
- the destination mailboxuidplus
- UIDPLUS callback for COPYUID information
create
public boolean create(String mailbox)
throws IOException
Creates a mailbox with the specified name.
mailbox
- the mailbox name
- true if the mailbox was successfully created, false otherwise
delete
public boolean delete(String mailbox)
throws IOException
Deletes the mailbox with the specified name.
mailbox
- the mailbox name
- true if the mailbox was successfully deleted, false otherwise
deleteacl
public boolean deleteacl(String mailbox,
String principal)
throws IOException
Removes any access rights for the given authentication principal on the
specified mailbox.
mailbox
- the mailbox nameprincipal
- the authentication identifier
examine
public MailboxStatus examine(String mailbox)
throws IOException
Selects the specified mailbox.
The mailbox is identified as read-only.
mailbox
- the mailbox name
- a MailboxStatus containing the state of the selected mailbox
expunge
public int[] expunge()
throws IOException
Permanently removes all messages that have the \Delete flag set.
- the numbers of the messages expunged
fetch
public MessageStatus fetch(int message,
String[] fetchCommands)
throws IOException
Retrieves data associated with the specified message in the mailbox.
message
- the message numberfetchCommands
- the fetch commands, e.g. FLAGS
fetch
public MessageStatus[] fetch(int start,
int end,
String[] fetchCommands)
throws IOException
Retrieves data associated with the specified range of messages in
the mailbox.
start
- the message number of the first messageend
- the message number of the last messagefetchCommands
- the fetch commands, e.g. FLAGS
fetch
public MessageStatus[] fetch(int[] messages,
String[] fetchCommands)
throws IOException
Retrieves data associated with messages in the mailbox.
messages
- the message numbersfetchCommands
- the fetch commands, e.g. FLAGS
getAlerts
public String[] getAlerts()
Returns the pending alerts for the user-agent as an array.
getSSLSocketFactory
protected SSLSocketFactory getSSLSocketFactory(TrustManager tm)
throws GeneralSecurityException
Returns a configured SSLSocketFactory to use in creating new SSL
sockets.
tm
- an optional trust manager to use
getacl
public Map getacl(String mailbox)
throws IOException
Returns the access control list for the specified mailbox.
The returned rights are a logical OR of RIGHTS_* bits.
mailbox
- the mailbox name
- a map of principal names to Integer rights
getquota
public Quota getquota(String quotaRoot)
throws IOException
Returns the specified quota root's resource usage and limits.
quotaRoot
- the quota root
getquotaroot
public Quota[] getquotaroot(String mailbox)
throws IOException
Returns the quotas for the given mailbox.
mailbox
- the mailbox name
invokeSimpleCommand
public boolean invokeSimpleCommand(String command)
throws IOException
Sends the specified IMAP command.
- true if OK was received, or false if NO was received
list
public ListEntry[] list(String reference,
String mailbox)
throws IOException
Returns a subset of names from the compete set of names available to
the client.
reference
- the context relative to which mailbox names are
definedmailbox
- a mailbox name, possibly including IMAP wildcards
listImpl
protected ListEntry[] listImpl(String command,
String reference,
String mailbox)
throws IOException
listrights
public int listrights(String mailbox,
String principal)
throws IOException
Returns the rights for the given principal for the specified mailbox.
The returned rights are a logical OR of RIGHTS_* bits.
mailbox
- the mailbox nameprincipal
- the authentication identity
login
public boolean login(String username,
String password)
throws IOException
Login to the connection using the username and password method.
username
- the authentication principalpassword
- the authentication credentials
- true if authentication was successful, false otherwise
logout
public void logout()
throws IOException
Logout this connection.
Underlying network resources will be freed.
lsub
public ListEntry[] lsub(String reference,
String mailbox)
throws IOException
Returns a subset of subscribed names.
myrights
public int myrights(String mailbox)
throws IOException
Returns the rights for the current principal for the specified mailbox.
The returned rights are a logical OR of RIGHTS_* bits.
mailbox
- the mailbox name
namespace
public Namespaces namespace()
throws IOException
Returns the namespaces available on the server.
See RFC 2342 for details.
newTag
protected String newTag()
Returns a new tag for a command.
noop
public MailboxStatus noop()
throws IOException
Ping the server.
If a change in mailbox state is detected, a new mailbox status is
returned, otherwise this method returns null.
readResponse
protected IMAPResponse readResponse()
throws IOException
Reads an IMAP response from the server.
The response will consist of
either:
- A tagged response corresponding to a pending command
- An untagged error response
- A continuation response
rename
public boolean rename(String source,
String target)
throws IOException
Renames the source mailbox to the specified name.
source
- the source mailbox nametarget
- the target mailbox name
- true if the mailbox was successfully renamed, false otherwise
search
public int[] search(String charset,
String[] criteria)
throws IOException
Searches the currently selected mailbox for messages matching the
specified criteria.
select
public MailboxStatus select(String mailbox)
throws IOException
Selects the specified mailbox.
The mailbox is identified as read-write if writes are permitted.
mailbox
- the mailbox name
- a MailboxStatus containing the state of the selected mailbox
selectImpl
protected MailboxStatus selectImpl(String mailbox,
String command)
throws IOException
sendCommand
protected void sendCommand(String tag,
String command)
throws IOException
Sends the specified IMAP tagged command to the server.
setAnsiDebug
public void setAnsiDebug(boolean flag)
Sets whether debugging output should use ANSI colour escape sequences.
setacl
public boolean setacl(String mailbox,
String principal,
int rights)
throws IOException
Changes the access rights on the specified mailbox such that the
authentication principal is granted the specified permissions.
mailbox
- the mailbox nameprincipal
- the authentication identifierrights
- the rights to assign
setquota
public Quota setquota(String quotaRoot,
Quota.Resource[] resources)
throws IOException
Sets the quota for the specified quota root.
quotaRoot
- the quota rootresources
- the list of resources and associated limits to set
- the new quota, or
null
if the operation failed
starttls
public boolean starttls()
throws IOException
Attempts to start TLS on the specified connection.
See RFC 2595 for details.
- true if successful, false otherwise
starttls
public boolean starttls(TrustManager tm)
throws IOException
Attempts to start TLS on the specified connection.
See RFC 2595 for details.
tm
- the custom trust manager to use
- true if successful, false otherwise
status
public MailboxStatus status(String mailbox,
String[] statusNames)
throws IOException
Requests the status of the specified mailbox.
store
public MessageStatus store(int message,
String flagCommand,
String[] flags)
throws IOException
Alters data associated with the specified message in the mailbox.
message
- the message numberflagCommand
- FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags
- message flags to set
store
public MessageStatus[] store(int start,
int end,
String flagCommand,
String[] flags)
throws IOException
Alters data associated with the specified range of messages in the
mailbox.
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 set
- a list of message-number to current flags
store
public MessageStatus[] store(int[] messages,
String flagCommand,
String[] flags)
throws IOException
Alters data associated with messages in the mailbox.
messages
- the message numbersflagCommand
- FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags
- message flags to set
- a list of message-number to current flags
subscribe
public boolean subscribe(String mailbox)
throws IOException
Adds the specified mailbox to the set of subscribed mailboxes as
returned by the LSUB command.
mailbox
- the mailbox name
- true if the mailbox was successfully subscribed, false otherwise
uidExpunge
public int[] uidExpunge(long start,
long end)
throws IOException
Expunges the specified range of messages.
See RFC 2359 for details.
start
- the UID of the first message to expungeend
- the UID of the last message to expunge
uidFetch
public MessageStatus uidFetch(long uid,
String[] fetchCommands)
throws IOException
Retrieves data associated with the specified message in the mailbox.
uid
- the message UIDfetchCommands
- the fetch commands, e.g. FLAGS
uidFetch
public MessageStatus[] uidFetch(long start,
long end,
String[] fetchCommands)
throws IOException
Retrieves data associated with the specified range of messages in
the mailbox.
start
- the message number of the first messageend
- the message number of the last messagefetchCommands
- the fetch commands, e.g. FLAGS
uidFetch
public MessageStatus[] uidFetch(long[] uids,
String[] fetchCommands)
throws IOException
Retrieves data associated with messages in the mailbox.
uids
- the message UIDsfetchCommands
- the fetch commands, e.g. FLAGS
uidStore
public MessageStatus uidStore(long uid,
String flagCommand,
String[] flags)
throws IOException
Alters data associated with the specified message in the mailbox.
uid
- the message UIDflagCommand
- FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags
- message flags to set
uidStore
public MessageStatus[] uidStore(long start,
long end,
String flagCommand,
String[] flags)
throws IOException
Alters data associated with the specified range of messages in the
mailbox.
start
- the UID of the first messageend
- the UID of the last messageflagCommand
- FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags
- message flags to set
- a list of message-number to current flags
uidStore
public MessageStatus[] uidStore(long[] uids,
String flagCommand,
String[] flags)
throws IOException
Alters data associated with messages in the mailbox.
uids
- the message UIDsflagCommand
- FLAGS, +FLAGS, -FLAGS(or .SILENT versions)flags
- message flags to set
- a list of message-number to current flags
unsubscribe
public boolean unsubscribe(String mailbox)
throws IOException
Removes the specified mailbox from the set of subscribed mailboxes as
returned by the LSUB command.
mailbox
- the mailbox name
- true if the mailbox was successfully unsubscribed, false otherwise
updateMailboxStatus
protected boolean updateMailboxStatus(MailboxStatus ms,
String id,
IMAPResponse response)
throws IOException