This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


com.sun.mail.imap.protocol
class IMAPProtocol

com.sun.mail.iap.Protocol extended by com.sun.mail.imap.protocol.IMAPProtocol

public class IMAPProtocol
extends Protocol

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).


Field Summary
 
Fields inherited from class com.sun.mail.iap.Protocol
debug, host, out, prefix, props, quote
 
Constructor Summary
IMAPProtocol(String name, String host, int port, boolean debug, PrintStream out, Properties props, boolean isSSL)

          Constructor.
 
Method Summary
 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)

          
 void

          The AUTHENTICATE command with AUTH=LOGIN authenticate scheme
 void
authplain(String authzid, String u, String p)

          The AUTHENTICATE command with AUTH=PLAIN authentication scheme.
 void

          CAPABILITY command.
 void

          CHECK Command.
 void

          CLOSE Command.
 void
copy(int start, int end, String mbox)

          
 void
copy(MessageSet[] msgsets, String mbox)

          COPY command.
 void
create(String mbox)

          CREATE Command.
 void
delete(String mbox)

          DELETE Command.
 void
deleteACL(String mbox, String user)

          DELETEACL Command.
 void

          Close socket connection.
 MailboxInfo

          EXAMINE Command.
 void

          EXPUNGE Command.
 Response[]
fetch(int start, int end, String what)

          
 Response[]
fetch(int msg, String what)

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

          
 BODY
fetchBody(int msgno, String section)

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

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

          Partial FETCH of given BODY section.
protected BODY
fetchBody(int msgno, String section, int start, int size, boolean peek, ByteArray ba)

          
 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

          Get the sequence number for the given UID.
 UID[]
fetchSequenceNumbers(long start, long end)

          Get the sequence numbers for UIDs ranging from start till end.
 UID[]
fetchSequenceNumbers(long[] uids)

          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

          Return the map of capabilities returned by the server.
 Quota[]

          GETQUOTA Command.
 Quota[]

          GETQUOTAROOT Command.
protected ByteArray

          Return a buffer to read a response into.
 boolean

          Check whether the given capability is supported by this server.
 void

          Abort an IDLE command.
 void

          IDLE Command.
 boolean

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

          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 Command.
 void

          LOGOUT Command.
 ListInfo[]
lsub(String ref, String pattern)

          LSUB Command.
 Rights

          MYRIGHTS Command.
 Namespaces

          NAMESPACE Command.
 void

          The NOOP command.
protected void

          Parse the capabilities from a CAPABILITY response or from a CAPABILITY response code attached to (e.g.) an OK response.
 BODY
peekBody(int msgno, String section)

          Fetch given BODY section, without marking the message as SEEN.
 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, int start, int size, ByteArray ba)

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

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

          Process a response returned by readIdleResponse().
 void

          PROXYAUTH Command.
 Response

          While an IDLE command is in progress, read a response sent from the server.
 Response

          Read a response from the server.
 void

          RENAME Command.
 void
sasllogin(String[] allowed, String realm, String authzid, String u, String p)

          SASL-based login.
 int[]
search(MessageSet[] msgsets, SearchTerm term)

          Issue the given search criterion on the specified message sets.
 int[]

          Issue the given search criterion on all messages in this folder.
 MailboxInfo
select(String mbox)

          SELECT Command.
 void
setACL(String mbox, char modifier, ACL acl)

          SETACL Command.
protected void

          If the response contains a CAPABILITY response code, extract it and save the capabilities.
 void
setQuota(Quota quota)

          SETQUOTA Command.
 void

          STARTTLS Command.
 Status
status(String mbox, String[] items)

          STATUS Command.
 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
storeFlags(MessageSet[] msgsets, Flags flags, boolean set)

          
 void

          SUBSCRIBE Command.
protected boolean

          Returns whether this Protocol supports non-synchronizing literals.
 void

          UID EXPUNGE Command.
 void

          UNSUBSCRIBE Command.
 
Methods inherited from class com.sun.mail.iap.Protocol
addResponseHandler, command, disconnect, finalize, getInputStream, getOutputStream, getResponseBuffer, getTimestamp, handleResult, notifyResponseHandlers, processGreeting, readResponse, removeResponseHandler, simpleCommand, startTLS, supportsNonSyncLiterals, writeCommand
 

Constructor Detail

IMAPProtocol

public IMAPProtocol(String name,
                    String host,
                    int port,
                    boolean debug,
                    PrintStream out,
                    Properties props,
                    boolean isSSL)
             throws IOException,
                    ProtocolException
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
Method Detail

append

public void append(String mbox,
                   Flags f,
                   Date d,
                   Literal data)
            throws ProtocolException
APPEND Command.

Parameters:
mbox
f
d
data
Throws:
ProtocolException

appenduid

public AppendUID appenduid(String mbox,
                           Flags f,
                           Date d,
                           Literal data)
                    throws ProtocolException
APPEND Command, return uid from APPENDUID response code.

Parameters:
mbox
f
d
data
Throws:
ProtocolException

appenduid

public AppendUID appenduid(String mbox,
                           Flags f,
                           Date d,
                           Literal data,
                           boolean uid)
                    throws ProtocolException
Parameters:
mbox
f
d
data
uid
Throws:
ProtocolException

authlogin

public synchronized void authlogin(String u,
                                   String p)
                            throws ProtocolException
The AUTHENTICATE command with AUTH=LOGIN authenticate scheme

Parameters:
u
p
Throws:
ProtocolException

authplain

public synchronized void authplain(String authzid,
                                   String u,
                                   String p)
                            throws ProtocolException
The AUTHENTICATE command with AUTH=PLAIN authentication scheme. This is based heavly on the {@link #authlogin} method.

Parameters:
authzid - the authorization id
u - the username
p - the password
Throws:
ProtocolException - as thrown by {@link Protocol#handleResult}.

capability

public void capability()
                throws ProtocolException
CAPABILITY command.

Throws:
ProtocolException

check

public void check()
           throws ProtocolException
CHECK Command.

Throws:
ProtocolException

close

public void close()
           throws ProtocolException
CLOSE Command.

Throws:
ProtocolException

copy

public void copy(int start,
                 int end,
                 String mbox)
          throws ProtocolException
Parameters:
start
end
mbox
Throws:
ProtocolException

copy

public void copy(MessageSet[] msgsets,
                 String mbox)
          throws ProtocolException
COPY command.

Parameters:
msgsets
mbox
Throws:
ProtocolException

create

public void create(String mbox)
            throws ProtocolException
CREATE Command.

Parameters:
mbox
Throws:
ProtocolException

delete

public void delete(String mbox)
            throws ProtocolException
DELETE Command.

Parameters:
mbox
Throws:
ProtocolException

deleteACL

public void deleteACL(String mbox,
                      String user)
               throws ProtocolException
DELETEACL Command.

Parameters:
mbox
user
Throws:
ProtocolException

disconnect

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

Overrides:
disconnect in class Protocol

examine

public MailboxInfo examine(String mbox)
                    throws ProtocolException
EXAMINE Command.

Parameters:
mbox
Throws:
ProtocolException

expunge

public void expunge()
             throws ProtocolException
EXPUNGE Command.

Throws:
ProtocolException

fetch

public Response[] fetch(int start,
                        int end,
                        String what)
                 throws ProtocolException
Parameters:
start
end
what
Throws:
ProtocolException

fetch

public Response[] fetch(int msg,
                        String what)
                 throws ProtocolException
Parameters:
msg
what
Throws:
ProtocolException

fetch

public Response[] fetch(MessageSet[] msgsets,
                        String what)
                 throws ProtocolException
Parameters:
msgsets
what
Throws:
ProtocolException

fetchBody

public BODY fetchBody(int msgno,
                      String section)
               throws ProtocolException
Fetch given BODY section.

Parameters:
msgno
section
Throws:
ProtocolException

fetchBody

protected BODY fetchBody(int msgno,
                         String section,
                         boolean peek)
                  throws ProtocolException
Parameters:
msgno
section
peek
Throws:
ProtocolException

fetchBody

public BODY fetchBody(int msgno,
                      String section,
                      int start,
                      int size)
               throws ProtocolException
Partial FETCH of given BODY section.

Parameters:
msgno
section
start
size
Throws:
ProtocolException

fetchBody

protected BODY fetchBody(int msgno,
                         String section,
                         int start,
                         int size,
                         boolean peek,
                         ByteArray ba)
                  throws ProtocolException
Parameters:
msgno
section
start
size
peek
ba
Throws:
ProtocolException

fetchBody

public BODY fetchBody(int msgno,
                      String section,
                      int start,
                      int size,
                      ByteArray ba)
               throws ProtocolException
Partial FETCH of given BODY section.

Parameters:
msgno
section
start
size
ba
Throws:
ProtocolException

fetchBodyStructure

public BODYSTRUCTURE fetchBodyStructure(int msgno)
                                 throws ProtocolException
Fetch the BODYSTRUCTURE of the specified message.

Parameters:
msgno
Throws:
ProtocolException

fetchFlags

public Flags fetchFlags(int msgno)
                 throws ProtocolException
Fetch the FLAGS for the given message.

Parameters:
msgno
Throws:
ProtocolException

fetchRFC822

public RFC822DATA fetchRFC822(int msgno,
                              String what)
                       throws ProtocolException
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
Throws:
ProtocolException

fetchSequenceNumber

public UID fetchSequenceNumber(long uid)
                        throws ProtocolException
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
Throws:
ProtocolException

fetchSequenceNumbers

public UID[] fetchSequenceNumbers(long start,
                                  long end)
                           throws ProtocolException
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
Throws:
ProtocolException

fetchSequenceNumbers

public UID[] fetchSequenceNumbers(long[] uids)
                           throws ProtocolException
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
Throws:
ProtocolException

fetchUID

public UID fetchUID(int msgno)
             throws ProtocolException
Fetch the IMAP UID for the given message.

Parameters:
msgno
Throws:
ProtocolException

getACL

public ACL[] getACL(String mbox)
             throws ProtocolException
GETACL Command.

Parameters:
mbox
Throws:
ProtocolException

getCapabilities

public Map getCapabilities()
Return the map of capabilities returned by the server.


getQuota

public Quota[] getQuota(String root)
                 throws ProtocolException
GETQUOTA Command. Returns an array of Quota objects, representing the quotas for this quotaroot.

Parameters:
root
Throws:
ProtocolException

getQuotaRoot

public Quota[] getQuotaRoot(String mbox)
                     throws ProtocolException
GETQUOTAROOT Command. Returns an array of Quota objects, representing the quotas for this mailbox and, indirectly, the quotaroots for this mailbox.

Parameters:
mbox
Throws:
ProtocolException

getResponseBuffer

protected ByteArray getResponseBuffer()
Return a buffer to read a response into. The buffer is provided by fetchBody and is used only once.

Overrides:
getResponseBuffer in class Protocol

hasCapability

public boolean hasCapability(String c)
Check whether the given capability is supported by this server. Returns true if so, otherwise returns false.

Parameters:
c

idleAbort

public void idleAbort()
               throws ProtocolException
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.

Throws:
ProtocolException

idleStart

public synchronized void idleStart()
                            throws ProtocolException
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.

Throws:
ProtocolException

isAuthenticated

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


isREV1

public boolean isREV1()
Returns true if this is a IMAP4rev1 server


list

public ListInfo[] list(String ref,
                       String pattern)
                throws ProtocolException
LIST Command.

Parameters:
ref
pattern
Throws:
ProtocolException

listRights

public Rights[] listRights(String mbox,
                           String user)
                    throws ProtocolException
LISTRIGHTS Command.

Parameters:
mbox
user
Throws:
ProtocolException

login

public void login(String u,
                  String p)
           throws ProtocolException
LOGIN Command.

Parameters:
u
p
Throws:
ProtocolException

logout

public void logout()
            throws ProtocolException
LOGOUT Command.

Throws:
ProtocolException

lsub

public ListInfo[] lsub(String ref,
                       String pattern)
                throws ProtocolException
LSUB Command.

Parameters:
ref
pattern
Throws:
ProtocolException

myRights

public Rights myRights(String mbox)
                throws ProtocolException
MYRIGHTS Command.

Parameters:
mbox
Throws:
ProtocolException

namespace

public Namespaces namespace()
                     throws ProtocolException
NAMESPACE Command.

Throws:
ProtocolException

noop

public void noop()
          throws ProtocolException
The NOOP command.

Throws:
ProtocolException

parseCapabilities

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

peekBody

public BODY peekBody(int msgno,
                     String section)
              throws ProtocolException
Fetch given BODY section, without marking the message as SEEN.

Parameters:
msgno
section
Throws:
ProtocolException

peekBody

public BODY peekBody(int msgno,
                     String section,
                     int start,
                     int size)
              throws ProtocolException
Partial FETCH of given BODY section, without setting SEEN flag.

Parameters:
msgno
section
start
size
Throws:
ProtocolException

peekBody

public BODY peekBody(int msgno,
                     String section,
                     int start,
                     int size,
                     ByteArray ba)
              throws ProtocolException
Partial FETCH of given BODY section, without setting SEEN flag.

Parameters:
msgno
section
start
size
ba
Throws:
ProtocolException

processGreeting

protected void processGreeting(Response r)
                        throws ProtocolException
Check the greeting when first connecting; look for PREAUTH response.

Overrides:
processGreeting in class Protocol
Parameters:
r
Throws:
ProtocolException

processIdleResponse

public boolean processIdleResponse(Response r)
                            throws ProtocolException
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
Throws:
ProtocolException

proxyauth

public void proxyauth(String u)
               throws ProtocolException
PROXYAUTH Command.

Parameters:
u
Throws:
ProtocolException

readIdleResponse

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.


readResponse

public Response readResponse()
                      throws IOException,
                             ProtocolException
Read a response from the server.

Overrides:
readResponse in class Protocol
Throws:
IOException
ProtocolException

rename

public void rename(String o,
                   String n)
            throws ProtocolException
RENAME Command.

Parameters:
o
n
Throws:
ProtocolException

sasllogin

public void sasllogin(String[] allowed,
                      String realm,
                      String authzid,
                      String u,
                      String p)
               throws ProtocolException
SASL-based login.

Parameters:
allowed
realm
authzid
u
p
Throws:
ProtocolException

search

public int[] search(MessageSet[] msgsets,
                    SearchTerm term)
             throws ProtocolException,
                    SearchException
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.
Throws:
ProtocolException
SearchException

search

public int[] search(SearchTerm term)
             throws ProtocolException,
                    SearchException
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.
Throws:
ProtocolException
SearchException

select

public MailboxInfo select(String mbox)
                   throws ProtocolException
SELECT Command.

Parameters:
mbox
Throws:
ProtocolException

setACL

public void setACL(String mbox,
                   char modifier,
                   ACL acl)
            throws ProtocolException
SETACL Command.

Parameters:
mbox
modifier
acl
Throws:
ProtocolException

setCapabilities

protected void setCapabilities(Response r)
If the response contains a CAPABILITY response code, extract it and save the capabilities.

Parameters:
r

setQuota

public void setQuota(Quota quota)
              throws ProtocolException
SETQUOTA Command. Set the indicated quota on the corresponding quotaroot.

Parameters:
quota
Throws:
ProtocolException

startTLS

public void startTLS()
              throws ProtocolException
STARTTLS Command.

Throws:
ProtocolException

status

public Status status(String mbox,
                     String[] items)
              throws ProtocolException
STATUS Command.

Parameters:
mbox
items
Throws:
ProtocolException

storeFlags

public void storeFlags(int msg,
                       Flags flags,
                       boolean set)
                throws ProtocolException
Set the specified flags on this message.

Parameters:
msg
flags
set
Throws:
ProtocolException

storeFlags

public void storeFlags(int start,
                       int end,
                       Flags flags,
                       boolean set)
                throws ProtocolException
Parameters:
start
end
flags
set
Throws:
ProtocolException

storeFlags

public void storeFlags(MessageSet[] msgsets,
                       Flags flags,
                       boolean set)
                throws ProtocolException
Parameters:
msgsets
flags
set
Throws:
ProtocolException

subscribe

public void subscribe(String mbox)
               throws ProtocolException
SUBSCRIBE Command.

Parameters:
mbox
Throws:
ProtocolException

supportsNonSyncLiterals

protected boolean supportsNonSyncLiterals()
Returns whether this Protocol supports non-synchronizing literals.

Overrides:
supportsNonSyncLiterals in class Protocol

uidexpunge

public void uidexpunge(UIDSet[] set)
                throws ProtocolException
UID EXPUNGE Command.

Parameters:
set
Throws:
ProtocolException

unsubscribe

public void unsubscribe(String mbox)
                 throws ProtocolException
UNSUBSCRIBE Command.

Parameters:
mbox
Throws:
ProtocolException


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention. The official Sun™ documentation can be found here at http://java.sun.com/products/javamail/javadocs/index.html.