Secure iNet Factory

com.jscape.inet.imapssl
Class ImapSsl

java.lang.Object
  extended by com.jscape.inet.imap.Imap
      extended by com.jscape.inet.imapssl.ImapSsl
All Implemented Interfaces:
java.io.Serializable

public class ImapSsl
extends Imap

Implements the basic functionality of a secure IMAP client using SSL/TLS. Client supports both implicit SSL/TLS on port 993 (default) and explicit SSL/TLS using STARTTLS command on port 143.

Example Usage (implicit SSL/TLS):

 // new instance with hostname, SSL port, username and password
 ImapSsl imap = new ImapSsl("imap4.myserver.com",993,"jsmith","secret");
 try {
   // connect to IMAP4 server
   imap.connect();

   // get messages
   int messageCount = imap.getMessageCount();
   for(int i = 1; i <= messageCount(); ++i) {
     EmailMessage em = imap.getMessage(i);
   }

   // disconnect
   imap.disconnect();
 }
 catch(Exception e) {
   System.out.println(e);
 }
 
Example Usage (explicit SSL/TLS using STARTTLS command):

 // new instance with hostname, SSL port, username and password
 ImapSsl imap = new ImapSsl("imap4.myserver.com",143,"jsmith","secret");
 imap.setConnectionType(ImapSsl.STARTTLS);
 try {
   // connect to IMAP4 server
   imap.connect();

   // get messages
   int messageCount = imap.getMessageCount();
   for(int i = 1; i <= messageCount(); ++i) {
     EmailMessage em = imap.getMessage(i);
   }

   // disconnect
   imap.disconnect();
 }
 catch(Exception e) {
   System.out.println(e);
 }
 

See Also:
Serialized Form

Field Summary
static int DEFAULT_PORT
          The default port to connect to for secure IMAP over SSL connections (993).
static int IMPLICIT_SSL
          Connection type for implicit SSL/TLS connections on port 993.
static int STARTTLS
          Connection type for explicit SSL/TLS connections using STARTTLS command on port 143.
 
Fields inherited from class com.jscape.inet.imap.Imap
AUTH_CRAM_MD5, AUTH_LOGIN, FLAG_ANSWERED, FLAG_DELETED, FLAG_DRAFT, FLAG_FLAGGED, FLAG_MODE_ADD, FLAG_MODE_DELETE, FLAG_MODE_REPLACE, FLAG_RECENT, FLAG_SEEN
 
Constructor Summary
ImapSsl(java.lang.String hostname, int port, java.lang.String username, java.lang.String password)
          Creates a new ImapSsl instance.
ImapSsl(java.lang.String hostname, java.lang.String username, java.lang.String password)
          Creates a new ImapSsl instance.
 
Method Summary
 void clearProxySettings()
          Clears proxy server values.
 void connect()
          Establishes secure SSL connection to IMAP server.
 void disconnect()
          Disconnects from IMAP server.
 int getConnectionType()
          Gets the connection type for this session.
 void setClientCertificates(java.lang.String filename, java.lang.String password)
          Sets optional client certificate to be used during authentication.
 void setClientCertificates(java.lang.String filename, java.lang.String password, java.lang.String storetype)
          Sets optional client certificate to be used during authentication.
 void setConnectionType(int mode)
          Sets the connection type for this session.
 void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
          Sets the username and password to use when for authentication with proxy server.
 void setProxyHost(java.lang.String proxyHostname, int proxyPort)
          Sets the proxy hostname and port for this connection.
 void setProxyType(java.lang.String proxyType)
          Sets the proxy type will be used for this connection.
 void setServerCertificates(java.lang.String filename, java.lang.String password)
          Sets optional server certificate to be used during authentication.
 void setServerCertificates(java.lang.String filename, java.lang.String password, java.lang.String storetype)
          Sets optional server certificate to be used during authentication.
 void setSSLContext(javax.net.ssl.SSLContext context)
          Sets SSL context for this connection.
 
Methods inherited from class com.jscape.inet.imap.Imap
addImapListener, append, append, createMailbox, deleteMailbox, deleteMessage, deleteMessages, expunge, getAuthMode, getConnectTimeout, getDebugStream, getHostname, getMailboxes, getMessage, getMessageCount, getMessageHeader, getMessageHeaders, getMessageID, getMessages, getMessages, getMessages, getMessagesWithFlags, getMessagesWithFlags, getMessagesWithFlags, getMessageWithFlags, getNewMessageID, getNewMessages, getNewMessagesWithFlags, getPort, getReadTimeout, getTimeout, getUid, getUid, getUsername, isConnected, isDebug, isDelete, issueCommand, listMailboxes, listMailboxes, removeImapListener, renameMailbox, selectMailbox, setAuthMode, setConnectTimeout, setDebug, setDebugStream, setDelete, setHostname, setPassword, setPort, setReadTimeout, setTimeout, setUsername, store, store
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMPLICIT_SSL

public static final int IMPLICIT_SSL
Connection type for implicit SSL/TLS connections on port 993. Value of 0.

See Also:
setConnectionType(int), STARTTLS, Constant Field Values

STARTTLS

public static final int STARTTLS
Connection type for explicit SSL/TLS connections using STARTTLS command on port 143. Value of 1.

See Also:
setConnectionType(int), IMPLICIT_SSL, Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port to connect to for secure IMAP over SSL connections (993).

See Also:
Constant Field Values
Constructor Detail

ImapSsl

public ImapSsl(java.lang.String hostname,
               java.lang.String username,
               java.lang.String password)
Creates a new ImapSsl instance.

Parameters:
hostname - the IMAP hostname
username - the IMAP username
password - the IMAP password

ImapSsl

public ImapSsl(java.lang.String hostname,
               int port,
               java.lang.String username,
               java.lang.String password)
Creates a new ImapSsl instance.

Parameters:
hostname - the IMAP hostname
username - the IMAP username
password - the IMAP password
port - the IMAP SSL port
Method Detail

setClientCertificates

public void setClientCertificates(java.lang.String filename,
                                  java.lang.String password)
Sets optional client certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the client certificate
password - the keystore password

setClientCertificates

public void setClientCertificates(java.lang.String filename,
                                  java.lang.String password,
                                  java.lang.String storetype)
Sets optional client certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the client certificate
password - the keystore password
storetype - the keystore type valid values include jks and pkcs12

setConnectionType

public void setConnectionType(int mode)
Sets the connection type for this session.

Parameters:
mode - a valid connection type
See Also:
IMPLICIT_SSL, STARTTLS

getConnectionType

public int getConnectionType()
Gets the connection type for this session. Default is IMPLICIT_SSL

Returns:
the connection type
See Also:
IMPLICIT_SSL, STARTTLS

setSSLContext

public void setSSLContext(javax.net.ssl.SSLContext context)
Sets SSL context for this connection.

Parameters:
context - an SSLContext instance
See Also:
SSLContext

setServerCertificates

public void setServerCertificates(java.lang.String filename,
                                  java.lang.String password)
Sets optional server certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the server certificate
password - the keystore password

setServerCertificates

public void setServerCertificates(java.lang.String filename,
                                  java.lang.String password,
                                  java.lang.String storetype)
Sets optional server certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the server certificate
password - the keystore password
storetype - the keystore type valid values include jks and pkcs12

setProxyAuthentication

public void setProxyAuthentication(java.lang.String proxyUsername,
                                   java.lang.String proxyPassword)
Sets the username and password to use when for authentication with proxy server. To clear these settings invoke the #clearProxySettings method.

Overrides:
setProxyAuthentication in class Imap
Parameters:
proxyUsername - the proxy username
proxyPassword - the proxy password
See Also:
clearProxySettings()

setProxyHost

public void setProxyHost(java.lang.String proxyHostname,
                         int proxyPort)
Sets the proxy hostname and port for this connection. To clear these settings invoke the #clearProxySettings method.

Overrides:
setProxyHost in class Imap
Parameters:
proxyHostname - the hostname or ip address of the proxy server
proxyPort - the port of the proxy server
See Also:
clearProxySettings()

setProxyType

public void setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this connection.

Overrides:
setProxyType in class Imap
Parameters:
proxyType - The proxy type. Valid values: HTTP, SOCKS5

clearProxySettings

public void clearProxySettings()
Clears proxy server values.

Overrides:
clearProxySettings in class Imap

connect

public void connect()
             throws ImapException
Establishes secure SSL connection to IMAP server.

Overrides:
connect in class Imap
Throws:
ImapException - if I/O or IMAP related error occurs

disconnect

public void disconnect()
                throws ImapException
Disconnects from IMAP server. Issues CLOSE and LOGOUT commands to IMAP server.

Overrides:
disconnect in class Imap
Throws:
ImapException - if I/O or IMAP related error occurs
See Also:
Imap.connect()

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved