|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.geronimo.javamail.util.MailConnection org.apache.geronimo.javamail.store.imap.connection.IMAPConnection
public class IMAPConnection
Simple implementation of IMAP transport. Just does plain RFC977-ish delivery.
There is no way to indicate failure for a given recipient (it's possible to have a recipient address rejected). The sun impl throws exceptions even if others successful), but maybe we do a different way...
Field Summary | |
---|---|
protected static String |
CAPABILITY_LOGIN_DISABLED
|
protected boolean |
closed
|
protected long |
lastAccess
|
protected IMAPConnectionPool |
pool
|
protected List |
queuedResponses
|
protected IMAPResponseStream |
reader
|
protected LinkedList |
responseHandlers
|
Constructor Summary | |
---|---|
IMAPConnection(ProtocolProperties props,
IMAPConnectionPool pool)
Normal constructor for an IMAPConnection() object. |
Method Summary | |
---|---|
void |
addACLRights(String mailbox,
ACL acl)
Add a set of ACL rights to a mailbox. |
void |
addResponseHandler(IMAPUntaggedResponseHandler h)
Attach a handler for untagged responses to this connection. |
void |
appendMessage(String mailbox,
Date messageDate,
Flags messageFlags,
byte[] messageData)
Append a message to a mailbox, given the direct message data. |
void |
close()
Close the connection. |
void |
closeMailbox()
Deselect a mailbox when a folder returns a connection. |
void |
copyMessages(String messageSet,
String target)
Copy a range of messages to a target mailbox. |
void |
createMailbox(String mailbox)
Create a mailbox. |
void |
deleteACL(String mailbox,
String name)
Delete an ACL item for a given user name from a target mailbox. |
void |
deleteMailbox(String mailbox)
Delete a mailbox. |
List |
expungeMailbox()
Tells the IMAP server to expunge messages marked for deletion. |
protected IMAPFetchDataItem |
extractFetchDataItem(long sequenceNumber,
int type)
Extract a fetch response data item from the queued elements. |
protected List |
extractFetchDataItems(int type)
Extract a all fetch responses that contain a given data item. |
List |
extractFetchResponses(int sequenceNumber)
Extract all responses from the pending queue that are "FETCH" responses for a given message number. |
IMAPUntaggedResponse |
extractResponse(String type)
Extract a single response from the pending queue that match a give keyword type. |
List |
extractResponses(String type)
Extract all responses from the pending queue that match a give keyword type. |
List |
fetch(String messageSet,
FetchProfile profile)
Prefetch message information based on the request profile. |
IMAPBody |
fetchBody(int sequenceNumber,
String section)
Issue a FETCH command to retrieve the entire message body in one shot. |
IMAPMessageText |
fetchBodyPartText(int sequenceNumber,
String section)
Issue a FETCH command to retrieve the message text |
IMAPBodyStructure |
fetchBodyStructure(int sequenceNumber)
Issue a FETCH command to retrieve the message BODYSTRUCTURE structure. |
byte[] |
fetchContent(int sequenceNumber)
Fetch the message content. |
byte[] |
fetchContent(int sequenceNumber,
String section)
Fetch the message content. |
List |
fetchEnvelope(int sequenceNumber)
Issue a fetch command to retrieve the message ENVELOPE structure. |
Flags |
fetchFlags(int sequenceNumber)
Fetch the flag set for a given message sequence number. |
InternetHeaders |
fetchHeaders(int sequenceNumber,
String part)
Issue a FETCH command to retrieve the message RFC822.HEADERS structure containing the message headers (using PEEK). |
Quota[] |
fetchQuota(String root)
Fetch QUOTA information from a named QUOTE root. |
Quota[] |
fetchQuotaRoot(String mailbox)
Fetch the quota root information for a target mailbox. |
IMAPMessageText |
fetchText(int sequenceNumber)
Issue a FETCH command to retrieve the message text |
ACL[] |
getACLRights(String mailbox)
Get the ACL rights assigned to a given mailbox. |
void |
getCapability()
Get the servers capabilities from the wire.... |
protected void |
getConnection()
Create a transport connection object and connect it to the target server. |
String |
getHost()
Return the server host for this connection. |
IMAPMailboxStatus |
getMailboxStatus(String mailbox)
Retrieve a complete set of status items for a mailbox. |
Rights |
getMyRights(String mailbox)
Get the current user's ACL rights to a given mailbox. |
IMAPNamespaceResponse |
getNamespaces()
Retrieve the user name space info from the server. |
protected ClientAuthenticator |
getSaslAuthenticator()
|
IMAPUid |
getSequenceNumberForUid(long uid)
Fetch the message number for a give UID. |
List |
getSequenceNumbersForUids(long start,
long end)
Fetch the message numbers for a consequetive range of UIDs. |
IMAPUid |
getUidForSequenceNumber(int sequenceNumber)
Fetch the UID value for a target message number |
boolean |
hasCapability(String capability)
Test if this connection has a given capability. |
boolean |
isAlive(long timeout)
check to see if this connection is truely alive. |
boolean |
isClosed()
Test if the connnection has been forcibly closed. |
boolean |
isStale(long timeout)
Test if the connection has been sitting idle for longer than the set timeout period. |
List |
list(String mailbox,
String pattern)
Send an LIST command to the IMAP server, returning all LIST response information. |
Rights[] |
listACLRights(String mailbox,
String name)
List the ACL rights that a particular user has to a mailbox. |
List |
listSubscribed(String mailbox,
String pattern)
Send an LSUB command to the IMAP server, returning all LSUB response information. |
protected boolean |
login()
Authenticate with the server, if necessary (or possible). |
void |
logout()
Logs out from the server. |
IMAPMailboxStatus |
openMailbox(String mailbox,
boolean readOnly)
Select a mailbox, returning the accumulated status information about the mailbox returned with the response. |
protected boolean |
processLogin()
Process a LOGIN using the LOGIN command instead of AUTHENTICATE. |
protected boolean |
processLogin(ClientAuthenticator authenticator)
Process a login using the provided authenticator object. |
protected boolean |
processLoginAuthentication()
Process SASL-type LOGIN authentication. |
void |
processPendingResponses()
Process any untagged responses in the queue. |
protected boolean |
processPlainAuthentication()
Process SASL-type PLAIN authentication. |
protected boolean |
processSaslAuthentication()
Process SASL-type authentication. |
boolean |
protocolConnect(String host,
int port,
String authid,
String realm,
String username,
String password)
Connect to the server and do the initial handshaking. |
void |
queuePendingResponse(IMAPUntaggedResponse response)
Add a response to the pending untagged response queue. |
IMAPTaggedResponse |
receiveResponse()
Get a reply line for an IMAP command. |
void |
removeACLRights(String mailbox,
ACL acl)
Remove an ACL from a given mailbox. |
void |
removeResponseHandler(IMAPUntaggedResponseHandler h)
Remove a response handler from the connection. |
void |
renameMailbox(String oldName,
String newName)
Rename a mailbox. |
int[] |
searchMailbox(SearchTerm term)
|
int[] |
searchMailbox(String messages,
SearchTerm term)
Send a search to the IMAP server using the specified messages selector and search term. |
int[] |
searchMailbox(String messages,
SearchTerm term,
String charset)
Send a search to the IMAP server using the specified messages selector and search term. |
IMAPTaggedResponse |
sendCommand(IMAPCommand data)
Sends a command down the socket, returning the server response. |
IMAPTaggedResponse |
sendCommand(String data)
Sends a command down the socket, returning the server response. |
IMAPTaggedResponse |
sendLine(byte[] data)
Sends a message down the socket and terminates with the appropriate CRLF |
IMAPTaggedResponse |
sendLine(byte[] data,
int offset,
int length)
Sends a message down the socket and terminates with the appropriate CRLF |
IMAPTaggedResponse |
sendLine(String data)
Sends a message down the socket and terminates with the appropriate CRLF |
void |
sendSimpleCommand(IMAPCommand data)
Process a simple command/response sequence between the client and the server. |
void |
sendSimpleCommand(String data)
Process a simple command/response sequence between the client and the server. |
void |
setACLRights(String mailbox,
ACL acl)
Set the ACL rights for a mailbox. |
void |
setClosed()
Tag this connection as having been closed by the server. |
Flags |
setFlags(int sequenceNumber,
Flags flags,
boolean set)
Set the flags for a single message. |
List |
setFlags(String messageSet,
Flags flags,
boolean set)
Set the flags for a range of messages. |
void |
setQuota(Quota quota)
Set a Quota item for the currently accessed userid/folder resource. |
void |
subscribe(String mailbox)
Subscribe to a give mailbox. |
void |
unsubscribe(String mailbox)
Unsubscribe from a mailbox. |
protected void |
updateLastAccess()
Update the last access time for the connection. |
void |
updateMailboxStatus()
Make sure we have the latest status information available. |
Methods inherited from class org.apache.geronimo.javamail.util.MailConnection |
---|
checkConnected, closeServerConnection, connect, debugOut, debugOut, getCapabilities, getConnectedSocket, getConnectedSSLSocket, getConnectedTLSSocket, getConnectionProperties, getConnectionStreams, getLocalHost, getLoginAuthenticator, getSaslMechanisms, getSASLRealm, getServerMechanisms, protocolConnect, selectSaslMechanisms, setLocalHost, setSASLRealm, supportsMechanism |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final String CAPABILITY_LOGIN_DISABLED
protected IMAPConnectionPool pool
protected IMAPResponseStream reader
protected long lastAccess
protected LinkedList responseHandlers
protected List queuedResponses
protected boolean closed
Constructor Detail |
---|
public IMAPConnection(ProtocolProperties props, IMAPConnectionPool pool)
props
- The protocol properties abstraction containing our
property modifiers.pool
- Method Detail |
---|
public boolean protocolConnect(String host, int port, String authid, String realm, String username, String password) throws MessagingException
MessagingException
protected void updateLastAccess()
public boolean isStale(long timeout)
timeout
- The allowed "freshness" interval.
public void close() throws MessagingException
MessagingException
protected void getConnection() throws IOException, MessagingException
getConnection
in class MailConnection
MessagingException
IOException
public void sendSimpleCommand(String data) throws MessagingException
data
- The command data we're writing out.
MessagingException
public void sendSimpleCommand(IMAPCommand data) throws MessagingException
data
- The command data we're writing out.
MessagingException
public IMAPTaggedResponse sendCommand(String data) throws MessagingException
data
- The String form of the command.
MessagingException
public IMAPTaggedResponse sendCommand(IMAPCommand data) throws MessagingException
data
- An IMAPCommand object with the prepared command information.
MessagingException
public IMAPTaggedResponse sendLine(String data) throws MessagingException
data
- The string data to send.
MessagingException
public IMAPTaggedResponse sendLine(byte[] data) throws MessagingException
data
- The array of data to send to the server.
MessagingException
public IMAPTaggedResponse sendLine(byte[] data, int offset, int length) throws MessagingException
data
- The source data array.offset
- The offset within the data array.length
- The length of data to send.
MessagingException
public IMAPTaggedResponse receiveResponse() throws MessagingException
MessagingException
public void getCapability() throws MessagingException
MessagingException
public void logout() throws MessagingException
MessagingException
public void closeMailbox() throws MessagingException
MessagingException
protected boolean login() throws MessagingException
MessagingException
protected boolean processSaslAuthentication() throws MessagingException
MessagingException
protected ClientAuthenticator getSaslAuthenticator()
protected boolean processPlainAuthentication() throws MessagingException
MessagingException
protected boolean processLoginAuthentication() throws MessagingException
MessagingException
protected boolean processLogin() throws MessagingException
MessagingException
protected boolean processLogin(ClientAuthenticator authenticator) throws MessagingException
MessagingException
public String getHost()
getHost
in class MailConnection
public void addResponseHandler(IMAPUntaggedResponseHandler h)
h
- The new untagged response handler.public void removeResponseHandler(IMAPUntaggedResponseHandler h)
h
- The handler to remove.public void queuePendingResponse(IMAPUntaggedResponse response)
response
- The response to add.public void processPendingResponses() throws MessagingException
MessagingException
public IMAPUntaggedResponse extractResponse(String type)
type
- The string name of the keyword.
public List extractResponses(String type)
type
- The string name of the keyword.
public List extractFetchResponses(int sequenceNumber)
type
- The string name of the keyword.
protected IMAPFetchDataItem extractFetchDataItem(long sequenceNumber, int type)
sequenceNumber
- The message number we're interested in. Fetch responses for other messages
will be skipped.type
- The type of body element we need. It is assumed that only one item for
the given message number will exist in the queue. The located item will
be returned, and that fetch response will be removed from the pending queue.
protected List extractFetchDataItems(int type)
type
- The type of body element we need. It is assumed that only one item for
the given message number will exist in the queue. The located item will
be returned, and that fetch response will be removed from the pending queue.
public void updateMailboxStatus() throws MessagingException
MessagingException
public boolean isAlive(long timeout)
timeout
- The timeout value to control how often we ping
the server to see if we're still good.
public List fetchEnvelope(int sequenceNumber) throws MessagingException
sequenceNumber
- The sequence number of the message.
MessagingException
public IMAPBodyStructure fetchBodyStructure(int sequenceNumber) throws MessagingException
sequenceNumber
- The sequence number of the message.
MessagingException
public InternetHeaders fetchHeaders(int sequenceNumber, String part) throws MessagingException
sequenceNumber
- The sequence number of the message.
MessagingException
public IMAPMessageText fetchText(int sequenceNumber) throws MessagingException
sequenceNumber
- The sequence number of the message.
MessagingException
public IMAPMessageText fetchBodyPartText(int sequenceNumber, String section) throws MessagingException
sequenceNumber
- The sequence number of the message.
MessagingException
public IMAPBody fetchBody(int sequenceNumber, String section) throws MessagingException
sequenceNumber
- The sequence number of the message.section
- The section number to fetch. If null, the entire body of the message
is retrieved.
MessagingException
public byte[] fetchContent(int sequenceNumber) throws MessagingException
sequenceNumber
- The sequence number of the target message.
MessagingException
public byte[] fetchContent(int sequenceNumber, String section) throws MessagingException
sequenceNumber
- The sequence number of the target message.
MessagingException
public List list(String mailbox, String pattern) throws MessagingException
mailbox
- The reference mailbox name sent on the command.pattern
- The match pattern used on the name.
MessagingException
public List listSubscribed(String mailbox, String pattern) throws MessagingException
mailbox
- The reference mailbox name sent on the command.pattern
- The match pattern used on the name.
MessagingException
public void subscribe(String mailbox) throws MessagingException
mailbox
- The desired mailbox name.
MessagingException
public void unsubscribe(String mailbox) throws MessagingException
mailbox
- The mailbox to remove.
MessagingException
public void createMailbox(String mailbox) throws MessagingException
mailbox
- The desired new mailbox name (fully qualified);
MessagingException
public void deleteMailbox(String mailbox) throws MessagingException
mailbox
- The target mailbox name (fully qualified);
MessagingException
public void renameMailbox(String oldName, String newName) throws MessagingException
mailbox
- The target mailbox name (fully qualified);
MessagingException
public IMAPMailboxStatus getMailboxStatus(String mailbox) throws MessagingException
mailbox
- The mailbox name.
MessagingException
public IMAPMailboxStatus openMailbox(String mailbox, boolean readOnly) throws MessagingException
mailbox
- The desired mailbox name.readOnly
- The open mode. If readOnly is true, the mailbox is opened
using EXAMINE rather than SELECT.
MessagingException
public List expungeMailbox() throws MessagingException
MessagingException
public int[] searchMailbox(SearchTerm term) throws MessagingException
MessagingException
public int[] searchMailbox(String messages, SearchTerm term) throws MessagingException
messages
- The list of messages (comma-separated numbers or "ALL").term
- The desired search criteria
MessagingException
public int[] searchMailbox(String messages, SearchTerm term, String charset) throws MessagingException
messages
- The list of messages (comma-separated numbers or "ALL").charset
- The charset specifier to send to the server. If null, then
the CHARSET keyword is omitted.term
- The desired search criteria
MessagingException
public void appendMessage(String mailbox, Date messageDate, Flags messageFlags, byte[] messageData) throws MessagingException
mailbox
- The target mailbox name.messageFlags
- The initial flag set for the appended message.messageDate
- The received date the message is created with,messageData
- The RFC822 Message data stored on the server.
MessagingException
public Flags fetchFlags(int sequenceNumber) throws MessagingException
sequenceNumber
- The message sequence number.
MessagingException
public List setFlags(String messageSet, Flags flags, boolean set) throws MessagingException
messageSet
- The set of message numbers.flags
- The new flag settings.set
- true if the flags should be set, false for a clear operation.
MessagingException
public Flags setFlags(int sequenceNumber, Flags flags, boolean set) throws MessagingException
sequenceNumber
- The sequence number of target message.flags
- The new flag settings.set
- true if the flags should be set, false for a clear operation.
MessagingException
public void copyMessages(String messageSet, String target) throws MessagingException
messageSet
- The set of message numbers.target
- The target mailbox name.
MessagingException
public IMAPUid getSequenceNumberForUid(long uid) throws MessagingException
uid
- The target UID
MessagingException
public List getSequenceNumbersForUids(long start, long end) throws MessagingException
start
- The start of the range.end
- The end of the uid range.
MessagingException
public IMAPUid getUidForSequenceNumber(int sequenceNumber) throws MessagingException
sequenceNumber
- The target message number.
MessagingException
public IMAPNamespaceResponse getNamespaces() throws MessagingException
MessagingException
public List fetch(String messageSet, FetchProfile profile) throws MessagingException
messageSet
- The set of message numbers we need to fetch.profile
- The profile of the required information.
MessagingException
public void setACLRights(String mailbox, ACL acl) throws MessagingException
mailbox
- The target mailbox.acl
- The new ACL to be used for the mailbox.
MessagingException
public void addACLRights(String mailbox, ACL acl) throws MessagingException
mailbox
- The mailbox to alter.acl
- The ACL to add.
MessagingException
public void removeACLRights(String mailbox, ACL acl) throws MessagingException
mailbox
- The mailbox to alter.acl
- The particular ACL to revoke.
MessagingException
public ACL[] getACLRights(String mailbox) throws MessagingException
mailbox
- The target mailbox.
MessagingException
public Rights getMyRights(String mailbox) throws MessagingException
mailbox
- The target mailbox.
MessagingException
public Rights[] listACLRights(String mailbox, String name) throws MessagingException
mailbox
- The target mailbox.name
- The user we're querying.
MessagingException
public void deleteACL(String mailbox, String name) throws MessagingException
mailbox
- The mailbox we're altering.name
- The user name.
MessagingException
public Quota[] fetchQuotaRoot(String mailbox) throws MessagingException
mailbox
- The mailbox of interest.
MessagingException
public Quota[] fetchQuota(String root) throws MessagingException
root
- The target root name.
MessagingException
public void setQuota(Quota quota) throws MessagingException
quota
- The new QUOTA information.
MessagingException
public boolean hasCapability(String capability)
hasCapability
in class MailConnection
capability
- The capability name.
public void setClosed()
public boolean isClosed()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |