Top Description Fields Constructors Methods
com.sun.mail.imap.protocol

public Class IMAPProtocol

extends Protocol
Class Inheritance
Imports
java.io.*, java.util.*, java.text.*, java.lang.reflect.*, java.util.logging.Level, java.nio.charset.StandardCharsets, javax.mail.*, javax.mail.internet.*, javax.mail.search.*, com.sun.mail.util.PropUtil, .MailLogger, .ASCIIUtility, .BASE64EncoderStream, com.sun.mail.iap.*, com.sun.mail.auth.Ntlm, com.sun.mail.imap.ACL, .Rights, .AppendUID, .CopyUID, .SortTerm, .ResyncData, .Utility

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).
Authors
John Mani, Bill Shannon

Field Summary

Modifier and TypeField and Description
private boolean
private List<String>
private ByteArray
private Map<String, String>
private boolean
private static final byte[]
private static final byte[]
protected Set<String>
private static final FetchItem[]
private volatile String
private String
private boolean
private String
private boolean
private boolean
private SaslAuthenticator
protected String[]
protected SearchSequence
private boolean
Inherited from com.sun.mail.iap.Protocol:
hostloggerprefixpropsquotetraceLogger

Constructor Summary

AccessConstructor and Description
public
IMAPProtocol(String
the protocol name
name
,
String
host to connect to
host
,
int
port number to connect to
port
,
Properties
Properties object used by this protocol
props
,
boolean
true if SSL should be used
isSSL
,
MailLogger
the MailLogger to use for debug output
logger
)

Constructor.

public
IMAPProtocol(InputStream
the InputStream from which to read
in
,
PrintStream
the PrintStream to which to write
out
,
Properties
Properties object used by this protocol
props
,
boolean
true to enable debugging output
debug
)

Constructor for debugging.

Method Summary

Modifier and TypeMethod and Description
public void
append(String
the mailbox
mbox
,
Flags
the message Flags
f
,
Date
the message date
d
,
Literal
the message data
data
)

APPEND Command.

public AppendUID

Returns:

APPENDUID data
appenduid
(String
the mailbox
mbox
,
Flags
the message Flags
f
,
Date
the message date
d
,
Literal
the message data
data
)

APPEND Command, return uid from APPENDUID response code.

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

public synchronized void
authlogin(String
the username
u
,
String
the password
p
)

The AUTHENTICATE command with AUTH=LOGIN authenticate scheme

public synchronized void
authntlm(String
the authorization id
authzid
,
String
the username
u
,
String
the password
p
)

The AUTHENTICATE command with AUTH=NTLM authentication scheme.

public synchronized void
authoauth2(String
the username
u
,
String
the password
p
)

The AUTHENTICATE command with AUTH=XOAUTH2 authentication scheme.

public synchronized void
authplain(String
the authorization id
authzid
,
String
the username
u
,
String
the password
p
)

The AUTHENTICATE command with AUTH=PLAIN authentication scheme.

public void
capability()

CAPABILITY command.

public void
check()

CHECK Command.

private void
checkReferral(Response r)

Check for an IMAP login REFERRAL response code.

public void
close()

CLOSE Command.

public void
compress()

COMPRESS Command.

public void
copy(MessageSet[]
the messages to copy
msgsets
,
String
the mailbox to copy them to
mbox
)

COPY command.

public void
copy(int
start message number
start
,
int
end message number
end
,
String
the mailbox to copy them to
mbox
)

COPY command.

public CopyUID

Returns:

COPYUID response data
copyuid
(MessageSet[]
the messages to copy
msgsets
,
String
the mailbox to copy them to
mbox
)

COPY command, return uid from COPYUID response code.

public CopyUID

Returns:

COPYUID response data
copyuid
(int
start message number
start
,
int
end message number
end
,
String
the mailbox to copy them to
mbox
)

COPY command, return uid from COPYUID response code.

private CopyUID
copyuid(String msgSequence, String mbox, boolean uid)

public void
create(String
the mailbox to create
mbox
)

CREATE Command.

protected String

Returns:

the IMAP flag_list
createFlagList
(Flags
the flags
flags
)

Creates an IMAP flag_list from the given Flags object.

public void
delete(String
the mailbox to delete
mbox
)

DELETE Command.

public void
deleteACL(String
the mailbox
mbox
,
String
the user
user
)

DELETEACL Command.

public void
disconnect()

Overrides com.sun.mail.iap.Protocol.disconnect.

Close socket connection.
protected ListInfo[]

Returns:

array of ListInfo results
doList
(String
the list command
cmd
,
String
the reference string
ref
,
String
the pattern
pat
)

Execute the specified LIST-like command (e.g., "LIST" or "LSUB"), using the reference and pattern.

public void
enable(String
the name of the capability to enable
cap
)

ENABLE Command.

public MailboxInfo

Returns:

MailboxInfo if successful
examine
(String
the mailbox name
mbox
)

EXAMINE Command.

public MailboxInfo

Returns:

MailboxInfo if successful
examine
(String
the mailbox name
mbox
,
ResyncData
the ResyncData
rd
)

EXAMINE Command with QRESYNC data.

public void
expunge()

EXPUNGE Command.

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

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

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

private Response[]
fetch(String msgSequence, String what, boolean uid)

public BODY

Returns:

the BODY item
fetchBody
(int
the message number
msgno
,
String
the body section
section
)

Fetch given BODY section.

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

public BODY

Returns:

the BODY item
fetchBody
(int
the message number
msgno
,
String
the body section
section
,
int
starting byte count
start
,
int
number of bytes to fetch
size
)

Partial FETCH of given BODY section.

public BODY

Returns:

the BODY item
fetchBody
(int
the message number
msgno
,
String
the body section
section
,
int
starting byte count
start
,
int
number of bytes to fetch
size
,
ByteArray
the buffer into which to read the response
ba
)

Partial FETCH of given BODY section.

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

public BODYSTRUCTURE

Returns:

the BODYSTRUCTURE item
fetchBodyStructure
(int
the message number
msgno
)

Fetch the BODYSTRUCTURE of the specified message.

public Flags

Returns:

the Flags
fetchFlags
(int
the message number
msgno
)

Fetch the FLAGS for the given message.

public MODSEQ

Returns:

the MODSEQ
fetchMODSEQ
(int
the message number
msgno
)

Fetch the IMAP MODSEQ for the given message.

public RFC822DATA

Returns:

the RFC822DATA item
fetchRFC822
(int
the message number
msgno
,
String
the item to fetch
what
)

Fetch the specified RFC822 Data item.

protected BODY

Returns:

the BODY item
fetchSectionBody
(int
the message number
msgno
,
String
the body section
section
,
String
the body string
body
)

Fetch the given body section of the given message, using the body string "body".

public void
fetchSequenceNumber(long
the UID
uid
)

Get the sequence number for the given UID.

public long[]

Returns:

array of sequence numbers
fetchSequenceNumbers
(long
first UID
start
,
long
last UID
end
)

Get the sequence numbers for UIDs ranging from start till end.

public void
fetchSequenceNumbers(long[]
the UIDs
uids
)

Get the sequence numbers for UIDs specified in the array.

public UID

Returns:

the UID
fetchUID
(int
the message number
msgno
)

Fetch the IMAP UID for the given message.

public ACL[]

Returns:

the ACL array
getACL
(String
the mailbox
mbox
)

GETACL Command.

private AppendUID
getAppendUID(Response r)

If the response contains an APPENDUID response code, extract it and return an AppendUID object with the information.

public Map<String, String>

Returns:

the Map of capabilities
getCapabilities
()

Return the map of capabilities returned by the server.

protected CopyUID

Returns:

the COPYUID response code data, or null if not found
getCopyUID
(Response[]
the responses to examine
rr
)

If the response contains a COPYUID response code, extract it and return a CopyUID object with the information.

public FetchItem[]

Returns:

an array of FetchItem objects
getFetchItems
()

Return an array of FetchItem objects describing the FETCH items supported by this protocol.

pack-priv OutputStream
public String

Returns:

the PROXYAUTH user name
getProxyAuthUser
()

Get the user name used with the PROXYAUTH command.

public Quota[]

Returns:

the quotas
getQuota
(String
the quotaroot
root
)

GETQUOTA Command.

public Quota[]

Returns:

array of Quota objects
getQuotaRoot
(String
the mailbox
mbox
)

GETQUOTAROOT Command.

protected ByteArray

Returns:

the buffer to use
getResponseBuffer
()

Overrides com.sun.mail.iap.Protocol.getResponseBuffer.

Return a buffer to read a response into.
protected SearchSequence

Returns:

the SearchSequence
getSearchSequence
()

Get the SearchSequence object.

public void
handleCapabilityResponse(Response[]
the responses
r
)

Handle any untagged CAPABILITY response in the Response array.

protected void
handleLoginResult(Response
the response
r
)

Handle the result response for a LOGIN or AUTHENTICATE command.

public boolean

Returns:

true if the server has the capability
hasCapability
(String
the capability name
c
)

Check whether the given capability is supported by this server.

public void
id(String
the GUID
guid
)

Deprecated As of JavaMail 1.5.1, replaced by id(Map<String,String>)
ID Command, for Yahoo!
public Map<String, String>

Returns:

map of names and values from server
id
(Map<String, String>
map of names and values
clientParams
)

ID Command.

public void
idleAbort()

Abort an IDLE command.

public synchronized void
idleStart()

IDLE Command.

public boolean

Returns:

true if the connection has been authenticated
isAuthenticated
()

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

public boolean

Returns:

true if enabled
isEnabled
(String
the capability name
cap
)

Is the capability/extension enabled?

public boolean

Returns:

true if this is an IMAP4rev1 server
isREV1
()

Returns true if this is an IMAP4rev1 server

private int[]
issueSearch(String msgSequence, SearchTerm term, String charset)

public ListInfo[]

Returns:

LIST results
list
(String
reference string
ref
,
String
pattern to list
pattern
)

LIST Command.

public Rights[]

Returns:

the rights array
listRights
(String
the mailbox
mbox
,
String
the user rights to return
user
)

LISTRIGHTS Command.

public void
login(String
the username
u
,
String
the password
p
)

LOGIN Command.

public void
logout()

LOGOUT Command.

public ListInfo[]

Returns:

LSUB results
lsub
(String
reference string
ref
,
String
pattern to list
pattern
)

LSUB Command.

public void
move(MessageSet[]
the messages to move
msgsets
,
String
the mailbox to move them to
mbox
)

MOVE command.

public void
move(int
start message number
start
,
int
end message number
end
,
String
the mailbox to move them to
mbox
)

MOVE command.

public CopyUID

Returns:

COPYUID response data
moveuid
(MessageSet[]
the messages to move
msgsets
,
String
the mailbox to move them to
mbox
)

MOVE Command, return uid from COPYUID response code.

public CopyUID

Returns:

COPYUID response data
moveuid
(int
start message number
start
,
int
end message number
end
,
String
the mailbox to move them to
mbox
)

MOVE Command, return uid from COPYUID response code.

private CopyUID
moveuid(String msgSequence, String mbox, boolean uid)

MOVE Command, return uid from COPYUID response code.

public Rights

Returns:

the rights
myRights
(String
the mailbox
mbox
)

MYRIGHTS Command.

public Namespaces

Returns:

the namespaces
namespace
()

NAMESPACE Command.

public void
noop()

The NOOP command.

protected void
parseCapabilities(Response
the CAPABILITY response
r
)

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

private Quota
parseQuota(Response r)

Parse a QUOTA response.

public BODY

Returns:

the BODY item
peekBody
(int
the message number
msgno
,
String
the body section
section
)

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

public BODY

Returns:

the BODY item
peekBody
(int
the message number
msgno
,
String
the body section
section
,
int
starting byte count
start
,
int
number of bytes to fetch
size
)

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

public BODY

Returns:

the BODY item
peekBody
(int
the message number
msgno
,
String
the body section
section
,
int
starting byte count
start
,
int
number of bytes to fetch
size
,
ByteArray
the buffer into which to read the response
ba
)

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

protected void
processGreeting(Response
the greeting response
r
)

Overrides com.sun.mail.iap.Protocol.processGreeting.

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

Returns:

true if IDLE is done
processIdleResponse
(Response
the response
r
)

Process a response returned by readIdleResponse().

public void
proxyauth(String
the PROXYAUTH user name
u
)

PROXYAUTH Command.

public synchronized Response

Returns:

the response
readIdleResponse
()

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

public Response

Returns:

the response
readResponse
()

Overrides com.sun.mail.iap.Protocol.readResponse.

Read a response from the server.
public void
rename(String
old mailbox name
o
,
String
new mailbox name
n
)

RENAME Command.

private static Argument
resyncArgs(ResyncData rd)

Generate a QRESYNC argument list based on the ResyncData.

public void
sasllogin(String[]
the SASL mechanisms we're allowed to use
allowed
,
String
the SASL realm
realm
,
String
the authorization id
authzid
,
String
the username
u
,
String
the password
p
)

SASL-based login.

public int[]

Returns:

array of matching sequence numbers.
search
(MessageSet[]
array of MessageSets
msgsets
,
SearchTerm
SearchTerm
term
)

Issue the given search criterion on the specified message sets.

public int[]

Returns:

array of matching sequence numbers.
search
(SearchTerm
SearchTerm
term
)

Issue the given search criterion on all messages in this folder.

private int[]
search(String msgSequence, SearchTerm term)

public MailboxInfo

Returns:

MailboxInfo if successful
select
(String
the mailbox name
mbox
)

SELECT Command.

public MailboxInfo

Returns:

MailboxInfo if successful
select
(String
the mailbox name
mbox
,
ResyncData
the ResyncData
rd
)

SELECT Command with QRESYNC data.

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

SETACL Command.

protected void
setCapabilities(Response
the response
r
)

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

public void
setQuota(Quota
the quota to set
quota
)

SETQUOTA Command.

public int[]

Returns:

array of matching sequence numbers.
sort
(SortTerm[]
sort criteria
term
,
SearchTerm
SearchTerm
sterm
)

Sort messages in the folder according to the specified sort criteria.

public void
startTLS()

STARTTLS Command.

public Status

Returns:

STATUS results
status
(String
the mailbox
mbox
,
String[]
the STATUS items to request
items
)

STATUS Command.

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

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

public void
storeFlags(int
the message number
msg
,
Flags
the flags
flags
,
boolean
true to set, false to clear
set
)

Set the specified flags on this message.

private void
storeFlags(String msgset, Flags flags, boolean set)

public void
subscribe(String
the mailbox
mbox
)

SUBSCRIBE Command.

protected boolean

Returns:

true if non-synchronizing literals are supported
supportsNonSyncLiterals
()

Overrides com.sun.mail.iap.Protocol.supportsNonSyncLiterals.

Returns whether this Protocol supports non-synchronizing literals.
public boolean
supportsUtf8()

Overrides com.sun.mail.iap.Protocol.supportsUtf8.

Does the server support UTF-8?
public void
uidexpunge(UIDSet[]
UIDs to expunge
set
)

UID EXPUNGE Command.

public int[]

Returns:

array of sequence numbers
uidfetchChangedSince
(long
first UID
start
,
long
last UID
end
,
long
the MODSEQ
modseq
)

Get the sequence numbers for messages changed since the given modseq and with UIDs ranging from start till end.

public void
unauthenticate()

UNAUTHENTICATE Command.

public void
unselect()

UNSELECT Command.

public void
unsubscribe(String
the mailbox
mbox
)

UNSUBSCRIBE Command.

protected void
writeMailboxName(Argument
the arguments
args
,
String
the name to encode
name
)

Encode a mailbox name appropriately depending on whether or not the server supports UTF-8, and add the encoded name to the Argument.

Inherited from com.sun.mail.iap.Protocol:
addResponseHandlercommandfinalizegetChannelgetInetAddressgetInputStreamgetLocalHostgetOutputStreamgetTimestamphandleResulthasResponseisSSLisTracingnotifyResponseHandlersremoveResponseHandlerresumeTracingsimpleCommandstartCompressionstartTLSsuspendTracingwriteCommand