public class Pop
extends java.lang.Object
implements java.lang.AutoCloseable, java.io.Serializable
Example Usage:
// new instance with hostname, username and password Pop pop = new Pop("pop3.myserver.com","jsmith","secret"); try { // connect to POP3 server pop.connect(); // get messages Enumeration e = pop.getMessages(); while(e.hasMoreElements()) { EmailMessage em = (EmailMessage)e.nextElement(); } // disconnect pop.disconnect(); } catch(Exception e) { System.out.println(e); }
Modifier and Type | Class and Description |
---|---|
static class |
Pop.Authentication |
Modifier and Type | Field and Description |
---|---|
static int |
AUTH_APOP
APOP authentication.
|
static int |
AUTH_LOGIN
Standard username/password authentication.
|
static int |
AUTH_PASS
Deprecated.
replaced by AUTH_LOGIN variable for consistency
|
static int |
AUTH_XOAUTH2 |
Constructor and Description |
---|
Pop()
Constructs a new Pop instance.
|
Pop(java.lang.String hostname,
java.lang.String username,
java.lang.String password)
Constructs a new Pop instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addPopListener(PopListener listener)
Adds Pop event listener.
|
void |
clearProxySettings()
Clears proxy server values.
|
void |
close() |
Pop |
connect()
Connects to POP3 server and performs login.
|
void |
deleteMessage(int msg)
Deletes message from POP3 server.
|
void |
disconnect()
Disconnects from POP3 server.
|
int |
getAuthMode()
Gets the authentication mode used when logging into POP3 server.
|
int |
getConnectTimeout()
Gets the timeout used when opening a POP3 server connection.
|
java.io.PrintStream |
getDebugStream()
Gets PrintStream used in reporting debug statements.
|
java.lang.String |
getHostname()
Gets the hostname of the POP3 server.
|
EmailMessage |
getMessage(int msg)
Gets message from POP3 server.
|
int |
getMessageCount()
Gets number of messages currently in POP3 mailbox.
|
PopMessageReader |
getMessageReader(int msg)
Gets a reader that may be used to read message.
|
java.util.Enumeration |
getMessages()
Gets all available messages in mailbox from POP3 server.
|
int |
getMessageSize(int msg)
Gets size of message in bytes from POP3 server.
|
int |
getPort()
Gets the port of the POP3 server.
|
int |
getReadTimeout()
Gets the timeout used when reading responses from POP server.
|
int |
getTimeout()
Deprecated.
Replaced by getConnectTimeout and getReadTimeout
|
java.lang.String |
getTop(int msg,
int lines)
Gets summary of message from POP3 server.
|
java.lang.String |
getUid(int msg)
Gets unique message id for a message on POP3 server.
|
java.lang.String |
getUsername()
Gets the username to be used in authentication to POP3 server.
|
boolean |
isConnected()
Checks if client is connected to POP3 server.
|
boolean |
isDebug()
Gets debug level of POP3 session.
|
boolean |
isDelete()
Checks whether to delete messages automatically after retrieval.
|
java.lang.String |
issueCommand(java.lang.String command)
Issues a command to POP3 server and reads response.
|
java.lang.String |
issueCommand(java.lang.String command,
boolean readResponse)
Issues a command to POP3 server and optionally reads response.
|
java.lang.String |
issueCommandMultiLine(java.lang.String command)
Issues a command to POP3 server and reads a multi-line response.
|
void |
removePopListener(PopListener listener)
Removes specified Pop event listener.
|
Pop |
setAuthentication(Pop.Authentication authentication) |
void |
setAuthMode(int mode)
Sets the authentication mode used when logging into POP3 server.
|
void |
setConnectTimeout(int timeout)
Sets the timeout for opening a POP3 server connection.
|
void |
setDebug(boolean debug)
Sets debugging state.
|
void |
setDebugStream(java.io.PrintStream debugStream)
Sets PrintStream used in reporting debug statements.
|
void |
setDelete(boolean delete)
Defines whether to delete messages automatically after retrieval.
|
void |
setHostname(java.lang.String hostname)
Sets the hostname of the POP3 server.
|
void |
setPassword(java.lang.String password)
Sets the password to be used in authentication to POP3 server.
|
void |
setPort(int port)
Sets the port of the POP3 server.
|
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 |
setReadTimeout(int timeout)
Sets the timeout for reading responses from POP server.
|
void |
setTimeout(int timeout)
Deprecated.
Replaced by setConnectTimeout and setReadTimeout
|
void |
setUsername(java.lang.String username)
Sets the username to be used in authentication to POP3 server.
|
public static final int AUTH_PASS
setAuthMode
method.public static final int AUTH_LOGIN
setAuthMode
method.public static final int AUTH_APOP
setAuthMode
method.public static final int AUTH_XOAUTH2
public Pop()
public Pop(java.lang.String hostname, java.lang.String username, java.lang.String password)
hostname
- the hostname of POP3 serverusername
- the username of POP3 userpassword
- the password of POP3 userpublic Pop setAuthentication(Pop.Authentication authentication)
public void setAuthMode(int mode)
mode
- authentication modepublic int getAuthMode()
public void setConnectTimeout(int timeout)
timeout
- the timeout in millisecondspublic int getConnectTimeout()
public boolean isConnected()
public void setDebug(boolean debug)
debug
- true
to turn debugging onsetDebugStream(java.io.PrintStream)
public boolean isDebug()
true
if debugging is onsetDebugStream(java.io.PrintStream)
public void setDebugStream(java.io.PrintStream debugStream)
debugStream
- the PrintStream to send debug statements toPrintStream
public java.io.PrintStream getDebugStream()
PrintStream
public void setDelete(boolean delete)
false
.delete
- true
to delete automaticallypublic boolean isDelete()
false
.true
if should delete automaticallypublic void setHostname(java.lang.String hostname)
hostname
- the hostname of POP3 serverpublic java.lang.String getHostname()
public EmailMessage getMessage(int msg) throws PopException
msg
- message id of messagePopException
- if I/O or POP3 related error occursEmailMessage
public int getMessageCount() throws PopException
PopException
- if I/O or POP3 related error occurspublic PopMessageReader getMessageReader(int msg) throws PopException
msg
- the message id of messagePopException
- if an I/O or POP3 related error occurs.PopMessageReader
public int getMessageSize(int msg) throws PopException
msg
- message id of messagePopException
- if I/O or POP3 related error occurspublic java.util.Enumeration getMessages() throws PopException
PopException
- if I/O or POP3 related error occursEmailMessage
public void setPassword(java.lang.String password)
password
- the password of POP3 userpublic void setPort(int port)
port
- the port of POP3 serverpublic int getPort()
public void setReadTimeout(int timeout)
timeout
- the timeout in millisecondspublic int getReadTimeout()
public void setTimeout(int timeout)
timeout
- the timeout in millisecondssetConnectTimeout(int)
,
setReadTimeout(int)
public int getTimeout()
getConnectTimeout()
,
getReadTimeout()
public java.lang.String getTop(int msg, int lines) throws PopException
msg
- message idlines
- number of lines to retrievePopException
- if I/O or POP3 related error occurspublic java.lang.String getUid(int msg) throws PopException
msg
- the message number to get the unique message id for. Message number is always (1)
based, first message number is 1, second is 2 and so on.PopException
- if an I/O or POP3 related error occurspublic void setUsername(java.lang.String username)
username
- the username of POP3 userpublic java.lang.String getUsername()
public void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
#clearProxySettings
method.proxyUsername
- the proxy usernameproxyPassword
- the proxy passwordclearProxySettings()
public void setProxyHost(java.lang.String proxyHostname, int proxyPort)
#clearProxySettings
method.proxyHostname
- the hostname or ip address of the proxy serverproxyPort
- the port of the proxy serverclearProxySettings()
public void setProxyType(java.lang.String proxyType)
proxyType
- The proxy type. Valid values: HTTP, SOCKS5public void clearProxySettings()
public void addPopListener(PopListener listener)
listener
- a PopListenerPopListener
public Pop connect() throws PopException
PopException
- if I/O or POP3 related error occurspublic void deleteMessage(int msg) throws PopException
msg
- message id of messagePopException
- if I/O or POP3 related error occurspublic void disconnect() throws PopException
PopException
- if I/O or POP3 related error occurspublic void close() throws java.lang.Exception
close
in interface java.lang.AutoCloseable
java.lang.Exception
public java.lang.String issueCommand(java.lang.String command) throws PopException
command
- a POP3 commandPopException
- if I/O or POP3 related error occurspublic java.lang.String issueCommand(java.lang.String command, boolean readResponse) throws PopException
command
- a POP3 commandreadResponse
- true
if should read response
false
otherwisePopException
- if I/O or POP3 related error occurspublic java.lang.String issueCommandMultiLine(java.lang.String command) throws PopException
command
- a POP3 commandPopException
- if I/O or POP3 related error occurspublic void removePopListener(PopListener listener)
listener
- the PopListener to removePopListener
Copyright © JSCAPE LLC. 1999-2021. All Rights Reserved