public class

IMAPProtocol

extends Protocol
java.lang.Object
   ↳ com.google.code.com.sun.mail.iap.Protocol
     ↳ com.google.code.com.sun.mail.imap.protocol.IMAPProtocol

Class Overview

This class extends the iap.Protocol object and implements IMAP semantics. In general, there is a method corresponding to each IMAP protocol command. The typical implementation issues the appropriate protocol command, collects all responses, processes those responses that are specific to this command and then dispatches the rest (the unsolicited ones) to the dispatcher using the notifyResponseHandlers(r).

Summary

Fields
private static final byte[] CRLF
private static final byte[] DONE
private boolean authenticated
private List authmechs
private ByteArray ba
private Map capabilities
private boolean connected
private String idleTag
private String name
private boolean rev1
private SaslAuthenticator saslAuthenticator
protected String[] searchCharsets
[Expand]
Inherited Fields
From class com.google.code.com.sun.mail.iap.Protocol
Public Constructors
IMAPProtocol(String name, String host, int port, boolean debug, PrintStream out, Properties props, boolean isSSL)
Constructor.
Public Methods
void append(String mbox, Flags f, Date d, Literal data)
APPEND Command.
AppendUID appenduid(String mbox, Flags f, Date d, Literal data)
APPEND Command, return uid from APPENDUID response code.
AppendUID appenduid(String mbox, Flags f, Date d, Literal data, boolean uid)
synchronized void authlogin(String u, String p)
The AUTHENTICATE command with AUTH=LOGIN authenticate scheme
synchronized void authntlm(String authzid, String u, String p)
The AUTHENTICATE command with AUTH=NTLM authentication scheme.
synchronized void authplain(String authzid, String u, String p)
The AUTHENTICATE command with AUTH=PLAIN authentication scheme.
void capability()
CAPABILITY command.
void check()
CHECK Command.
void close()
CLOSE Command.
void copy(MessageSet[] msgsets, String mbox)
COPY command.
void copy(int start, int end, String mbox)
void create(String mbox)
CREATE Command.
void delete(String mbox)
DELETE Command.
void deleteACL(String mbox, String user)
DELETEACL Command.
void disconnect()
Close socket connection.
MailboxInfo examine(String mbox)
EXAMINE Command.
void expunge()
EXPUNGE Command.
Response[] fetch(MessageSet[] msgsets, String what)
Response[] fetch(int msg, String what)
Response[] fetch(int start, int end, String what)
BODY fetchBody(int msgno, String section)
Fetch given BODY section.
BODY fetchBody(int msgno, String section, int start, int size)
Partial FETCH of given BODY section.
BODY fetchBody(int msgno, String section, int start, int size, ByteArray ba)
Partial FETCH of given BODY section.
BODYSTRUCTURE fetchBodyStructure(int msgno)
Fetch the BODYSTRUCTURE of the specified message.
Flags fetchFlags(int msgno)
Fetch the FLAGS for the given message.
RFC822DATA fetchRFC822(int msgno, String what)
Fetch the specified RFC822 Data item.
UID fetchSequenceNumber(long uid)
Get the sequence number for the given UID.
UID[] fetchSequenceNumbers(long[] uids)
Get the sequence numbers for UIDs ranging from start till end.
UID[] fetchSequenceNumbers(long start, long end)
Get the sequence numbers for UIDs ranging from start till end.
UID fetchUID(int msgno)
Fetch the IMAP UID for the given message.
ACL[] getACL(String mbox)
GETACL Command.
Map getCapabilities()
Return the map of capabilities returned by the server.
Quota[] getQuota(String root)
GETQUOTA Command.
Quota[] getQuotaRoot(String mbox)
GETQUOTAROOT Command.
boolean hasCapability(String c)
Check whether the given capability is supported by this server.
void id(String guid)
ID Command, for Yahoo! Mail IMAP server.
void idleAbort()
Abort an IDLE command.
synchronized void idleStart()
IDLE Command.
boolean isAuthenticated()
Returns true if the connection has been authenticated, either due to a successful login, or due to a PREAUTH greeting response.
boolean isREV1()
Returns true if this is a IMAP4rev1 server
ListInfo[] list(String ref, String pattern)
LIST Command.
Rights[] listRights(String mbox, String user)
LISTRIGHTS Command.
void login(String u, String p)
LOGIN Command.
void logout()
LOGOUT Command.
ListInfo[] lsub(String ref, String pattern)
LSUB Command.
Rights myRights(String mbox)
MYRIGHTS Command.
Namespaces namespace()
NAMESPACE Command.
void noop()
The NOOP command.
BODY peekBody(int msgno, String section, int start, int size, ByteArray ba)
Partial FETCH of given BODY section, without setting SEEN flag.
BODY peekBody(int msgno, String section, int start, int size)
Partial FETCH of given BODY section, without setting SEEN flag.
BODY peekBody(int msgno, String section)
Fetch given BODY section, without marking the message as SEEN.
boolean processIdleResponse(Response r)
Process a response returned by readIdleResponse().
void proxyauth(String u)
PROXYAUTH Command.
synchronized Response readIdleResponse()
While an IDLE command is in progress, read a response sent from the server.
Response readResponse()
Read a response from the server.
void rename(String o, String n)
RENAME Command.
void sasllogin(String[] allowed, String realm, String authzid, String u, String p)
SASL-based login.
int[] search(SearchTerm term)
Issue the given search criterion on all messages in this folder.
int[] search(MessageSet[] msgsets, SearchTerm term)
Issue the given search criterion on the specified message sets.
MailboxInfo select(String mbox)
SELECT Command.
void setACL(String mbox, char modifier, ACL acl)
SETACL Command.
void setQuota(Quota quota)
SETQUOTA Command.
int[] sort(SortTerm[] term, SearchTerm sterm)
Sort messages in the folder according to the specified sort criteria.
void startTLS()
STARTTLS Command.
Status status(String mbox, String[] items)
STATUS Command.
void storeFlags(MessageSet[] msgsets, Flags flags, boolean set)
void storeFlags(int msg, Flags flags, boolean set)
Set the specified flags on this message.
void storeFlags(int start, int end, Flags flags, boolean set)
void storeGoogleMessageLabels(int msg, String[] labels, boolean set)
void storeGoogleMessageLabels(MessageSet[] msgsets, String[] labels, boolean set)
void storeGoogleMessageLabels(String msgset, String[] labels, boolean set)
void storeGoogleMessageLabels(int start, int end, String[] labels, boolean set)
void subscribe(String mbox)
SUBSCRIBE Command.
void uidexpunge(UIDSet[] set)
UID EXPUNGE Command.
void unselect()
UNSELECT Command.
void unsubscribe(String mbox)
UNSUBSCRIBE Command.
ListInfo[] xlist(String ref, String pattern)
XLIST Command.
Protected Methods
BODY fetchBody(int msgno, String section, int start, int size, boolean peek, ByteArray ba)
BODY fetchBody(int msgno, String section, boolean peek)
ByteArray getResponseBuffer()
Return a buffer to read a response into.
void parseCapabilities(Response r)
Parse the capabilities from a CAPABILITY response or from a CAPABILITY response code attached to (e.g.) an OK response.
void processGreeting(Response r)
Check the greeting when first connecting; look for PREAUTH response.
void setCapabilities(Response r)
If the response contains a CAPABILITY response code, extract it and save the capabilities.
boolean supportsNonSyncLiterals()
Returns whether this Protocol supports non-synchronizing literals.
[Expand]
Inherited Methods
From class com.google.code.com.sun.mail.iap.Protocol
From class java.lang.Object

Fields

private static final byte[] CRLF

private static final byte[] DONE

private boolean authenticated

private List authmechs

private ByteArray ba

private Map capabilities

private boolean connected

private String idleTag

private String name

private boolean rev1

private SaslAuthenticator saslAuthenticator

protected String[] searchCharsets

Public Constructors

public IMAPProtocol (String name, String host, int port, boolean debug, PrintStream out, Properties props, boolean isSSL)

Constructor. Opens a connection to the given host at given port.

Parameters
name
host Host to connect to
port Portnumber to connect to
debug Debug mode
out
props Properties object used by this protocol
isSSL
Throws
IOException
ProtocolException

Public Methods

public void append (String mbox, Flags f, Date d, Literal data)

APPEND Command.

Parameters
mbox
f
d
data
See Also
  • RFC2060, section 6.3.11

public AppendUID appenduid (String mbox, Flags f, Date d, Literal data)

APPEND Command, return uid from APPENDUID response code.

Parameters
mbox
f
d
data
See Also
  • RFC2060, section 6.3.11

public AppendUID appenduid (String mbox, Flags f, Date d, Literal data, boolean uid)

Parameters
mbox
f
d
data
uid

public synchronized void authlogin (String u, String p)

The AUTHENTICATE command with AUTH=LOGIN authenticate scheme

Parameters
u
p
See Also
  • RFC2060, section 6.2.1

public synchronized void authntlm (String authzid, String u, String p)

The AUTHENTICATE command with AUTH=NTLM authentication scheme. This is based heavly on the authlogin(String, String) method.

Parameters
authzid The authorization id
u The username
p The password
See Also
  • RFC3501, section 6.2.2
  • RFC2595, section 6

public synchronized void authplain (String authzid, String u, String p)

The AUTHENTICATE command with AUTH=PLAIN authentication scheme. This is based heavly on the authlogin(String, String) method.

Parameters
authzid The authorization id
u The username
p The password
See Also
  • RFC3501, section 6.2.2
  • RFC2595, section 6

public void capability ()

CAPABILITY command.

See Also
  • RFC2060, section 6.1.1

public void check ()

CHECK Command.

See Also
  • RFC2060, section 6.4.1

public void close ()

CLOSE Command.

See Also
  • RFC2060, section 6.4.2

public void copy (MessageSet[] msgsets, String mbox)

COPY command.

Parameters
msgsets
mbox

public void copy (int start, int end, String mbox)

Parameters
start
end
mbox

public void create (String mbox)

CREATE Command.

Parameters
mbox
See Also
  • RFC2060, section 6.3.3

public void delete (String mbox)

DELETE Command.

Parameters
mbox
See Also
  • RFC2060, section 6.3.4

public void deleteACL (String mbox, String user)

DELETEACL Command.

Parameters
mbox
user
See Also
  • RFC2086

public void disconnect ()

Close socket connection. This method just makes the Protocol.disconnect() method public.

public MailboxInfo examine (String mbox)

EXAMINE Command.

Parameters
mbox
See Also
  • RFC2060, section 6.3.2

public void expunge ()

EXPUNGE Command.

See Also
  • RFC2060, section 6.4.3

public Response[] fetch (MessageSet[] msgsets, String what)

Parameters
msgsets
what

public Response[] fetch (int msg, String what)

Parameters
msg
what

public Response[] fetch (int start, int end, String what)

Parameters
start
end
what

public BODY fetchBody (int msgno, String section)

Fetch given BODY section.

Parameters
msgno
section

public BODY fetchBody (int msgno, String section, int start, int size)

Partial FETCH of given BODY section.

Parameters
msgno
section
start
size

public BODY fetchBody (int msgno, String section, int start, int size, ByteArray ba)

Partial FETCH of given BODY section.

Parameters
msgno
section
start
size
ba

public BODYSTRUCTURE fetchBodyStructure (int msgno)

Fetch the BODYSTRUCTURE of the specified message.

Parameters
msgno

public Flags fetchFlags (int msgno)

Fetch the FLAGS for the given message.

Parameters
msgno

public RFC822DATA fetchRFC822 (int msgno, String what)

Fetch the specified RFC822 Data item. 'what' names the item to be fetched. 'what' can be null to fetch the whole message.

Parameters
msgno
what

public UID fetchSequenceNumber (long uid)

Get the sequence number for the given UID. A UID object containing the sequence number is returned. If the given UID is invalid, null is returned.

Parameters
uid

public UID[] fetchSequenceNumbers (long[] uids)

Get the sequence numbers for UIDs ranging from start till end. UID objects that contain the sequence numbers are returned. If no UIDs in the given range are found, an empty array is returned.

Parameters
uids

public UID[] fetchSequenceNumbers (long start, long end)

Get the sequence numbers for UIDs ranging from start till end. UID objects that contain the sequence numbers are returned. If no UIDs in the given range are found, an empty array is returned.

Parameters
start
end

public UID fetchUID (int msgno)

Fetch the IMAP UID for the given message.

Parameters
msgno

public ACL[] getACL (String mbox)

GETACL Command.

Parameters
mbox
See Also
  • RFC2086

public Map getCapabilities ()

Return the map of capabilities returned by the server.

public Quota[] getQuota (String root)

GETQUOTA Command. Returns an array of Quota objects, representing the quotas for this quotaroot.

Parameters
root
See Also
  • RFC2087

public Quota[] getQuotaRoot (String mbox)

GETQUOTAROOT Command. Returns an array of Quota objects, representing the quotas for this mailbox and, indirectly, the quotaroots for this mailbox.

Parameters
mbox
See Also
  • RFC2087

public boolean hasCapability (String c)

Check whether the given capability is supported by this server. Returns true if so, otherwise returns false.

Parameters
c

public void id (String guid)

ID Command, for Yahoo! Mail IMAP server.

Parameters
guid
See Also
  • http://en.wikipedia.org/wiki/Yahoo%21_Mail#Free_IMAP_and_SMTPs_access

public void idleAbort ()

Abort an IDLE command. While one thread is blocked in readIdleResponse(), another thread will use this method to abort the IDLE command, which will cause the server to send the closing tag for the IDLE command, which readIdleResponse() and processIdleResponse() will see and terminate the IDLE state.

public synchronized void idleStart ()

IDLE Command.

If the server supports the IDLE command extension, the IDLE command is issued and this method blocks until a response has been received. Once the first response has been received, the IDLE command is terminated and all responses are collected and handled and this method returns.

Note that while this method is blocked waiting for a response, no other threads may issue any commands to the server that would use this same connection.

See Also
  • RFC2177

public boolean isAuthenticated ()

Returns true if the connection has been authenticated, either due to a successful login, or due to a PREAUTH greeting response.

public boolean isREV1 ()

Returns true if this is a IMAP4rev1 server

public ListInfo[] list (String ref, String pattern)

LIST Command.

Parameters
ref
pattern
See Also
  • RFC2060, section 6.3.8

public Rights[] listRights (String mbox, String user)

LISTRIGHTS Command.

Parameters
mbox
user
See Also
  • RFC2086

public void login (String u, String p)

LOGIN Command.

Parameters
u
p
See Also
  • RFC2060, section 6.2.2

public void logout ()

LOGOUT Command.

See Also
  • RFC2060, section 6.1.3

public ListInfo[] lsub (String ref, String pattern)

LSUB Command.

Parameters
ref
pattern
See Also
  • RFC2060, section 6.3.9

public Rights myRights (String mbox)

MYRIGHTS Command.

Parameters
mbox
See Also
  • RFC2086

public Namespaces namespace ()

NAMESPACE Command.

See Also
  • RFC2342

public void noop ()

The NOOP command.

See Also
  • RFC2060, section 6.1.2

public BODY peekBody (int msgno, String section, int start, int size, ByteArray ba)

Partial FETCH of given BODY section, without setting SEEN flag.

Parameters
msgno
section
start
size
ba

public BODY peekBody (int msgno, String section, int start, int size)

Partial FETCH of given BODY section, without setting SEEN flag.

Parameters
msgno
section
start
size

public BODY peekBody (int msgno, String section)

Fetch given BODY section, without marking the message as SEEN.

Parameters
msgno
section

public boolean processIdleResponse (Response r)

Process a response returned by readIdleResponse(). This method will be called with appropriate locks held so that the processing of the response is safe.

Parameters
r

public void proxyauth (String u)

PROXYAUTH Command.

Parameters
u
See Also
  • Netscape/iPlanet/SunONE Messaging Server extension

public synchronized Response readIdleResponse ()

While an IDLE command is in progress, read a response sent from the server. The response is read with no locks held so that when the read blocks waiting for the response from the server it's not holding locks that would prevent other threads from interrupting the IDLE command.

public Response readResponse ()

Read a response from the server.

Throws
IOException
ProtocolException

public void rename (String o, String n)

RENAME Command.

Parameters
o
n
See Also
  • RFC2060, section 6.3.5

public void sasllogin (String[] allowed, String realm, String authzid, String u, String p)

SASL-based login.

Parameters
allowed
realm
authzid
u
p

public int[] search (SearchTerm term)

Issue the given search criterion on all messages in this folder. Returns array of matching sequence numbers. An empty array is returned if no matches are found.

Parameters
term SearchTerm
Returns
  • array of matching sequence numbers.

public int[] search (MessageSet[] msgsets, SearchTerm term)

Issue the given search criterion on the specified message sets. Returns array of matching sequence numbers. An empty array is returned if no matches are found.

Parameters
msgsets Array of MessageSets
term SearchTerm
Returns
  • array of matching sequence numbers.

public MailboxInfo select (String mbox)

SELECT Command.

Parameters
mbox
See Also
  • RFC2060, section 6.3.1

public void setACL (String mbox, char modifier, ACL acl)

SETACL Command.

Parameters
mbox
modifier
acl
See Also
  • RFC2086

public void setQuota (Quota quota)

SETQUOTA Command. Set the indicated quota on the corresponding quotaroot.

Parameters
quota
See Also
  • RFC2087

public int[] sort (SortTerm[] term, SearchTerm sterm)

Sort messages in the folder according to the specified sort criteria. If the search term is not null, limit the sort to only the messages that match the search term. Returns an array of sorted sequence numbers. An empty array is returned if no matches are found.

Parameters
term Sort criteria
sterm SearchTerm
Returns
  • array of matching sequence numbers.
See Also
  • RFC 5256

public void startTLS ()

STARTTLS Command.

See Also
  • RFC3501, section 6.2.1

public Status status (String mbox, String[] items)

STATUS Command.

Parameters
mbox
items
See Also
  • RFC2060, section 6.3.10

public void storeFlags (MessageSet[] msgsets, Flags flags, boolean set)

Parameters
msgsets
flags
set

public void storeFlags (int msg, Flags flags, boolean set)

Set the specified flags on this message.

Parameters
msg
flags
set

public void storeFlags (int start, int end, Flags flags, boolean set)

Parameters
start
end
flags
set

public void storeGoogleMessageLabels (int msg, String[] labels, boolean set)

Parameters
msg
labels
set

public void storeGoogleMessageLabels (MessageSet[] msgsets, String[] labels, boolean set)

Parameters
msgsets
labels
set

public void storeGoogleMessageLabels (String msgset, String[] labels, boolean set)

Parameters
msgset
labels
set

public void storeGoogleMessageLabels (int start, int end, String[] labels, boolean set)

Parameters
start
end
labels
set

public void subscribe (String mbox)

SUBSCRIBE Command.

Parameters
mbox
See Also
  • RFC2060, section 6.3.6

public void uidexpunge (UIDSet[] set)

UID EXPUNGE Command.

Parameters
set
See Also
  • RFC2359, section 4.1

public void unselect ()

UNSELECT Command.

See Also
  • RFC 3691

public void unsubscribe (String mbox)

UNSUBSCRIBE Command.

Parameters
mbox
See Also
  • RFC2060, section 6.3.7

public ListInfo[] xlist (String ref, String pattern)

XLIST Command.

Parameters
ref
pattern

Protected Methods

protected BODY fetchBody (int msgno, String section, int start, int size, boolean peek, ByteArray ba)

Parameters
msgno
section
start
size
peek
ba

protected BODY fetchBody (int msgno, String section, boolean peek)

Parameters
msgno
section
peek

protected ByteArray getResponseBuffer ()

Return a buffer to read a response into. The buffer is provided by fetchBody and is used only once.

protected void parseCapabilities (Response r)

Parse the capabilities from a CAPABILITY response or from a CAPABILITY response code attached to (e.g.) an OK response.

Parameters
r

protected void processGreeting (Response r)

Check the greeting when first connecting; look for PREAUTH response.

Parameters
r

protected void setCapabilities (Response r)

If the response contains a CAPABILITY response code, extract it and save the capabilities.

Parameters
r

protected boolean supportsNonSyncLiterals ()

Returns whether this Protocol supports non-synchronizing literals.